2025-01-13 23:18:10 +02:00
|
|
|
import type FNote from "../entities/fnote.js";
|
2025-02-13 23:46:20 +02:00
|
|
|
import CalendarView from "../widgets/view_widgets/calendar_view.js";
|
2025-02-13 23:23:18 +02:00
|
|
|
import ListOrGridView from "../widgets/view_widgets/list_or_grid_view.js";
|
2025-06-27 17:44:29 +03:00
|
|
|
import TableView from "../widgets/view_widgets/table_view/index.js";
|
2025-02-15 10:13:47 +02:00
|
|
|
import type { ViewModeArgs } from "../widgets/view_widgets/view_mode.js";
|
2025-02-13 23:23:18 +02:00
|
|
|
import type ViewMode from "../widgets/view_widgets/view_mode.js";
|
2020-10-07 23:08:17 +02:00
|
|
|
|
2025-06-25 10:31:41 +03:00
|
|
|
export type ViewTypeOptions = "list" | "grid" | "calendar" | "table";
|
2025-02-16 18:09:01 +02:00
|
|
|
|
2025-02-13 23:23:18 +02:00
|
|
|
export default class NoteListRenderer {
|
2023-06-22 23:34:05 +02:00
|
|
|
|
2025-02-16 18:09:01 +02:00
|
|
|
private viewType: ViewTypeOptions;
|
2025-06-25 18:30:44 +03:00
|
|
|
public viewMode: ViewMode<any> | null;
|
2023-03-21 16:19:09 -04:00
|
|
|
|
2025-06-27 21:51:38 +03:00
|
|
|
constructor(args: ViewModeArgs) {
|
|
|
|
|
this.viewType = this.#getViewType(args.parentNote);
|
2025-02-13 23:46:20 +02:00
|
|
|
|
2025-06-25 10:31:41 +03:00
|
|
|
switch (this.viewType) {
|
|
|
|
|
case "list":
|
|
|
|
|
case "grid":
|
|
|
|
|
this.viewMode = new ListOrGridView(this.viewType, args);
|
|
|
|
|
break;
|
|
|
|
|
case "calendar":
|
|
|
|
|
this.viewMode = new CalendarView(args);
|
|
|
|
|
break;
|
|
|
|
|
case "table":
|
|
|
|
|
this.viewMode = new TableView(args);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
this.viewMode = null;
|
2025-02-13 23:46:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 18:09:01 +02:00
|
|
|
#getViewType(parentNote: FNote): ViewTypeOptions {
|
2025-02-13 23:46:20 +02:00
|
|
|
const viewType = parentNote.getLabelValue("viewType");
|
|
|
|
|
|
2025-06-25 10:31:41 +03:00
|
|
|
if (!["list", "grid", "calendar", "table"].includes(viewType || "")) {
|
2025-02-13 23:46:20 +02:00
|
|
|
// when not explicitly set, decide based on the note type
|
|
|
|
|
return parentNote.type === "search" ? "list" : "grid";
|
|
|
|
|
} else {
|
2025-02-16 18:09:01 +02:00
|
|
|
return viewType as ViewTypeOptions;
|
2025-02-13 23:46:20 +02:00
|
|
|
}
|
2021-01-28 23:29:10 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-21 17:17:53 +02:00
|
|
|
get isFullHeight() {
|
|
|
|
|
return this.viewMode?.isFullHeight;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 22:11:39 +02:00
|
|
|
async renderList() {
|
2025-02-13 23:46:20 +02:00
|
|
|
if (!this.viewMode) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 23:23:18 +02:00
|
|
|
return await this.viewMode.renderList();
|
2020-10-23 22:11:39 +02:00
|
|
|
}
|
2020-10-22 22:49:22 +02:00
|
|
|
|
2020-10-07 23:08:17 +02:00
|
|
|
}
|