diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js index eebff9e3b..e9b30c0da 100644 --- a/apps/web/src/views/Notebooks.js +++ b/apps/web/src/views/Notebooks.js @@ -9,169 +9,60 @@ import { Virtuoso as List } from "react-virtuoso"; import Notebook from "../components/notebook"; import Topic from "../components/topic"; import Note from "../components/note"; -import { routes, navigationEvents, goBack as p_goBack } from "../navigation"; +import { sendNewNoteEvent } from "../common"; +import { createRoute } from "../navigation/routes"; +import Navigator from "../navigation"; import { CreateNotebookDialog, ask } from "../components/dialogs"; -const history = [{}]; -const Notebooks = props => { +const NotebooksView = props => { const [open, setOpen] = useState(false); const [notebooks, setNotebooks] = useState([]); - const [selected, setSelected] = useState({}); - const [intent, setIntent] = useState(props.intent); useEffect(() => { function onRefresh() { setNotebooks(db.getNotebooks()); } onRefresh(); - navigationEvents.onWillNavigateAway = async routeName => { - if (intent === "moveNote") { - return await ask( - Icon.Move, - "Move", - "Are you sure you want to navigate away? Your note selection will be lost." - ); - } - return true; - }; ev.addListener("refreshNotebooks", onRefresh); return () => { ev.removeListener("refreshNotebooks", onRefresh); - navigationEvents.onWillNavigateAway = undefined; Notebooks.onRefresh = undefined; }; - }, [intent]); - function navigate(item, save = true, title = undefined) { - //transform notes in a topic to real notes - if (item.notes) { - item = { ...item }; - item.notes = db.getTopic(selected.dateCreated, item.title); - } - if (save) { - history[history.length] = selected; - } - //set notebook title if we are inside the notebook else set the provided or item's title. - title = - selected.type === "notebook" - ? selected.title - : title || item.title || routes.notebooks.title; - props.changeTitle(title); - props.canGoBack(item.title !== undefined); - props.backAction(goBack); + }, []); - setSelected((item.title && item) || {}); - } - function goBack() { - navigate(history.pop(), false); - } return ( - {notebooks.length > 0 ? ( - - {selected.type === "topic" && ( - - {selected.title} - + + + ( + { + NotebookNavigator.navigate("topics", { + title: notebooks[index].title, + notebook: notebooks[index] + }); + }} + /* onTopicClick={(notebook, topic) => + navigate(topic, true, notebook.title) + } */ + /> )} - {intent === "moveNote" && selected.type !== "topic" && ( - - Please select a{" "} - {selected.type === "notebook" ? "topic" : "notebook"} to move the - note to: - - )} - - { - return selected.type === "notebook" ? ( - navigate(selected.topics[index])} - /> - ) : selected.type === "topic" ? ( - - ) : ( - navigate(notebooks[index])} - onTopicClick={(notebook, topic) => - navigate(topic, true, notebook.title) - } - /> - ); - }} - /> -