Skip to content

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

feat: implement fav/pin for notebook

thecodrr7b8e57de6a7f
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index dabb75d33..4788d2a83 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -34,6 +34,7 @@ const menuItems = note => [
ev.emit("refreshNotes");
})
},
+ { title: "Edit" },
{ title: note.locked ? "Remove lock" : "Lock" }, //TODO
{ title: "Share" },
{
@@ -65,7 +66,7 @@ const Note = ({ item, index }) => {
index={index}
onClick={sendOpenNoteEvent.bind(this, note)}
info={
- <Flex flexDirection="row" justifyContent="center" alignItems="center">
+ <Flex justifyContent="center" alignItems="center">
<TimeAgo datetime={note.dateCreated} />
{note.locked && <Icon.Lock size={16} style={{ marginLeft: 5 }} />}
{note.favorite && <Icon.Star size={16} style={{ marginLeft: 5 }} />}
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 1a90e645e..2a44d6085 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -2,15 +2,33 @@ import React from "react";
import { Flex, Text } from "rebass";
import * as Icon from "react-feather";
import ListItem from "../list-item";
+import { db, ev } from "../../common";
+import { showSnack } from "../snackbar";
const dropdownRefs = [];
-const menuItems = [
- { title: "Favorite", icon: Icon.Heart },
- { title: "Share", icon: Icon.Share2 },
+const menuItems = notebook => [
+ {
+ title: notebook.pinned ? "Unpin" : "Pin",
+ onClick: async () =>
+ db.pinItem("notebook", notebook.dateCreated).then(() => {
+ showSnack("Notebook pinned!", Icon.Check);
+ ev.emit("refreshNotebooks");
+ })
+ },
+ {
+ title: notebook.favorite ? "Unfavorite" : "Favorite",
+ onClick: async () =>
+ db.favoriteItem("notebook", notebook.dateCreated).then(() => {
+ showSnack("Notebook favorited!", Icon.Check);
+ ev.emit("refreshNotebooks");
+ })
+ },
+ { title: "Edit" },
+ { title: "Share" },
{
title: "Delete",
- icon: Icon.Trash,
- color: "red"
+ color: "red",
+ onClick: () => {}
}
];
const Notebook = ({ item, index, onClick, onTopicClick }) => {
@@ -46,15 +64,19 @@ const Notebook = ({ item, index, onClick, onTopicClick }) => {
</Flex>
}
info={
- <Text>
+ <Flex justifyContent="center" alignItems="center">
{new Date(notebook.dateCreated).toDateString().substring(4)}
<Text as="span">{" • " + notebook.totalNotes} Notes</Text>
- </Text>
+ {notebook.favorite && (
+ <Icon.Star size={16} style={{ marginLeft: 5 }} />
+ )}
+ </Flex>
}
+ pinned={notebook.pinned}
dropdownRefs={dropdownRefs}
index={index}
menuData={notebook}
- menuItems={menuItems}
+ menuItems={menuItems(notebook)}
/>
);
};
diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.js
index ff0cbd91d..f98ff87c9 100644
--- a/apps/web/src/views/Home.js
+++ b/apps/web/src/views/Home.js
@@ -17,8 +17,8 @@ function Home() {
useEffect(() => {
function onRefreshNotes() {
setNotes(db.groupNotes(undefined, true));
+ setPinnedItems(db.getPinned());
}
- setPinnedItems(db.getPinned());
onRefreshNotes();
ev.addListener("refreshNotes", onRefreshNotes);
return () => {