add colors

This commit is contained in:
ammarahm-ed
2020-02-07 00:26:44 +05:00
parent 6555124234
commit 39c25b3420
11 changed files with 109 additions and 50 deletions

View File

@@ -342,12 +342,10 @@ export const ActionSheetComponent = ({
if (noteColors.includes(color)) { if (noteColors.includes(color)) {
await db.notes.note(note.id).uncolor(color); await db.notes.note(note.id).uncolor(color);
} else { } else {
noteColors.push(color);
}
await db.notes.note(note.id).color(color); await db.notes.note(note.id).color(color);
}
localRefresh(item.type); dispatch({type: ACTIONS.COLORS});
localRefresh(note.type);
}} }}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',

View File

@@ -44,6 +44,7 @@ export const Container = ({
placeholder = '', placeholder = '',
noSearch = false, noSearch = false,
noSelectionHeader = false, noSelectionHeader = false,
headerColor = null,
}) => { }) => {
// State // State
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -181,6 +182,7 @@ export const Container = ({
countUp = 0; countUp = 0;
countDown = 0; countDown = 0;
}} }}
headerColor={headerColor}
navigation={navigation} navigation={navigation}
colors={colors} colors={colors}
isLoginNavigator={isLoginNavigator} isLoginNavigator={isLoginNavigator}
@@ -195,6 +197,7 @@ export const Container = ({
clear={() => setText('')} clear={() => setText('')}
hide={hideHeader} hide={hideHeader}
onChangeText={onChangeText} onChangeText={onChangeText}
headerColor={headerColor}
onSubmitEditing={onSubmitEditing} onSubmitEditing={onSubmitEditing}
placeholder={placeholder} placeholder={placeholder}
onBlur={onBlur} onBlur={onBlur}
@@ -234,7 +237,7 @@ export const Container = ({
alignSelf: 'center', alignSelf: 'center',
borderRadius: br, borderRadius: br,
backgroundColor: colors.accent, backgroundColor: headerColor ? headerColor : colors.accent,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
marginBottom: 0, marginBottom: 0,

View File

@@ -41,7 +41,7 @@ export const Menu = ({
noTextMode = false, noTextMode = false,
}) => { }) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, tags} = state; const {colors, tags, colorNotes} = state;
// todo // todo
let overlayRef; let overlayRef;
@@ -386,42 +386,61 @@ export const Menu = ({
marginTop: pv / 2, marginTop: pv / 2,
marginBottom: pv / 2, marginBottom: pv / 2,
}}> }}>
{['red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray'].map( {colorNotes.map(item => (
item => (
<TouchableOpacity <TouchableOpacity
key={item} key={item.id}
activeOpacity={opacity / 2} activeOpacity={opacity / 2}
onPress={() => {
NavigationService.navigate('Notes', {
type: 'color',
title: item.title,
color: item,
});
}}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
justifyContent: noTextMode ? 'center' : 'flex-start', justifyContent: noTextMode ? 'center' : 'flex-start',
alignItems: 'center', alignItems: 'center',
margin: noTextMode ? 0 : 5, margin: noTextMode ? 0 : 5,
marginLeft: 0,
marginRight: noTextMode ? 0 : 15,
marginTop: normalize(15), marginTop: normalize(15),
}}> }}>
<View <View
style={{ style={{
width: noTextMode ? SIZE.md : normalize(30), width: noTextMode ? SIZE.md : normalize(30),
height: noTextMode ? SIZE.md : normalize(30), height: noTextMode ? SIZE.md : normalize(30),
backgroundColor: item, backgroundColor: item.title,
borderRadius: 100, borderRadius: 100,
}}></View> }}></View>
<Text <Text
style={{ style={{
color: colors.pri, color: colors.pri,
fontSize: SIZE.xxs - 2, fontSize: SIZE.xxs - 2,
minWidth: 10, minWidth: 12,
minHeight: 10, minHeight: 12,
borderRadius: 2, borderWidth: 0.5,
paddingHorizontal: 2,
borderColor: item.title,
borderRadius: 100,
textAlign: 'center', textAlign: 'center',
padding: 0,
paddingHorizontal: 1,
position: 'absolute', position: 'absolute',
top: -5, bottom: -5,
right: -10, right:
}}></Text> item.count < 10
? -8
: item.count >= 10 && item.count < 100
? -10
: item.count >= 100 && item.count < 1000
? -12
: item.count > 1000
? -14
: -8,
}}>
{item.count + 10}
</Text>
</TouchableOpacity> </TouchableOpacity>
), ))}
)}
</View> </View>
</View> </View>

