Skip to content

Commit 4134f00

Browse files
Jakob Schlanstedtwerererer
authored andcommitted
refactor(note-create): remove unnecessary deep hierarchy
1 parent f15b778 commit 4134f00

File tree

13 files changed

+39
-47
lines changed

13 files changed

+39
-47
lines changed

apps/client/src/components/main_tree_executors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import appContext, { type EventData } from "./app_context.js";
2-
import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteAfterUrlOpts } from "../services/note_create.js";
2+
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
33
import treeService from "../services/tree.js";
44
import hoistedNoteService from "../services/hoisted_note.js";
55
import Component from "./component.js";
@@ -55,7 +55,7 @@ export default class MainTreeExecutors extends Component {
5555
isProtected: activeNoteContext.note.isProtected,
5656
saveSelection: false,
5757
promptForType: false,
58-
} as CreateNoteIntoUrlOpts
58+
} as CreateNoteWithUrlOpts
5959
);
6060
}
6161

@@ -84,7 +84,7 @@ export default class MainTreeExecutors extends Component {
8484
targetBranchId: node.data.branchId,
8585
isProtected: isProtected,
8686
saveSelection: false
87-
} as CreateNoteAfterUrlOpts
87+
} as CreateNoteWithUrlOpts
8888
);
8989
}
9090
}

apps/client/src/components/root_command_executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import froca from "../services/froca.js";
99
import utils from "../services/utils.js";
1010
import LlmChatPanel from "../widgets/llm_chat_panel.js";
1111
import toastService from "../services/toast.js";
12-
import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js";
12+
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
1313

1414
export default class RootCommandExecutor extends Component {
1515
editReadOnlyNoteCommand() {
@@ -242,7 +242,7 @@ export default class RootCommandExecutor extends Component {
242242
messages: [],
243243
title: "New AI Chat"
244244
}),
245-
} as CreateNoteIntoUrlOpts
245+
} as CreateNoteWithUrlOpts
246246
);
247247

248248
if (!result.note) {

apps/client/src/menus/tree_context_menu.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import treeService from "../services/tree.js";
22
import froca from "../services/froca.js";
33
import clipboard from "../services/clipboard.js";
4-
import noteCreateService, { CreateNoteAfterUrlOpts, CreateNoteIntoUrlOpts } from "../services/note_create.js";
4+
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
55
import contextMenu, { type MenuCommandItem, type MenuItem } from "./context_menu.js";
66
import appContext, { type ContextMenuCommandData, type FilteredCommandNames } from "../components/app_context.js";
77
import noteTypesService from "../services/note_types.js";
@@ -283,7 +283,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
283283
isProtected: isProtected,
284284
templateNoteId: templateNoteId,
285285
promptForType: false,
286-
} as CreateNoteAfterUrlOpts
286+
} as CreateNoteWithUrlOpts
287287
);
288288
} else if (command === "insertChildNote") {
289289
const parentNotePath = treeService.getNotePath(this.node);
@@ -296,7 +296,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
296296
isProtected: this.node.data.isProtected,
297297
templateNoteId: templateNoteId,
298298
promptForType: false,
299-
} as CreateNoteIntoUrlOpts
299+
} as CreateNoteWithUrlOpts
300300
);
301301
} else if (command === "openNoteInSplit") {
302302
const subContexts = appContext.tabManager.getActiveContext()?.getSubContexts();

apps/client/src/services/note_autocomplete.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import server from "./server.js";
22
import appContext from "../components/app_context.js";
3-
import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteIntoInboxOpts } from "./note_create.js";
3+
import noteCreateService, { CreateNoteIntoInboxOpts, CreateNoteWithUrlOpts } from "./note_create.js";
44
import froca from "./froca.js";
55
import { t } from "./i18n.js";
66
import commandRegistry from "./command_registry.js";
@@ -528,7 +528,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
528528
title: suggestion.noteTitle,
529529
activate: true,
530530
promptForType: true,
531-
} as CreateNoteIntoUrlOpts,
531+
} as CreateNoteWithUrlOpts,
532532
);
533533

534534
if (!note) return;
@@ -549,7 +549,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
549549
title: suggestion.noteTitle,
550550
activate: false,
551551
promptForType: true,
552-
} as CreateNoteIntoUrlOpts
552+
} as CreateNoteWithUrlOpts
553553
);
554554

