web: fix type errors and broken imports

This commit is contained in:
Abdullah Atta
2024-03-07 11:06:13 +05:00
parent 3efb79308a
commit 06113db2ff
22 changed files with 47 additions and 35 deletions

View File

@@ -41,7 +41,7 @@ import { createWritableStream } from "./desktop-bridge";
import { createZipStream } from "../utils/streams/zip-stream";
import { FeatureKeys } from "../dialogs/feature-dialog";
import { ZipEntry, createUnzipIterator } from "../utils/streams/unzip-stream";
import { User } from "@notesnook/core/dist/api/user-manager";
import { User } from "@notesnook/core";
import { LegacyBackupFile } from "@notesnook/core";
import { useEditorStore } from "../stores/editor-store";

View File

@@ -187,7 +187,6 @@ function DiffViewer(props: DiffViewerProps) {
unlock={async (password) => {
const decryptedContent = await db.vault.decryptContent(
content,
session.note.id,
password
);
setContent({
@@ -271,7 +270,6 @@ function DiffViewer(props: DiffViewerProps) {
unlock={async (password) => {
const decryptedContent = await db.vault.decryptContent(
conflictedContent,
session.note.id,
password
);
setConflictedContent({

View File

@@ -34,7 +34,9 @@ import { Tag } from "@notesnook/core";
type HeaderProps = { readonly: boolean; id: string };
function Header(props: HeaderProps) {
const { readonly, id } = props;
const tags = useEditorStore((store) => store.getSession(id)?.tags || []);
const tags = useEditorStore(
(store) => store.getSession(id, ["default", "readonly"])?.tags || []
);
const refreshTags = useEditorStore((store) => store.refreshTags);
useEffect(() => {

View File

@@ -151,7 +151,7 @@ function EditorView({ id }: { id: string }) {
const isTOCVisible = useEditorStore((store) => store.isTOCVisible);
const toggleProperties = useEditorStore((store) => store.toggleProperties);
const isReadonly = useEditorStore(
(store) => store.getSession(id, ["default"])?.note?.readonly
(store) => store.getSession(id, ["default", "readonly"])?.note?.readonly
);
const isFocusMode = useAppStore((store) => store.isFocusMode);
const isPreviewSession = !!previewSession.current;

View File

@@ -62,7 +62,7 @@ function TitleBox(props: TitleBoxProps) {
useEffect(() => {
const session = useEditorStore.getState().getSession(id);
if (!session || !session.note) return;
if (!session || !("note" in session) || !session.note) return;
const { title } = session.note;
if (!inputRef.current) return;

View File

@@ -42,7 +42,7 @@ import useStatus, { statusToString } from "../../hooks/use-status";
import { ScopedThemeProvider } from "../theme-provider";
import { checkForUpdate, installUpdate } from "../../utils/updater";
import { getTimeAgo, toTitleCase } from "@notesnook/common";
import { User } from "@notesnook/core/dist/api/user-manager";
import { User } from "@notesnook/core";
function StatusBar() {
const user = useUserStore((state) => state.user);

View File

@@ -44,7 +44,7 @@ import { isUserSubscribed } from "../../hooks/use-is-user-premium";
import { SUBSCRIPTION_STATUS } from "../../common/constants";
import BaseDialog from "../../components/dialog";
import { ScopedThemeProvider } from "../../components/theme-provider";
import { User } from "@notesnook/core/dist/api/user-manager";
import { User } from "@notesnook/core";
type BuyDialogProps = {
couponCode?: string;

View File

@@ -30,7 +30,7 @@ import {
} from "./steps";
import { Authenticator, OnNextFunction } from "./types";
import { ErrorText } from "../../components/error-text";
import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
import { AuthenticatorType } from "@notesnook/core";
type MultifactorDialogProps = {
onClose: Perform;

View File

@@ -22,7 +22,7 @@ import { Perform } from "../../common/dialog-controller";
import Dialog from "../../components/dialog";
import { steps } from "./steps";
import { ErrorText } from "../../components/error-text";
import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
import { AuthenticatorType } from "@notesnook/core";
type RecoveryCodesDialogProps = {
onClose: Perform;

View File

@@ -57,7 +57,7 @@ import {
} from "./types";
import { showMultifactorDialog } from "../../common/dialog-controller";
import { ErrorText } from "../../components/error-text";
import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
import { AuthenticatorType } from "@notesnook/core";
const QRCode = React.lazy(() => import("../../re-exports/react-qrcode-logo"));

View File

@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { AuthenticatorType } from "@notesnook/core/dist/api/user-manager";
import { AuthenticatorType } from "@notesnook/core";
import { Perform } from "../../common/dialog-controller";
import { Icon } from "../../components/icons";

View File

@@ -103,8 +103,11 @@ export const BackupExportSettings: SettingsGroup[] = [
description: "Encrypt all backup files using your master key.",
isHidden: () => !useUserStore.getState().isLoggedIn,
onStateChange: (listener) => {
useUserStore.subscribe((s) => s.isLoggedIn, listener);
useSettingStore.subscribe((s) => s.encryptBackups, listener);
const subscriptions = [
useUserStore.subscribe((s) => s.isLoggedIn, listener),
useSettingStore.subscribe((s) => s.encryptBackups, listener)
];
return () => subscriptions.forEach((s) => s());
},
components: [
{

View File

@@ -22,6 +22,8 @@ import { SettingsGroup } from "./types";
import { useStore as useSettingStore } from "../../stores/setting-store";
import dayjs from "dayjs";
import { isUserPremium } from "../../hooks/use-is-user-premium";
import { TimeFormat } from "@notesnook/core/dist/utils/date";
import { TrashCleanupInterval } from "@notesnook/core";
export const BehaviourSettings: SettingsGroup[] = [
{
@@ -91,7 +93,7 @@ export const BehaviourSettings: SettingsGroup[] = [
{
type: "dropdown",
onSelectionChanged: (value) =>
useSettingStore.getState().setTimeFormat(value),
useSettingStore.getState().setTimeFormat(value as TimeFormat),
selectedOption: () => useSettingStore.getState().timeFormat,
options: [
{ value: "12-hour", title: "12h" },
@@ -121,7 +123,9 @@ export const BehaviourSettings: SettingsGroup[] = [
onSelectionChanged: (value) =>
useSettingStore
.getState()
.setTrashCleanupInterval(parseInt(value)),
.setTrashCleanupInterval(
parseInt(value) as TrashCleanupInterval
),
selectedOption: () =>
useSettingStore.getState().trashCleanupInterval.toString(),
options: [

View File

@@ -145,5 +145,5 @@ export type TextInputSettingComponent = BaseSettingComponent<"input"> & {
};
export type CustomSettingComponent = BaseSettingComponent<"custom"> & {
component: () => JSX.Element;
component: () => JSX.Element | null;
};

View File

@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { User } from "@notesnook/core/dist/api/user-manager";
import { User } from "@notesnook/core";
import { SUBSCRIPTION_STATUS } from "../common/constants";
import {
useStore as useUserStore,
@@ -30,7 +30,6 @@ export function useIsUserPremium() {
}
export function isUserPremium(user?: User) {
return true;
if (IS_TESTING) return true;
if (!user) user = userstore.get().user;
if (!user) return false;

View File

@@ -28,7 +28,7 @@ import { NNCrypto } from "./nncrypto";
import type { Cipher, SerializedKey } from "@notesnook/crypto/dist/src/types";
import { isFeatureSupported } from "../utils/feature-check";
import { IKeyStore } from "./key-store";
import { User } from "@notesnook/core/dist/api/user-manager";
import { User } from "@notesnook/core";
type EncryptedKey = { iv: Uint8Array; cipher: BufferSource };
export type DatabasePersistence = "memory" | "db";

View File

@@ -316,8 +316,9 @@ class AppStore extends BaseStore<AppStore> {
logger.error(err);
if (err.cause === "MERGE_CONFLICT") {
const sessionId = editorstore.get().session.id;
if (sessionId) await editorstore.openSession(sessionId, true);
// TODO: reopen conflicted note
// const sessionId = editorstore.get().session.id;
// if (sessionId) await editorstore.openSession(sessionId, true);
await this.refresh();
this.updateSyncStatus("conflicts");
} else {

View File

@@ -121,14 +121,14 @@ class AttachmentStore extends BaseStore<AttachmentStore> {
if (await db.attachments.remove(attachment.hash, false)) {
await this.get().refresh();
const sessionId = useEditorStore.getState().session.id;
const session = useEditorStore.getState().getActiveSession(); //.id;
if (
sessionId &&
session &&
(await db.relations
.to({ id: attachment.id, type: "attachment" }, "note")
.has(sessionId))
.has(session.id))
) {
await useEditorStore.getState().clearSession();
useEditorStore.getState().closeSessions(session.id);
}
}
} catch (e) {

View File

@@ -71,8 +71,10 @@ class NoteStore extends BaseStore<NoteStore> {
};
delete = async (...ids: string[]) => {
const { session, clearSession } = useEditorStore.getState();
if (session.id && ids.indexOf(session.id) > -1) await clearSession();
const { closeSessions, getActiveSession } = useEditorStore.getState();
const session = getActiveSession();
if (session && session.id && ids.indexOf(session.id) > -1)
closeSessions(session.id);
await db.notes.moveToTrash(...ids);
await this.refresh();
};
@@ -91,7 +93,7 @@ class NoteStore extends BaseStore<NoteStore> {
unlock = async (id: string) => {
return await Vault.unlockNote(id).then(async (res) => {
if (useEditorStore.getState().session.id === id)
if (useEditorStore.getState().getActiveSession()?.id === id)
await useEditorStore.getState().openSession(id);
await this.refresh();
return res;
@@ -101,7 +103,7 @@ class NoteStore extends BaseStore<NoteStore> {
lock = async (id: string) => {
if (!(await Vault.lockNote(id))) return false;
await this.refresh();
if (useEditorStore.getState().session.id === id)
if (useEditorStore.getState().getActiveSession()?.id === id)
await useEditorStore.getState().openSession(id, true);
};
@@ -142,8 +144,9 @@ class NoteStore extends BaseStore<NoteStore> {
action: "favorite" | "pinned" | "readonly" | "localOnly" | "color",
value: boolean | string
) => {
const { session, toggle } = useEditorStore.getState();
if (!session.id || !noteIds.includes(session.id)) return false;
const { getActiveSession, toggle } = useEditorStore.getState();
const session = getActiveSession();
if (!session || !session.id || !noteIds.includes(session.id)) return false;
toggle(session.id, action, value);
return true;
};

View File

@@ -181,7 +181,9 @@ class SettingStore extends BaseStore<SettingStore> {
this.set({ hideNoteTitle: !hideNoteTitle });
Config.set("hideNoteTitle", !hideNoteTitle);
setDocumentTitle(
!hideNoteTitle ? undefined : useEditorStore.getState().session.title
!hideNoteTitle
? undefined
: useEditorStore.getState().getActiveSession()?.title
);
};

View File

@@ -43,7 +43,7 @@ import {
showLogoutConfirmation
} from "../common/dialog-controller";
import { ErrorText } from "../components/error-text";
import { AuthenticatorType, User } from "@notesnook/core/dist/api/user-manager";
import { AuthenticatorType, User } from "@notesnook/core";
type EmailFormData = {
email: string;

View File

@@ -31,7 +31,7 @@ import { showRecoveryKeyDialog } from "../common/dialog-controller";
import Config from "../utils/config";
import { EVENTS } from "@notesnook/core/dist/common";
import { ErrorText } from "../components/error-text";
import { User } from "@notesnook/core/dist/api/user-manager";
import { User } from "@notesnook/core";
type RecoveryMethodType = "key" | "backup" | "reset";
type RecoveryMethodsFormData = Record<string, unknown>;