View File

@@ -22,6 +22,7 @@ export default class NoteItem extends React.Component {
this.cipher = { this.cipher = {
value: false, value: false,
}; };
this.colors = [];
this.actionSheet; this.actionSheet;
this.show = null; this.show = null;
this.setMenuRef = {}; this.setMenuRef = {};
@@ -29,7 +30,10 @@ export default class NoteItem extends React.Component {
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
if (nextProps.item.locked !== this.cipher.value) { if (
nextProps.item.locked !== this.cipher.value ||
nextProps.item.colors.length !== this.colors.length
) {
return true; return true;
} else { } else {
return ( return (
@@ -39,12 +43,15 @@ export default class NoteItem extends React.Component {
} }
} }
componentDidUpdate() { componentDidUpdate() {
this.colors = [...this.props.item.colors];
this.cipher.value = this.props.item.locked ? true : false; this.cipher.value = this.props.item.locked ? true : false;
} }
componentWillUnmount() { componentWillUnmount() {
this.colors = [];
this.cipher.value = false; this.cipher.value = false;
} }
componentDidMount() { componentDidMount() {
this.colors = [];
if (this.props.item.locked) { if (this.props.item.locked) {
this.cipher.value = true; this.cipher.value = true;
} }
@@ -60,7 +67,8 @@ export default class NoteItem extends React.Component {
pinned, pinned,
index, index,
} = this.props; } = this.props;
console.log('rerendering', index, item.content.text.length);
console.log('rerendering again', index);
return ( return (
<View <View
style={[ style={[

View File

@@ -61,7 +61,11 @@ export const Search = props => {
borderRadius: br, borderRadius: br,
height: '90%', height: '90%',
borderWidth: props.hide ? 0 : 1.5, borderWidth: props.hide ? 0 : 1.5,
borderColor: focus ? colors.accent : colors.nav, borderColor: focus
? props.headerColor
? props.headerColor
: colors.accent
: colors.nav,
}}> }}>
<TextInput <TextInput
ref={inputRef} ref={inputRef}
@@ -96,7 +100,13 @@ export const Search = props => {
}); });
}} }}
name={props.value && props.value.length > 0 ? '' : 'search'} name={props.value && props.value.length > 0 ? '' : 'search'}
color={focus ? colors.accent : colors.icon} color={
focus
? props.headerColor
? props.headerColor
: colors.accent
: colors.icon
}
size={SIZE.xl} size={SIZE.xl}
/> />
</Animated.View> </Animated.View>

View File