555555
if (!note) return;

apps/client/src/services/note_create.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import dateNoteService from "../services/date_notes.js";
1717
* accepted by `note_create`.
1818
*
1919
* ## Overview
20-
* Each variant (e.g. `CreateNoteIntoUrlOpts`, `CreateNoteBeforeUrlOpts`, etc.)
21-
* extends `CreateNoteOpts` and enforces specific constraints to ensure only
22-
* valid note creation options are allowed at compile time.
20+
* Each variant extends `CreateNoteOpts` and enforces specific constraints to
21+
* ensure only valid note creation options are allowed at compile time.
2322
*
2423
* ## Type Safety
2524
* The `PromptingRule` ensures that `promptForType` and `type` stay mutually
@@ -36,10 +35,7 @@ import dateNoteService from "../services/date_notes.js";
3635
*
3736
* Hierarchy (general → specific):
3837
* - CreateNoteOpts
39-
* - CreateNoteAtUrlOpts
40-
* - CreateNoteIntoUrlOpts
41-
* - CreateNoteBeforeUrlOpts
42-
* - CreateNoteAfterUrlOpts
38+
* - CreateNoteWithUrlOpts
4339
* - CreateNoteIntoInboxOpts
4440
*/
4541

@@ -81,7 +77,7 @@ export type CreateNoteOpts = {
8177
* Serves as a base for "into", "before", and "after" variants,
8278
* sharing common URL-related fields.
8379
*/
84-
type CreateNoteWithUrlOpts = CreateNoteOpts & {
80+
export type CreateNoteWithUrlOpts = CreateNoteOpts & {
8581
// `Url` may refer to either parentNotePath or parentNoteId.
8682
// The vocabulary is inspired by existing function getNoteIdFromUrl.
8783
parentNoteUrl: string;
@@ -90,10 +86,6 @@ type CreateNoteWithUrlOpts = CreateNoteOpts & {
9086
targetBranchId: string;
9187
}
9288

93-
export type CreateNoteIntoUrlOpts = CreateNoteWithUrlOpts;
94-
export type CreateNoteBeforeUrlOpts = CreateNoteWithUrlOpts;
95-
export type CreateNoteAfterUrlOpts = CreateNoteWithUrlOpts;
96-
9789
type NeverDefineParentNoteUrlRule = {
9890
parentNoteUrl?: never;
9991
};
@@ -155,12 +147,12 @@ async function promptForType(
155147
} as CreateNoteOpts;
156148

157149
if (notePath) {
158-
resolvedOptions = resolvedOptions as CreateNoteIntoUrlOpts;
150+
resolvedOptions = resolvedOptions as CreateNoteWithUrlOpts;
159151
resolvedOptions = {
160152
...resolvedOptions,
161153
target: "into",
162154
parentNoteUrl: notePath,
163-
} as CreateNoteIntoUrlOpts;
155+
} as CreateNoteWithUrlOpts;
164156
}
165157

166158
return resolvedOptions;
@@ -274,7 +266,7 @@ async function createNoteIntoInbox(
274266
{
275267
...options,
276268
parentNoteUrl: inboxNote.noteId,
277-
} as CreateNoteIntoUrlOpts
269+
} as CreateNoteWithUrlOpts
278270
);
279271

280272
return result;

apps/client/src/widgets/collections/board/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import branches from "../../../services/branches";
66
import { executeBulkActions } from "../../../services/bulk_action";
77
import froca from "../../../services/froca";
88
import { t } from "../../../services/i18n";
9-
import note_create, { CreateNoteIntoUrlOpts } from "../../../services/note_create.js";
9+
import note_create, { CreateNoteWithUrlOpts } from "../../../services/note_create.js";
1010
import server from "../../../services/server";
1111
import { ColumnMap } from "./data";
1212

@@ -33,7 +33,7 @@ export default class BoardApi {
3333
parentNoteUrl: parentNotePath,
3434
activate: false,
3535
title,
36-
} as CreateNoteIntoUrlOpts);
36+
} as CreateNoteWithUrlOpts);
3737

3838
if (newNote && newBranch) {
3939
await this.changeColumn(newNote.noteId, column);
@@ -140,7 +140,7 @@ export default class BoardApi {
140140
activate: false,
141141
targetBranchId: relativeToBranchId,
142142
title: t("board_view.new-item"),
143-
} as CreateNoteIntoUrlOpts
143+
} as CreateNoteWithUrlOpts
144144
);
145145

