This commit is contained in:
alihamuh
2020-02-26 02:17:50 -05:00
7 changed files with 77 additions and 21 deletions

View File

@@ -5,6 +5,6 @@ import events from "events";
export const db = new Database(StorageInterface);
export const ev = new events.EventEmitter();
console.log("from common", db);
export function sendNewNoteEvent() {
ev.emit("onNewNote");
export function sendNewNoteEvent(context) {
ev.emit("onNewNote", context);
}

View File

@@ -104,7 +104,7 @@ export default class Editor extends React.Component {
this.setState({ pinned });
}
onNewNote(show = true, cb = null) {
onNewNote(context, show = true, cb = null) {
clearTimeout(this.timeout);
this.saveNote().then(() => {
this.titleRef.value = "";
@@ -112,6 +112,12 @@ export default class Editor extends React.Component {
this.title = undefined;
this.titleRef.focus();
this.quill.setText("\n");
this.setState({
colors: [...this.state.colors, ...context.colors],
tags: [...this.state.tags, ...context.tags]
});
console.log(this.state.colors);
ev.emit("refreshNotes");
cb && cb();
if (show) {
showSnack("Let's start writing!", Icon.Edit2);
@@ -121,14 +127,14 @@ export default class Editor extends React.Component {
onClearNote(id = undefined) {
if (id && id !== this.id) return;
this.onNewNote(false);
this.onNewNote(null, false);
}
onOpenNote(note) {
if (!note) return;
this.onNewNote(false, async () => {
this.onNewNote(null, false, async () => {
let dbNote = db.notes.note(note.id);
if (!dbNote) return this.onNewNote(false);
if (!dbNote) return this.onNewNote(null, false);
this.id = note.id;
this.title = note.title;
this.titleRef.value = note.title;
@@ -160,7 +166,7 @@ export default class Editor extends React.Component {
id: this.id,
favorite: this.favorite,
pinned: this.pinned,
colors: this.state.colors,
colors: this.state.colors
//tags: this.state.tags
};
return await db.notes.add(note);
@@ -244,8 +250,7 @@ export default class Editor extends React.Component {
tags[this.state.tags.length] = tag;
}
this.setState({ tags });
if (this.id)
await db.notes.note(this.id).tag(tag);
if (this.id) await db.notes.note(this.id).tag(tag);
}}
onLocked={state => {}}
/>

View File

@@ -101,7 +101,7 @@ const NavigationContainer = props => {
>
<Icon.Menu size={38} />
</Box>
<Heading fontSize="heading">
<Heading fontSize="heading" color={props.route.titleColor || "text"}>
{props.route.title || props.route.params.title}
</Heading>
</Flex>

View File

@@ -4,6 +4,7 @@ import {
Favorites,
Trash,
NotebooksContainer,
Notes,
TagsContainer
} from "../../views";
import * as Icon from "react-feather";
@@ -16,18 +17,54 @@ import {
import Navigator from "../index";
import { showSignInDialog } from "../../components/dialogs";
import { changeTheme, isDarkTheme } from "../../utils/theme";
import { db } from "../../common";
/*For color Search*/
const colorRoutes = {
...createColorRoute("red", "#ed2d37"),
...createColorRoute("orange", "#ec6e05"),
...createColorRoute("yellow", "yellow"),
...createColorRoute("green", "green"),
...createColorRoute("blue", "blue"),
...createColorRoute("purple", "purple"),
...createColorRoute("gray", "gray")
...createColorRoute("Red", Notes, "#ed2d37", {
onClick: () => {
onClickMethod("Red", "red");
}
}),
...createColorRoute("Orange", Notes, "#ec6e05", {
onClick: () => {
onClickMethod("Orange", "orange");
}
}),
...createColorRoute("Yellow", Notes, "yellow", {
onClick: () => {
onClickMethod("Yellow", "yellow");
}
}),
...createColorRoute("Green", Notes, "green", {
onClick: () => {
onClickMethod("Green", "green");
}
}),
...createColorRoute("Blue", Notes, "blue", {
onClick: () => {
onClickMethod("Blue", "blue");
}
}),
...createColorRoute("Purple", Notes, "purple", {
onClick: () => {
onClickMethod("Purple", "purple");
}
}),
...createColorRoute("Gray", Notes, "gray", {
onClick: () => {
onClickMethod("Gray", "gray");
}
})
};
function onClickMethod(Title, label) {
RootNavigator.navigate(Title, {
notes: db.notes.colored(label),
context: { colors: [label] }
});
}
const bottomRoutes = {
...createDeadRoute("nightmode", Icon.Moon, {
onClick: () => changeTheme(),

View File

@@ -11,8 +11,14 @@ export function createRoute(key, component, props = {}, params = {}) {
};
}
export function createColorRoute(key, color, props = {}) {
return createRoute(key, undefined, { icon: Icon.Circle, color, ...props });
export function createColorRoute(key, component, color, props = {}) {
return createRoute(key, component, {
title: key,
titleColor: color,
icon: Icon.Circle,
color,
...props
});
}
export function createNormalRoute(key, component, icon, props = {}) {

View File

@@ -11,7 +11,13 @@ const Notes = props => {
itemsLength={props.notes.length}
button={{
content: "Make a new note",
onClick: sendNewNoteEvent
onClick: () =>
sendNewNoteEvent({
colors: [],
tags: [],
notebook: {},
...props.context
})
}}
/>
);

View File

@@ -28,7 +28,9 @@ const Tags = props => {
onClick={() => {
const notesOfTag = db.notes.tagged(tags[index].title);
props.navigator.navigate("notes", {
notes: notesOfTag,title:tags[index].title
notes: notesOfTag,
title: tags[index].title,
context: { tags: [tags[index].title] }
});
}}
/>