mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-24 07:29:30 +01:00
mobile: use new types from core
This commit is contained in:
@@ -98,7 +98,7 @@ export async function downloadFile(filename, data, cancelToken) {
|
||||
export async function getUploadedFileSize(hash) {
|
||||
try {
|
||||
const url = `${hosts.API_HOST}/s3?name=${hash}`;
|
||||
const token = await db.user.tokenManager.getAccessToken();
|
||||
const token = await db.tokenManager.getAccessToken();
|
||||
|
||||
const attachmentInfo = await fetch(url, {
|
||||
method: "HEAD",
|
||||
|
||||
@@ -64,7 +64,7 @@ const Actions = ({ attachment, setAttachments, fwdRef, close }) => {
|
||||
name: "Download",
|
||||
onPress: async () => {
|
||||
if (currentProgress) {
|
||||
await db.fs.cancel(attachment.metadata.hash);
|
||||
await db.fs().cancel(attachment.metadata.hash);
|
||||
useAttachmentStore.getState().remove(attachment.metadata.hash);
|
||||
}
|
||||
downloadAttachment(attachment.metadata.hash, false);
|
||||
|
||||
@@ -68,7 +68,7 @@ const DownloadAttachments = ({ close, attachments, isNote, update }) => {
|
||||
});
|
||||
canceled.current = true;
|
||||
console.log(groupId.current, "canceling groupId downloads");
|
||||
await db.fs.cancel(groupId.current);
|
||||
await db.fs().cancel(groupId.current);
|
||||
setDownloading(false);
|
||||
groupId.current = null;
|
||||
};
|
||||
|
||||
@@ -108,9 +108,9 @@ export const SessionExpired = () => {
|
||||
|
||||
const open = React.useCallback(async () => {
|
||||
try {
|
||||
let res = await db.user.tokenManager.getToken();
|
||||
let res = await db.tokenManager.getToken();
|
||||
if (!res) throw new Error("no token found");
|
||||
if (db.user.tokenManager._isTokenExpired(res))
|
||||
if (db.tokenManager._isTokenExpired(res))
|
||||
throw new Error("token expired");
|
||||
Sync.run("global", false, true, async (complete) => {
|
||||
if (!complete) {
|
||||
|
||||
@@ -517,7 +517,7 @@ export default function ReminderSheet({
|
||||
mode="date"
|
||||
onConfirm={handleConfirm}
|
||||
onCancel={hideDatePicker}
|
||||
is24Hour={db.settings?.getTimeFormat() === "24-hour"}
|
||||
is24Hour={db.settings.getTimeFormat() === "24-hour"}
|
||||
date={date || new Date(Date.now())}
|
||||
/>
|
||||
|
||||
|
||||
@@ -103,14 +103,14 @@ export const TopicsSheet = () => {
|
||||
const [topics, setTopics] = useState(
|
||||
notebook
|
||||
? qclone(
|
||||
groupArray(notebook.topics, db.settings?.getGroupOptions("topics"))
|
||||
groupArray(notebook.topics, db.settings.getGroupOptions("topics"))
|
||||
)
|
||||
: []
|
||||
);
|
||||
const currentItem = useRef<string>();
|
||||
const { fontScale } = useWindowDimensions();
|
||||
const [groupOptions, setGroupOptions] = useState(
|
||||
db.settings?.getGroupOptions("topics")
|
||||
db.settings.getGroupOptions("topics")
|
||||
);
|
||||
|
||||
const onRequestUpdate = React.useCallback(
|
||||
@@ -124,7 +124,7 @@ export const TopicsSheet = () => {
|
||||
|
||||
setTopics(
|
||||
qclone(
|
||||
groupArray(_notebook.topics, db.settings?.getGroupOptions("topics"))
|
||||
groupArray(_notebook.topics, db.settings.getGroupOptions("topics"))
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ export const TopicsSheet = () => {
|
||||
);
|
||||
|
||||
const onUpdate = useCallback(() => {
|
||||
setGroupOptions({ ...(db.settings?.getGroupOptions("topics") as any) });
|
||||
setGroupOptions({ ...(db.settings.getGroupOptions("topics") as any) });
|
||||
onRequestUpdate();
|
||||
}, [onRequestUpdate]);
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ export const useEditor = (
|
||||
id = await db.notes?.add(noteData);
|
||||
if (!note && id) {
|
||||
currentNote.current = db.notes?.note(id).data as NoteType;
|
||||
const defaultNotebook = db.settings?.getDefaultNotebook();
|
||||
const defaultNotebook = db.settings.getDefaultNotebook();
|
||||
if (!state.current.onNoteCreated && defaultNotebook) {
|
||||
onNoteCreated(id, {
|
||||
type: defaultNotebook.topic ? "topic" : "notebook",
|
||||
|
||||
@@ -40,7 +40,7 @@ const Notebook = ({ route, navigation }: NavigationProps<"Notebook">) => {
|
||||
const [notes, setNotes] = useState(
|
||||
groupArray(
|
||||
db.relations?.from(route.params.item, "note") || [],
|
||||
db.settings?.getGroupOptions("notes")
|
||||
db.settings.getGroupOptions("notes")
|
||||
)
|
||||
);
|
||||
const params = useRef<NotebookScreenParams>(route?.params);
|
||||
@@ -86,7 +86,7 @@ const Notebook = ({ route, navigation }: NavigationProps<"Notebook">) => {
|
||||
params.current.item = notebook;
|
||||
const notes = db.relations?.from(notebook, "note");
|
||||
setNotes(
|
||||
groupArray(notes || [], db.settings?.getGroupOptions("notes"))
|
||||
groupArray(notes || [], db.settings.getGroupOptions("notes"))
|
||||
);
|
||||
syncWithNavigation();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export const ColoredNotes = ({
|
||||
ColoredNotes.get = (params: NotesScreenParams, grouped = true) => {
|
||||
const notes = db.notes?.colored(params.item.id) || [];
|
||||
return grouped
|
||||
? groupArray(notes, db.settings?.getGroupOptions("notes"))
|
||||
? groupArray(notes, db.settings.getGroupOptions("notes"))
|
||||
: notes;
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export const Monographs = ({
|
||||
Monographs.get = (params: NotesScreenParams, grouped = true) => {
|
||||
const notes = db.monographs?.all || [];
|
||||
return grouped
|
||||
? groupArray(notes, db.settings?.getGroupOptions("notes"))
|
||||
? groupArray(notes, db.settings.getGroupOptions("notes"))
|
||||
: notes;
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export const TaggedNotes = ({
|
||||
TaggedNotes.get = (params: NotesScreenParams, grouped = true) => {
|
||||
const notes = db.notes?.tagged((params.item as unknown as NoteType).id) || [];
|
||||
return grouped
|
||||
? groupArray(notes, db.settings?.getGroupOptions("notes"))
|
||||
? groupArray(notes, db.settings.getGroupOptions("notes"))
|
||||
: notes;
|
||||
};
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ TopicNotes.get = (params: NotesScreenParams, grouped = true) => {
|
||||
}
|
||||
const notes = topic?.all || [];
|
||||
return grouped
|
||||
? groupArray(notes, db.settings?.getGroupOptions("notes"))
|
||||
? groupArray(notes, db.settings.getGroupOptions("notes"))
|
||||
: notes;
|
||||
};
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ export const useDragState = create<DragState>(
|
||||
const _data = clone(data);
|
||||
|
||||
presets["custom"] = _data;
|
||||
db.settings?.setToolbarConfig(
|
||||
db.settings.setToolbarConfig(
|
||||
useSettingStore.getState().deviceMode || "mobile",
|
||||
{
|
||||
preset: "custom",
|
||||
@@ -80,7 +80,7 @@ export const useDragState = create<DragState>(
|
||||
set({ data: _data, preset: "custom", customPresetData: _data });
|
||||
},
|
||||
setPreset: (preset) => {
|
||||
db.settings?.setToolbarConfig(
|
||||
db.settings.setToolbarConfig(
|
||||
useSettingStore.getState().deviceMode || "mobile",
|
||||
{
|
||||
preset,
|
||||
@@ -98,7 +98,7 @@ export const useDragState = create<DragState>(
|
||||
init: async () => {
|
||||
const user = await db.user?.getUser();
|
||||
if (!user) return;
|
||||
const toolbarConfig = db.settings?.getToolbarConfig(
|
||||
const toolbarConfig = db.settings.getToolbarConfig(
|
||||
useSettingStore.getState().deviceMode || "mobile"
|
||||
);
|
||||
if (!toolbarConfig) {
|
||||
|
||||
@@ -516,9 +516,9 @@ export const settingsGroups: SettingSection[] = [
|
||||
name: "Clear default notebook/topic",
|
||||
description: "Clear the default notebook/topic for new notes",
|
||||
modifer: () => {
|
||||
db.settings?.setDefaultNotebook(undefined);
|
||||
db.settings.setDefaultNotebook(undefined);
|
||||
},
|
||||
hidden: () => !db.settings?.getDefaultNotebook()
|
||||
hidden: () => !db.settings.getDefaultNotebook()
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -26,7 +26,7 @@ import { useThemeColors } from "@notesnook/theme";
|
||||
import { SIZE } from "../../utils/size";
|
||||
|
||||
export const TitleFormat = () => {
|
||||
const [titleFormat] = useState(db.settings?.getTitleFormat());
|
||||
const [titleFormat] = useState(db.settings.getTitleFormat());
|
||||
const inputRef = useRef<TextInput>();
|
||||
const { colors } = useThemeColors();
|
||||
|
||||
@@ -34,10 +34,10 @@ export const TitleFormat = () => {
|
||||
<>
|
||||
<Input
|
||||
onSubmit={(e) => {
|
||||
db.settings?.setTitleFormat(e.nativeEvent.text);
|
||||
db.settings.setTitleFormat(e.nativeEvent.text);
|
||||
}}
|
||||
onChangeText={(text) => {
|
||||
db.settings?.setTitleFormat(text);
|
||||
db.settings.setTitleFormat(text);
|
||||
}}
|
||||
containerStyle={{ marginTop: 6 }}
|
||||
onLayout={() => {
|
||||
|
||||
@@ -102,7 +102,7 @@ export const Trash = ({ navigation, route }: NavigationProps<"Trash">) => {
|
||||
screen="Trash"
|
||||
loading={!isFocused}
|
||||
placeholderData={PLACEHOLDER_DATA(
|
||||
db.settings?.getTrashCleanupInterval()
|
||||
db.settings.getTrashCleanupInterval()
|
||||
)}
|
||||
headerProps={{
|
||||
heading: "Trash",
|
||||
|
||||
@@ -35,7 +35,7 @@ export const useFavoriteStore = create<FavoriteStore>((set, get) => ({
|
||||
set({
|
||||
favorites: groupArray(
|
||||
db?.notes?.favorites || [],
|
||||
db.settings?.getGroupOptions("favorites")
|
||||
db.settings.getGroupOptions("favorites")
|
||||
)
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -34,7 +34,7 @@ export const useNotebookStore = create<NotebookStore>((set, get) => ({
|
||||
set({
|
||||
notebooks: groupArray(
|
||||
(db?.notebooks?.all as NotebookType[]) || [],
|
||||
db.settings?.getGroupOptions("notebooks")
|
||||
db.settings.getGroupOptions("notebooks")
|
||||
)
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -40,7 +40,7 @@ export const useNoteStore = create<NoteStore>((set, get) => ({
|
||||
set({
|
||||
notes: groupArray(
|
||||
(db.notes?.all as NoteType[]) || [],
|
||||
db.settings?.getGroupOptions("home")
|
||||
db.settings.getGroupOptions("home")
|
||||
)
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -36,7 +36,7 @@ export const useTagStore = create<TagStore>((set, get) => ({
|
||||
set({
|
||||
tags: groupArray(
|
||||
(db?.tags?.all as TagType[]) || [],
|
||||
db.settings?.getGroupOptions("tags")
|
||||
db.settings.getGroupOptions("tags")
|
||||
)
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@ export const useTrashStore = create<TrashStore>((set, get) => ({
|
||||
set({
|
||||
trash: groupArray(
|
||||
db?.trash?.all || [],
|
||||
db.settings?.getGroupOptions("trash")
|
||||
db.settings.getGroupOptions("trash")
|
||||
)
|
||||
});
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user