146146
if (!note || !branch) {

apps/client/src/widgets/collections/table/context_menu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import froca from "../../../services/froca.js";
88
import branches from "../../../services/branches.js";
99
import Component from "../../../components/component.js";
1010
import { RefObject } from "preact";
11-
import { CreateNoteAfterUrlOpts, CreateNoteBeforeUrlOpts } from "../../../services/note_create.js";
11+
import { CreateNoteWithUrlOpts } from "../../../services/note_create.js";
1212

1313
export function useContextMenu(parentNote: FNote, parentComponent: Component | null | undefined, tabulator: RefObject<Tabulator>): Partial<EventCallBackMethods> {
1414
const events: Partial<EventCallBackMethods> = {};
@@ -185,7 +185,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
185185
customOpts: {
186186
target: "before",
187187
targetBranchId: rowData.branchId,
188-
} as CreateNoteBeforeUrlOpts
188+
} as CreateNoteWithUrlOpts
189189
})
190190
},
191191
{
@@ -199,7 +199,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
199199
customOpts: {
200200
target: "after",
201201
targetBranchId: branchId,
202-
} as CreateNoteAfterUrlOpts
202+
} as CreateNoteWithUrlOpts
203203
});
204204
}
205205
},
@@ -212,7 +212,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
212212
customOpts: {
213213
target: "after",
214214
targetBranchId: rowData.branchId,
215-
} as CreateNoteAfterUrlOpts
215+
} as CreateNoteWithUrlOpts
216216
})
217217
},
218218
{ kind: "separator" },

apps/client/src/widgets/collections/table/row_editing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EventCallBackMethods, RowComponent, Tabulator } from "tabulator-tables";
22
import { CommandListenerData } from "../../../components/app_context";
3-
import note_create, { CreateNoteOpts, CreateNoteIntoUrlOpts as CreateNoteIntoUrlOpts } from "../../../services/note_create";
3+
import note_create, { CreateNoteOpts, CreateNoteWithUrlOpts } from "../../../services/note_create";
44
import { useLegacyImperativeHandlers } from "../../react/hooks";
55
import { RefObject } from "preact";
66
import { setAttribute, setLabel } from "../../../services/attributes";
@@ -23,7 +23,7 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, attributeD
2323
{
2424
parentNoteUrl: notePath,
2525
...opts
26-
} as CreateNoteIntoUrlOpts
26+
} as CreateNoteWithUrlOpts
2727
).then(({ branch }) => {
2828
if (branch) {
2929
setTimeout(() => {

apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import appContext from "../../components/app_context";
33
import contextMenu from "../../menus/context_menu";
44
import branches from "../../services/branches";
55
import { t } from "../../services/i18n";
6-
import note_create, { CreateNoteIntoUrlOpts } from "../../services/note_create";
6+
import note_create, { CreateNoteWithUrlOpts } from "../../services/note_create";
77
import tree from "../../services/tree";
88
import ActionButton from "../react/ActionButton";
99
import { ParentComponent } from "../react/react_utils";
@@ -33,7 +33,7 @@ export default function MobileDetailMenu() {
3333
{
3434
target: "into",
3535
parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined
36-
} as CreateNoteIntoUrlOpts
36+
} as CreateNoteWithUrlOpts
3737
);
3838
} else if (command === "delete") {
3939
const notePath = appContext.tabManager.getActiveContextNotePath();

apps/client/src/widgets/note_detail.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SpacedUpdate from "../services/spaced_update.js";
55
import server from "../services/server.js";
66
import appContext, { type CommandListenerData, type EventData } from "../components/app_context.js";
77
import keyboardActionsService from "../services/keyboard_actions.js";
8-
import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js";
8+
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
99
import attributeService from "../services/attributes.js";
1010

1111
import EmptyTypeWidget from "./type_widgets/empty.js";
@@ -436,7 +436,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
436436
isProtected: note.isProtected,
437437
saveSelection: true,
438438
textEditor: await this.noteContext.getTextEditor()
439-
} as CreateNoteIntoUrlOpts
439+
} as CreateNoteWithUrlOpts
440440
);
441441
}
442442
}

0 commit comments

Comments
 (0)