Skip to content

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

web: settings.pins -> shortcuts migration

Abdullah Attaca1b66d68a42
diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.js
index 0b773b8b0..6ff0df88e 100644
--- a/apps/web/src/components/navigation-menu/index.js
+++ b/apps/web/src/components/navigation-menu/index.js
@@ -90,7 +90,7 @@ function NavigationMenu(props) {
const [location, previousLocation, state] = useLocation();
const isFocusMode = useAppStore((store) => store.isFocusMode);
const colors = useAppStore((store) => store.colors);
- const pins = useAppStore((store) => store.menuPins);
+ const shortcuts = useAppStore((store) => store.shortcuts);
const refreshNavItems = useAppStore((store) => store.refreshNavItems);
const isLoggedIn = useUserStore((store) => store.isLoggedIn);
const isMobile = useMobile();
@@ -188,40 +188,40 @@ function NavigationMenu(props) {
my={1}
sx={{ width: "85%", height: "0.8px", alignSelf: "center" }}
/>
- {pins.map((pin) => (
+ {shortcuts.map((item) => (
<NavigationItem
isTablet={isTablet}
- key={pin.id}
- title={pin.type === "tag" ? db.tags.alias(pin.id) : pin.title}
+ key={item.id}
+ title={item.type === "tag" ? db.tags.alias(item.id) : item.title}
menu={{
items: [
{
key: "removeshortcut",
title: () => "Remove shortcut",
- onClick: async ({ pin }) => {
- await db.settings.unpin(pin.id);
+ onClick: async ({ item }) => {
+ await db.shortcuts.remove(item.id);
refreshNavItems();
}
}
],
- extraData: { pin }
+ extraData: { item }
}}
icon={
- pin.type === "notebook"
+ item.type === "notebook"
? Notebook2
- : pin.type === "tag"
+ : item.type === "tag"
? Tag2
: Topic
}
isShortcut
- selected={shouldSelectNavItem(location, pin)}
+ selected={shouldSelectNavItem(location, item)}
onClick={() => {
- if (pin.type === "notebook") {
- _navigate(`/notebooks/${pin.id}`);
- } else if (pin.type === "topic") {
- _navigate(`/notebooks/${pin.notebookId}/${pin.id}`);
- } else if (pin.type === "tag") {
- _navigate(`/tags/${pin.id}`);
+ if (item.type === "notebook") {
+ _navigate(`/notebooks/${item.id}`);
+ } else if (item.type === "topic") {
+ _navigate(`/notebooks/${item.notebookId}/${item.id}`);
+ } else if (item.type === "tag") {
+ _navigate(`/tags/${item.id}`);
}
}}
/>
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 22accc991..c8b922d64 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -143,8 +143,8 @@ const menuItems = [
key: "shortcut",
icon: Icon.Shortcut,
title: ({ notebook }) =>
- db.settings.isPinned(notebook.id) ? "Remove shortcut" : "Create shortcut",
- onClick: ({ notebook }) => appStore.pinItemToMenu(notebook)
+ db.shortcuts.exists(notebook.id) ? "Remove shortcut" : "Create shortcut",
+ onClick: ({ notebook }) => appStore.addToShortcuts(notebook)
},
{
key: "movetotrash",
diff --git a/apps/web/src/components/tag/index.js b/apps/web/src/components/tag/index.js
index 2a768509b..58b55b7c6 100644
--- a/apps/web/src/components/tag/index.js
+++ b/apps/web/src/components/tag/index.js
@@ -39,9 +39,9 @@ const menuItems = [
{
key: "shortcut",
title: ({ tag }) =>
- db.settings.isPinned(tag.id) ? "Remove shortcut" : "Create shortcut",
+ db.shortcuts.exists(tag.id) ? "Remove shortcut" : "Create shortcut",
icon: Icon.Shortcut,
- onClick: ({ tag }) => appStore.pinItemToMenu(tag)
+ onClick: ({ tag }) => appStore.addToShortcuts(tag)
},
{
key: "delete",
diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.js
index 322aa89bb..f3b7a8635 100644
--- a/apps/web/src/components/topic/index.js
+++ b/apps/web/src/components/topic/index.js
@@ -81,9 +81,9 @@ const menuItems = [
{
key: "shortcut",
title: ({ topic }) =>
- db.settings.isPinned(topic.id) ? "Remove shortcut" : "Create shortcut",
+ db.shortcuts.exists(topic.id) ? "Remove shortcut" : "Create shortcut",
icon: Icon.Shortcut,
- onClick: ({ topic }) => appStore.pinItemToMenu(topic)
+ onClick: ({ topic }) => appStore.addToShortcuts(topic)
},
{
key: "delete",
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 7323f9827..9b32eec5d 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -48,7 +48,7 @@ class AppStore extends BaseStore {
colors = [];
globalMenu = { items: [], data: {} };
reminders = [];
- menuPins = [];
+ shortcuts = [];
lastSynced = 0;
init = () => {
@@ -101,7 +101,7 @@ class AppStore extends BaseStore {
refreshNavItems = () => {
this.set((state) => {
- state.menuPins = db.settings.pins;
+ state.shortcuts = db.shortcuts.resolved;
state.colors = db.colors.all;
});
};
@@ -158,15 +158,18 @@ class AppStore extends BaseStore {
});
};
- pinItemToMenu = async (item) => {
- if (db.settings.isPinned(item.id)) {
- await db.settings.unpin(item.id);
+ addToShortcuts = async (item) => {
+ if (db.shortcuts.exists(item.id)) {
+ await db.shortcuts.remove(item.id);
this.refreshNavItems();
showToast("success", `Shortcut removed!`);
} else {
- await db.settings.pin(item.type, {
- id: item.id,
- notebookId: item.notebookId
+ await db.shortcuts.add({
+ item: {
+ type: item.type,
+ id: item.id,
+ notebookId: item.notebookId
+ }
});
this.refreshNavItems();
showToast("success", `Shortcut created!`);
diff --git a/apps/web/src/views/topics.js b/apps/web/src/views/topics.js
index dbf62ad36..871f46716 100644
--- a/apps/web/src/views/topics.js
+++ b/apps/web/src/views/topics.js
@@ -64,13 +64,14 @@ export default Topics;
function NotebookHeader({ notebook }) {
const { title, description, topics, dateEdited } = notebook;
const [isShortcut, setIsShortcut] = useState(false);
- const menuPins = useAppStore((store) => store.menuPins);
- const pinItemToMenu = useAppStore((store) => store.pinItemToMenu);
- useEffect(() => {
- setIsShortcut(menuPins.findIndex((p) => p.id === notebook.id) > -1);
- }, [menuPins, notebook]);
+ const shortcuts = useAppStore((store) => store.shortcuts);
+ const addToShortcuts = useAppStore((store) => store.addToShortcuts);
const totalNotes = getTotalNotes(notebook);
+ useEffect(() => {
+ setIsShortcut(shortcuts.findIndex((p) => p.id === notebook.id) > -1);
+ }, [shortcuts, notebook]);
+
return (
<Flex mx={2} my={2} sx={{ flexDirection: "column" }}>
<Text variant="subBody">{formatDate(dateEdited)}</Text>
@@ -83,7 +84,7 @@ function NotebookHeader({ notebook }) {
mr={1}
p={0}
title={isShortcut ? "Remove shortcut" : "Create shortcut"}
- onClick={() => pinItemToMenu(notebook)}
+ onClick={() => addToShortcuts(notebook)}
>
{isShortcut ? (
<RemoveShortcutLink size={16} />