mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
add colors
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
dispatch({type: ACTIONS.COLORS});
|
||||||
await db.notes.note(note.id).color(color);
|
localRefresh(note.type);
|
||||||
|
|
||||||
localRefresh(item.type);
|
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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.id}
|
||||||
key={item}
|
activeOpacity={opacity / 2}
|
||||||
activeOpacity={opacity / 2}
|
onPress={() => {
|
||||||
|
NavigationService.navigate('Notes', {
|
||||||
|
type: 'color',
|
||||||
|
title: item.title,
|
||||||
|
color: item,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: noTextMode ? 'center' : 'flex-start',
|
||||||
|
alignItems: 'center',
|
||||||
|
margin: noTextMode ? 0 : 5,
|
||||||
|
marginLeft: 0,
|
||||||
|
marginRight: noTextMode ? 0 : 15,
|
||||||
|
marginTop: normalize(15),
|
||||||
|
}}>
|
||||||
|
<View
|
||||||
style={{
|
style={{
|
||||||
flexDirection: 'row',
|
width: noTextMode ? SIZE.md : normalize(30),
|
||||||
justifyContent: noTextMode ? 'center' : 'flex-start',
|
height: noTextMode ? SIZE.md : normalize(30),
|
||||||
alignItems: 'center',
|
backgroundColor: item.title,
|
||||||
margin: noTextMode ? 0 : 5,
|
borderRadius: 100,
|
||||||
marginTop: normalize(15),
|
}}></View>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
color: colors.pri,
|
||||||
|
fontSize: SIZE.xxs - 2,
|
||||||
|
minWidth: 12,
|
||||||
|
minHeight: 12,
|
||||||
|
borderWidth: 0.5,
|
||||||
|
paddingHorizontal: 2,
|
||||||
|
borderColor: item.title,
|
||||||
|
borderRadius: 100,
|
||||||
|
textAlign: 'center',
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: -5,
|
||||||
|
right:
|
||||||
|
item.count < 10
|
||||||
|
? -8
|
||||||
|
: item.count >= 10 && item.count < 100
|
||||||
|
? -10
|
||||||
|
: item.count >= 100 && item.count < 1000
|
||||||
|
? -12
|
||||||
|
: item.count > 1000
|
||||||
|
? -14
|
||||||
|
: -8,
|
||||||
}}>
|
}}>
|
||||||
<View
|
{item.count + 10}
|
||||||
style={{
|
</Text>
|
||||||
width: noTextMode ? SIZE.md : normalize(30),
|
</TouchableOpacity>
|
||||||
height: noTextMode ? SIZE.md : normalize(30),
|
))}
|
||||||
backgroundColor: item,
|
|
||||||
borderRadius: 100,
|
|
||||||
}}></View>
|
|
||||||
<Text
|
|
||||||
style={{
|
|
||||||
color: colors.pri,
|
|
||||||
fontSize: SIZE.xxs - 2,
|
|
||||||
minWidth: 10,
|
|
||||||
minHeight: 10,
|
|
||||||
borderRadius: 2,
|
|
||||||
textAlign: 'center',
|
|
||||||
padding: 0,
|
|
||||||
paddingHorizontal: 1,
|
|
||||||
position: 'absolute',
|
|
||||||
top: -5,
|
|
||||||
right: -10,
|
|
||||||
}}></Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|||||||
@@ -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={[
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export const defaultState = {
|
|||||||
favorites: [],
|
favorites: [],
|
||||||
pinned: [],
|
pinned: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
|
colorNotes: [],
|
||||||
colors: {
|
colors: {
|
||||||
night: false,
|
night: false,
|
||||||
bg: 'white',
|
bg: 'white',
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
|
||||||
|
|||||||
@@ -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 ${
|
||||||
|
|||||||
Reference in New Issue
Block a user