mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-07-10 04:21:21 +02:00
core: add getGroupOptionsById/setGroupOptionsById
This commit is contained in:
@@ -32,7 +32,8 @@ import {
|
||||
TrashCleanupInterval,
|
||||
TimeFormat,
|
||||
DayFormat,
|
||||
WeekFormat
|
||||
WeekFormat,
|
||||
GroupingByIdKey
|
||||
} from "../types.js";
|
||||
import { ICollection } from "./collection.js";
|
||||
import { SQLCachedCollection } from "../database/sql-cached-collection.js";
|
||||
@@ -66,6 +67,7 @@ const defaultSettings: SettingItemMap = {
|
||||
|
||||
"groupOptions:notes:notebooks": {},
|
||||
"groupOptions:notes:tags": {},
|
||||
"groupOptions:notes:colors": {},
|
||||
"groupOptions:trash": DEFAULT_GROUP_OPTIONS("trash"),
|
||||
"groupOptions:tags": DEFAULT_GROUP_OPTIONS("tags"),
|
||||
"groupOptions:notes": DEFAULT_GROUP_OPTIONS("notes"),
|
||||
@@ -152,29 +154,32 @@ export class Settings implements ICollection {
|
||||
return this.set(`groupOptions:${key}`, groupOptions);
|
||||
}
|
||||
|
||||
getNotebookGroupOptions(notebookId: string) {
|
||||
const notebookOptions = this.get("groupOptions:notes:notebooks");
|
||||
return notebookOptions[notebookId] || this.get("groupOptions:notes");
|
||||
}
|
||||
|
||||
async setNotebookGroupOptions(
|
||||
notebookId: string,
|
||||
async setGroupOptionsById(
|
||||
id: string,
|
||||
type: GroupingByIdKey,
|
||||
groupOptions: GroupOptions
|
||||
) {
|
||||
const notebookOptions = this.get("groupOptions:notes:notebooks");
|
||||
notebookOptions[notebookId] = groupOptions;
|
||||
return this.set("groupOptions:notes:notebooks", notebookOptions);
|
||||
const groupOptionsKey =
|
||||
type === "notebook"
|
||||
? "groupOptions:notes:notebooks"
|
||||
: type === "tag"
|
||||
? "groupOptions:notes:tags"
|
||||
: "groupOptions:notes:colors";
|
||||
|
||||
const groupOptionsMap = this.get(groupOptionsKey);
|
||||
groupOptionsMap[id] = groupOptions;
|
||||
return this.set(groupOptionsKey, groupOptionsMap);
|
||||
}
|
||||
|
||||
getTagGroupOptions(tagId: string) {
|
||||
const tagOptions = this.get("groupOptions:notes:tags");
|
||||
return tagOptions[tagId] || this.get("groupOptions:notes");
|
||||
}
|
||||
|
||||
async setTagGroupOptions(tagId: string, groupOptions: GroupOptions) {
|
||||
const tagOptions = this.get("groupOptions:notes:tags");
|
||||
tagOptions[tagId] = groupOptions;
|
||||
return this.set("groupOptions:notes:tags", tagOptions);
|
||||
getGroupOptionsById(id: string, type: GroupingByIdKey) {
|
||||
const groupOptions = this.get(
|
||||
type === "notebook"
|
||||
? "groupOptions:notes:notebooks"
|
||||
: type === "tag"
|
||||
? "groupOptions:notes:tags"
|
||||
: "groupOptions:notes:colors"
|
||||
);
|
||||
return groupOptions[id] || this.get("groupOptions:notes");
|
||||
}
|
||||
|
||||
setToolbarConfig(platform: ToolbarConfigPlatforms, config: ToolbarConfig) {
|
||||
|
||||
@@ -57,6 +57,7 @@ export const GroupingKey = [
|
||||
"search"
|
||||
] as const;
|
||||
export type GroupingKey = (typeof GroupingKey)[number];
|
||||
export type GroupingByIdKey = "notebook" | "tag" | "color";
|
||||
|
||||
export type ValueOf<T> = T[keyof T];
|
||||
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
||||
@@ -487,7 +488,9 @@ export type SettingItemMap = {
|
||||
profile: Profile | undefined;
|
||||
} & Record<`groupOptions:${GroupingKey}`, GroupOptions> &
|
||||
Record<
|
||||
`groupOptions:notes:notebooks` | `groupOptions:notes:tags`,
|
||||
| `groupOptions:notes:notebooks`
|
||||
| `groupOptions:notes:tags`
|
||||
| `groupOptions:notes:colors`,
|
||||
Record<string, GroupOptions>
|
||||
> &
|
||||
Record<`toolbarConfig:${ToolbarConfigPlatforms}`, ToolbarConfig | undefined> &
|
||||
|
||||
Reference in New Issue
Block a user