fix: nb cannot be unpinned if 3 nbs are pinned

This commit is contained in:
thecodrr
2021-09-13 10:24:16 +05:00
parent 47336c9028
commit e500b7c3f8
6 changed files with 24 additions and 19 deletions

View File

@@ -155,9 +155,13 @@ export default React.memo(Note, function (prevProps, nextProps) {
);
});
const pin = async (note) => {
await store.pin(note.id);
if (note.pinned) await showUnpinnedToast(note.id, "note");
const pin = (note) => {
return store
.pin(note.id)
.then(async () => {
if (note.pinned) await showUnpinnedToast(note.id, "note");
})
.catch((error) => showToast("error", error.message));
};
const menuItems = [

View File

@@ -9,6 +9,7 @@ import * as Icon from "../icons";
import { hashNavigate, navigate } from "../../navigation";
import { getTotalNotes } from "../../common";
import IconTag from "../icon-tag";
import { showToast } from "../../utils/toast";
function Notebook(props) {
const { item, index } = props;
@@ -83,9 +84,13 @@ export default React.memo(Notebook, (prev, next) => {
);
});
const pin = async (notebook) => {
await store.pin(notebook);
if (notebook.pinned) showUnpinnedToast(notebook.id, "notebook");
const pin = (notebook) => {
return store
.pin(notebook.id)
.then(() => {
if (notebook.pinned) showUnpinnedToast(notebook.id, "notebook");
})
.catch((error) => showToast("error", error.message));
};
const menuItems = [

View File

@@ -141,8 +141,10 @@ class AppStore extends BaseStore {
this.set((state) => (state.isSyncing = true));
return db
.sync(full, force)
.then(async () => {
showToast("Sync completed.");
.then(async (result) => {
if (!result) return;
showToast("success", "Sync completed.");
await this.updateLastSynced();
return await this.refresh();
})

View File

@@ -7,7 +7,6 @@ import Vault from "../common/vault";
import BaseStore from ".";
import { EV, EVENTS } from "notes-core/common";
import Config from "../utils/config";
import { showToast } from "../utils/toast";
import { qclone } from "qclone";
import { hashNavigate } from "../navigation";
import { groupArray } from "notes-core/utils/grouping";
@@ -81,11 +80,9 @@ class NoteStore extends BaseStore {
};
pin = async (id) => {
// TODO (hack) we probably shouldn't do this here.
const note = db.notes.note(id);
if (!note.data.pinned && db.notes.pinned.length >= 3) {
await showToast("error", "You cannot pin more than 3 notes.");
return;
throw new Error("You cannot pin more than 3 notes.");
}
if (!this._syncEditor(note.id, "pinned", !note.data.pinned)) {
await note.pin();

View File

@@ -3,7 +3,6 @@ import createStore from "../common/store";
import { store as appStore } from "./app-store";
import { store as noteStore } from "./note-store";
import BaseStore from "./index";
import { showToast } from "../utils/toast";
import { groupArray } from "notes-core/utils/grouping";
import Config from "../utils/config";
@@ -36,11 +35,11 @@ class NotebookStore extends BaseStore {
};
pin = async (notebookId) => {
// TODO (hack) We probably shouldn't do this here.
if (db.notebooks.pinned.length >= 3) {
return await showToast("error", "You cannot pin more than 3 notebooks.");
const notebook = db.notebooks.notebook(notebookId);
if (!notebook._notebook.pinned && db.notebooks.pinned.length >= 3) {
throw new Error("You cannot pin more than 3 notebooks.");
}
await db.notebooks.notebook(notebookId).pin();
await notebook.pin();
this.refresh();
};

View File

@@ -10,7 +10,6 @@ import {
showSessionExpiredDialog,
} from "../common/dialog-controller";
import { Text } from "rebass";
import { showToast } from "../utils/toast";
import { showAccountLoggedOutNotice } from "../common/dialog-controller";
import Config from "../utils/config";
import { onPageVisibilityChanged } from "../utils/page-visibility";
@@ -64,7 +63,6 @@ class UserStore extends BaseStore {
this.set((state) => (state.user.subscription = subscription));
});
EV.subscribe(EVENTS.userEmailConfirmed, async () => {
showToast("success", "Email confirmed successfully!");
window.location.reload();
});