Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: database not initializing before page load

thecodrr882deda73625
diff --git a/apps/web/src/index.js b/apps/web/src/index.js
index 568b349dc..a64d1d4c3 100644
--- a/apps/web/src/index.js
+++ b/apps/web/src/index.js
@@ -6,11 +6,12 @@ import * as serviceWorker from "./serviceWorker";
import Modal from "react-modal";
import { db } from "./common";
-db.init();
-Modal.setAppElement("#root");
-ReactDOM.render(<App />, document.getElementById("root"));
+db.init().then(() => {
+ Modal.setAppElement("#root");
+ ReactDOM.render(<App />, document.getElementById("root"));
-// If you want your app to work offline and load faster, you can change
-// unregister() to register() below. Note this comes with some pitfalls.
-// Learn more about service workers: https://bit.ly/CRA-PWA
-serviceWorker.unregister();
+ // If you want your app to work offline and load faster, you can change
+ // unregister() to register() below. Note this comes with some pitfalls.
+ // Learn more about service workers: https://bit.ly/CRA-PWA
+ serviceWorker.unregister();
+});
diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.js
index f22a0c540..ef706f82e 100644
--- a/apps/web/src/views/Home.js
+++ b/apps/web/src/views/Home.js
@@ -6,7 +6,6 @@ import { GroupedVirtuoso as GroupList, Virtuoso as List } from "react-virtuoso";
import Button from "../components/button";
import Search from "../components/search";
import Note from "../components/note";
-import { HomeAnim } from "./Placeholders";
function SearchBox(props) {
return (
@@ -24,6 +23,64 @@ function SearchBox(props) {
);
}
+function Home() {
+ const [notes, setNotes] = useState({
+ items: [],
+ groupCounts: [],
+ groups: []
+ });
+ useEffect(() => {
+ function onRefreshNotes() {
+ let groups = db.notes.group(undefined, true);
+ setNotes(groups);
+ console.log("refreshing notes");
+ }
+ onRefreshNotes();
+ ev.addListener("refreshNotes", onRefreshNotes);
+ return () => {
+ ev.removeListener("refreshNotes", onRefreshNotes);
+ };
+ }, []);
+ return (
+ <Flex flexDirection="column" flex="1 1 auto">
+ <SearchBox setNotes={setNotes} />
+ <GroupList
+ style={{
+ width: "100%",
+ flex: "1 1 auto",
+ height: "auto",
+ overflowX: "hidden"
+ }}
+ groupCounts={notes.groupCounts}
+ group={groupIndex =>
+ notes.groups[groupIndex].title === "Pinned" ? (
+ <Box px={3} bg="background" py={1} />
+ ) : (
+ <Box px={3} bg="background">
+ <Text variant="heading" color="primary" fontSize={15}>
+ {notes.groups[groupIndex].title}
+ </Text>
+ </Box>
+ )
+ }
+ item={(index, groupIndex) => (
+ <Note index={index} item={notes.items[index]} />
+ )}
+ />
+ <Button
+ Icon={Icon.Plus}
+ content="Make a new note"
+ onClick={sendNewNoteEvent}
+ />
+ </Flex>
+ );
+}
+export default Home;
+/*
+import { HomeAnim } from "./Placeholders";
+
+
+
function Home() {
const [notes, setNotes] = useState({
items: [],
@@ -34,7 +91,8 @@ function Home() {
//const [pinnedItems, setPinnedItems] = useState([]);
useEffect(() => {
function onRefreshNotes() {
- let groups = db.notes.group(undefined, true);
+ let groups = db.notes.group();
+ console.log(groups);
setNotes(groups);
}
onRefreshNotes();
@@ -132,3 +190,4 @@ function Home() {
}
export default Home;
+ */