@@ -21,6 +21,7 @@ export const Header = ({
preventDefaultMargins, preventDefaultMargins,
navigation = null, navigation = null,
isLoginNavigator, isLoginNavigator,
headerColor,
}) => { }) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors} = state;
@@ -110,7 +111,7 @@ export const Header = ({
<Text <Text
style={{ style={{
fontSize: SIZE.xl, fontSize: SIZE.xl,
color: colors.pri, color: headerColor ? headerColor : colors.pri,
fontFamily: WEIGHT.bold, fontFamily: WEIGHT.bold,
}}> }}>
<Text <Text

View File

@@ -12,4 +12,5 @@ export const ACTIONS = {
CLEAR_SELECTION: 'clearSelection', CLEAR_SELECTION: 'clearSelection',
LOGIN_NAVIGATOR: 'loginNavigator', LOGIN_NAVIGATOR: 'loginNavigator',
CURRENT_EDITING_NOTE: 'currentEditingNote', CURRENT_EDITING_NOTE: 'currentEditingNote',
COLORS: 'colorNotes',
}; };

View File

@@ -10,6 +10,7 @@ export const defaultState = {
favorites: [], favorites: [],
pinned: [], pinned: [],
tags: [], tags: [],
colorNotes: [],
colors: { colors: {
night: false, night: false,
bg: 'white', bg: 'white',

View File

@@ -55,6 +55,13 @@ export const reducer = (state, action) => {
favorites: [...favorites], favorites: [...favorites],
}; };
} }
case ACTIONS.COLORS: {
let colors = db.notes.colors;
return {
...state,
colorNotes: [...colors],
};
}
case ACTIONS.SELECTION_MODE: { case ACTIONS.SELECTION_MODE: {
if (action.enabled) { if (action.enabled) {
SideMenuEvent.disable(); SideMenuEvent.disable();

View File

@@ -2,7 +2,7 @@ import React, {useEffect} from 'react';
import {SafeAreaView} from 'react-native'; import {SafeAreaView} from 'react-native';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';
import {useIsFocused} from 'react-navigation-hooks'; import {useIsFocused} from 'react-navigation-hooks';
import {DDS} from '../../../App'; import {DDS, db} from '../../../App';
import Container from '../../components/Container'; import Container from '../../components/Container';
import {NotesList} from '../../components/NotesList'; import {NotesList} from '../../components/NotesList';
import SelectionHeader from '../../components/SelectionHeader'; import SelectionHeader from '../../components/SelectionHeader';
@@ -22,6 +22,7 @@ export const Home = ({navigation}) => {
const isFocused = useIsFocused(); const isFocused = useIsFocused();
useEffect(() => { useEffect(() => {
dispatch({type: ACTIONS.COLORS});
dispatch({type: ACTIONS.NOTES}); dispatch({type: ACTIONS.NOTES});
}, [isFocused]); }, [isFocused]);

View File

@@ -10,7 +10,7 @@ import {ACTIONS} from '../../provider/actions';
export const Notes = ({navigation}) => { export const Notes = ({navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, selectionMode, currentEditingNote} = state; const {colors, selectionMode, currentEditingNote, colorNotes} = state;
const allNotes = state.notes; const allNotes = state.notes;
const [notes, setNotes] = useState([]); const [notes, setNotes] = useState([]);
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
@@ -28,6 +28,11 @@ export const Notes = ({navigation}) => {
if (params.type === 'tag') { if (params.type === 'tag') {
let notesInTag = db.notes.tagged(params.tag.title); let notesInTag = db.notes.tagged(params.tag.title);
setNotes([...notesInTag]); setNotes([...notesInTag]);
} else if (params.type == 'color') {
let notesInColors = db.notes.colored(params.color.id);
console.log(notesInColors);
setNotes([...notesInColors]);
//setNotes(...);
} else { } else {
let allNotes = db.notebooks let allNotes = db.notebooks
.notebook(params.notebookID) .notebook(params.notebookID)
@@ -36,7 +41,7 @@ export const Notes = ({navigation}) => {
setNotes(allNotes); setNotes(allNotes);
} }
} }
}, [allNotes]); }, [allNotes, colorNotes]);
const _renderItem = ({item, index}) => ( const _renderItem = ({item, index}) => (
<SelectionWrapper <SelectionWrapper
@@ -110,7 +115,12 @@ export const Notes = ({navigation}) => {
<Container <Container
bottomButtonText="Create a new note" bottomButtonText="Create a new note"
canGoBack={false} canGoBack={false}
heading={'#' + params.title} heading={
params.type == 'tag'
? '#' + params.title
: params.title.slice(0, 1).toUpperCase() + params.title.slice(1)
}
headerColor={params.type == 'color' ? params.title : null}
canGoBack={true} canGoBack={true}
data={notes} data={notes}
placeholder={`Search in ${ placeholder={`Search in ${