mirror of
https://github.com/QingWei-Li/notea.git
synced 2024-11-29 12:53:00 +03:00
change(promises): Nullability check for .catch calls
catch-nullability: For some reason, some functions that should return promises return null/undefined sometimes. This commit is purely so that that doesn't happen.
This commit is contained in:
parent
4f8d0a99cc
commit
e2ce891fc8
@ -90,7 +90,7 @@ export const EditContainer = () => {
|
||||
useEffect(() => {
|
||||
abortFindNote();
|
||||
loadNoteById(id)
|
||||
.catch((v) => console.error('Could not load note: %O', v));
|
||||
?.catch((v) => console.error('Could not load note: %O', v));
|
||||
}, [loadNoteById, abortFindNote, id]);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -9,7 +9,8 @@ const Backlinks: FC = () => {
|
||||
const { t } = useI18n();
|
||||
|
||||
useEffect(() => {
|
||||
getBackLinks().catch((v) => console.error('Error whilst getting backlinks: %O', v));
|
||||
getBackLinks()
|
||||
?.catch((v) => console.error('Error whilst getting backlinks: %O', v));
|
||||
}, [getBackLinks]);
|
||||
|
||||
if (!backlinks?.length) {
|
||||
|
@ -31,7 +31,7 @@ const EditTitle: FC<{ readOnly?: boolean }> = ({ readOnly }) => {
|
||||
(event: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const title = event.target.value;
|
||||
onNoteChange.callback({ title })
|
||||
.catch((v) => console.error('Error whilst changing title: %O', v));
|
||||
?.catch((v) => console.error('Error whilst changing title: %O', v));
|
||||
},
|
||||
[onNoteChange]
|
||||
);
|
||||
|
@ -21,7 +21,7 @@ const MenuButton = () => {
|
||||
(e: MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
sidebar.toggle()
|
||||
.catch((v) => console.error('Error whilst toggling sidebar: %O', v));
|
||||
?.catch((v) => console.error('Error whilst toggling sidebar: %O', v));
|
||||
},
|
||||
[sidebar]
|
||||
);
|
||||
|
@ -29,14 +29,14 @@ const PreviewModal: FC = () => {
|
||||
const gotoLink = useCallback(() => {
|
||||
if (note?.id) {
|
||||
router.push(note.id, undefined, { shallow: true })
|
||||
.catch((v) => console.error('Error whilst pushing to router: %O', v));
|
||||
?.catch((v) => console.error('Error whilst pushing to router: %O', v));
|
||||
}
|
||||
}, [note?.id, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.id) {
|
||||
findNote(data?.id)
|
||||
.catch((v) => console.error('Error whilst finding note %s: %O', data.id, v));
|
||||
?.catch((v) => console.error('Error whilst finding note %s: %O', data.id, v));
|
||||
}
|
||||
}, [data?.id, findNote]);
|
||||
|
||||
|
@ -20,7 +20,7 @@ const SearchModal: FC = () => {
|
||||
const onEnter = useCallback(
|
||||
(item: NoteModel) => {
|
||||
router.push(`/${item.id}`, `/${item.id}`, { shallow: true })
|
||||
.catch((v) => console.error('Error whilst pushing item to router: %O', v));
|
||||
?.catch((v) => console.error('Error whilst pushing item to router: %O', v));
|
||||
close();
|
||||
},
|
||||
[router, close]
|
||||
|
@ -28,7 +28,7 @@ const ShareModal: FC = () => {
|
||||
updateNote({
|
||||
shared: checked ? NOTE_SHARED.PUBLIC : NOTE_SHARED.PRIVATE,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst updating note: %O', v));
|
||||
?.catch((v) => console.error('Error whilst updating note: %O', v));
|
||||
},
|
||||
[updateNote]
|
||||
);
|
||||
|
@ -40,17 +40,17 @@ export const SidebarMenuItem = forwardRef<HTMLLIElement, ItemProps>(
|
||||
if (data?.id) {
|
||||
// TODO: merge with mutateNote
|
||||
removeNote(data.id)
|
||||
.catch((v) => console.error('Error whilst removing note: %O', v));
|
||||
?.catch((v) => console.error('Error whilst removing note: %O', v));
|
||||
mutateNote(data.id, {
|
||||
pinned: NOTE_PINNED.UNPINNED,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
?.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
}
|
||||
}, [close, data, mutateNote, removeNote]);
|
||||
|
||||
const doCopyLink = useCallback(() => {
|
||||
navigator.clipboard.writeText(location.origin + '/' + data?.id)
|
||||
.catch((v) => console.error('Error whilst writing to clipboard: %O', v));
|
||||
?.catch((v) => console.error('Error whilst writing to clipboard: %O', v));
|
||||
close();
|
||||
}, [close, data?.id]);
|
||||
|
||||
@ -60,7 +60,7 @@ export const SidebarMenuItem = forwardRef<HTMLLIElement, ItemProps>(
|
||||
mutateNote(data.id, {
|
||||
pinned: NOTE_PINNED.PINNED,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst mutating note: %O', v));
|
||||
?.catch((v) => console.error('Error whilst mutating note: %O', v));
|
||||
}
|
||||
}, [close, data, mutateNote]);
|
||||
|
||||
@ -70,7 +70,7 @@ export const SidebarMenuItem = forwardRef<HTMLLIElement, ItemProps>(
|
||||
mutateNote(data.id, {
|
||||
pinned: NOTE_PINNED.UNPINNED,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst mutating note: %O', v));
|
||||
?.catch((v) => console.error('Error whilst mutating note: %O', v));
|
||||
}
|
||||
}, [close, data, mutateNote]);
|
||||
|
||||
|
@ -20,7 +20,7 @@ const TrashModal: FC = () => {
|
||||
const onEnter = useCallback(
|
||||
(item: NoteModel) => {
|
||||
router.push(`/${item.id}`, `/${item.id}`, { shallow: true })
|
||||
.catch((v) => console.error('Error whilst pushing to router: %O', v));
|
||||
?.catch((v) => console.error('Error whilst pushing to router: %O', v));
|
||||
close();
|
||||
},
|
||||
[router, close]
|
||||
@ -29,7 +29,7 @@ const TrashModal: FC = () => {
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
filterNotes()
|
||||
.catch((v) => console.error('Error whilst filtering notes: %O', v));
|
||||
?.catch((v) => console.error('Error whilst filtering notes: %O', v));
|
||||
}
|
||||
}, [visible, filterNotes]);
|
||||
|
||||
|
@ -32,7 +32,7 @@ const Resizable: FC<{ width: number; children: ReactNodeLike }> = ({
|
||||
|
||||
if (width && lastWidth) {
|
||||
resize(lastWidth / width)
|
||||
.catch((v) => console.error('Error whilst resizing: %O', v));
|
||||
?.catch((v) => console.error('Error whilst resizing: %O', v));
|
||||
}
|
||||
lastWidthRef.current = width;
|
||||
}, [resize, width]);
|
||||
|
@ -23,8 +23,8 @@ export const DailyNotes: FC = () => {
|
||||
const handleChange = useCallback(
|
||||
async (_event: unknown, item: TreeOption | null) => {
|
||||
if (item) {
|
||||
updateSettings({ daily_root_id: item.id })
|
||||
.catch((v) => console.error('Error whilst updating settings: %O', v));
|
||||
await updateSettings({ daily_root_id: item.id })
|
||||
?.catch((v) => console.error('Error whilst updating settings: %O', v));
|
||||
setSelected(item);
|
||||
}
|
||||
},
|
||||
|
@ -33,7 +33,7 @@ export const SnippetInjection: FC = () => {
|
||||
useEffect(() => {
|
||||
if (IS_DEMO && settings.injection !== DEMO_INJECTION) {
|
||||
updateSettings({ injection: DEMO_INJECTION })
|
||||
.catch((v) => console.error('Error whilst updating settings: %O', v));
|
||||
?.catch((v) => console.error('Error whilst updating settings: %O', v));
|
||||
setSettings((prev) => ({ ...prev, injection: DEMO_INJECTION }));
|
||||
}
|
||||
}, [settings.injection, IS_DEMO, updateSettings, setSettings]);
|
||||
|
@ -56,11 +56,11 @@ const SidebarListItem: FC<{
|
||||
(e: MouseEvent) => {
|
||||
e.preventDefault();
|
||||
router.push(`/new?pid=` + item.id, undefined, { shallow: true })
|
||||
.catch((v) => console.error('Error whilst pushing to router: %O', v));
|
||||
?.catch((v) => console.error('Error whilst pushing to router: %O', v));
|
||||
mutateItem(item.id, {
|
||||
isExpanded: true,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
?.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
},
|
||||
[item.id, mutateItem]
|
||||
);
|
||||
|
@ -22,7 +22,7 @@ const SideBarList = () => {
|
||||
mutateItem(String(id), {
|
||||
isExpanded: true,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
?.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
},
|
||||
[mutateItem]
|
||||
);
|
||||
@ -32,7 +32,7 @@ const SideBarList = () => {
|
||||
mutateItem(String(id), {
|
||||
isExpanded: false,
|
||||
})
|
||||
.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
?.catch((v) => console.error('Error whilst mutating item: %O', v));
|
||||
},
|
||||
[mutateItem]
|
||||
);
|
||||
|
@ -42,7 +42,7 @@ const ButtonMenu = () => {
|
||||
} = UIState.useContainer();
|
||||
const onFold = useCallback(() => {
|
||||
toggle()
|
||||
.catch((v) => console.error('Error whilst toggling tool: %O', v));
|
||||
?.catch((v) => console.error('Error whilst toggling tool: %O', v));
|
||||
}, [toggle]);
|
||||
|
||||
return (
|
||||
|
@ -10,7 +10,7 @@ const Sidebar: FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
initTree()
|
||||
.catch((v) => console.error('Error whilst initialising tree: %O', v));
|
||||
?.catch((v) => console.error('Error whilst initialising tree: %O', v));
|
||||
}, [initTree]);
|
||||
|
||||
return ua?.isMobileOnly ? <MobileSidebar /> : <BrowserSidebar />;
|
||||
|
@ -163,7 +163,7 @@ const useEditor = (initNote?: NoteModel) => {
|
||||
const onEditorChange = useCallback(
|
||||
(value: () => string): void => {
|
||||
onNoteChange.callback({ content: value() })
|
||||
.catch((v) => console.error('Error whilst updating note: %O', v));
|
||||
?.catch((v) => console.error('Error whilst updating note: %O', v));
|
||||
},
|
||||
[onNoteChange]
|
||||
);
|
||||
|
@ -205,7 +205,7 @@ const useNoteTree = (initData: TreeModel = DEFAULT_TREE) => {
|
||||
(note: NoteModel) => {
|
||||
const parents = findParentTreeItems(treeRef.current, note);
|
||||
setItemsExpandState(parents, true)
|
||||
.catch((v) => console.error('Error whilst expanding item: %O', v));
|
||||
?.catch((v) => console.error('Error whilst expanding item: %O', v));
|
||||
},
|
||||
[setItemsExpandState]
|
||||
);
|
||||
|
@ -25,12 +25,12 @@ export default function useSidebar(initState = false, isMobileOnly = false) {
|
||||
|
||||
const open = useCallback(() => {
|
||||
toggle(true)
|
||||
.catch((v) => console.error('Error whilst opening sidebar: %O', v));
|
||||
?.catch((v) => console.error('Error whilst opening sidebar: %O', v));
|
||||
}, [toggle]);
|
||||
|
||||
const close = useCallback(() => {
|
||||
toggle(false)
|
||||
.catch((v) => console.error('Error whilst closing sidebar: %O', v));
|
||||
?.catch((v) => console.error('Error whilst closing sidebar: %O', v));
|
||||
}, [toggle]);
|
||||
|
||||
return { isFold, toggle, open, close };
|
||||
|
@ -19,7 +19,7 @@ const EditNotePage: NextPage<{ tree: TreeModel }> = ({ tree }) => {
|
||||
useEffect(() => {
|
||||
if (ua.isMobileOnly) {
|
||||
Router.push('/new')
|
||||
.catch((v) => console.error('Error whilst pushing /new route: %O', v));
|
||||
?.catch((v) => console.error('Error whilst pushing /new route: %O', v));
|
||||
}
|
||||
}, [ua.isMobileOnly]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user