|
1 | | -import { useNoteContext, useTriliumEvent } from "./react/hooks" |
2 | | -import FNote from "../entities/fnote"; |
3 | | -import protected_session_holder from "../services/protected_session_holder"; |
| 1 | +import "./NoteDetail.css"; |
| 2 | + |
| 3 | +import { isValidElement, VNode } from "preact"; |
4 | 4 | import { useEffect, useRef, useState } from "preact/hooks"; |
| 5 | + |
5 | 6 | import NoteContext from "../components/note_context"; |
6 | | -import { isValidElement, VNode } from "preact"; |
7 | | -import { TypeWidgetProps } from "./type_widgets/type_widget"; |
8 | | -import "./NoteDetail.css"; |
| 7 | +import FNote from "../entities/fnote"; |
9 | 8 | import attributes from "../services/attributes"; |
10 | | -import { ExtendedNoteType, TYPE_MAPPINGS, TypeWidget } from "./note_types"; |
11 | | -import { dynamicRequire, isElectron, isMobile } from "../services/utils"; |
12 | | -import toast from "../services/toast.js"; |
13 | 9 | import { t } from "../services/i18n"; |
| 10 | +import protected_session_holder from "../services/protected_session_holder"; |
| 11 | +import toast from "../services/toast.js"; |
| 12 | +import { dynamicRequire, isElectron, isMobile } from "../services/utils"; |
| 13 | +import { ExtendedNoteType, TYPE_MAPPINGS, TypeWidget } from "./note_types"; |
| 14 | +import { useNoteContext, useTriliumEvent } from "./react/hooks"; |
| 15 | +import { TypeWidgetProps } from "./type_widgets/type_widget"; |
14 | 16 |
|
15 | 17 | /** |
16 | 18 | * The note detail is in charge of rendering the content of a note, by determining its type (e.g. text, code) and using the appropriate view widget. |
@@ -80,7 +82,7 @@ export default function NoteDetail() { |
80 | 82 | parentComponent.handleEvent("noteTypeMimeChanged", { noteId: note.noteId }); |
81 | 83 | } else if (note.noteId |
82 | 84 | && loadResults.isNoteReloaded(note.noteId, parentComponent.componentId) |
83 | | - && (type !== (await getWidgetType(note, noteContext)) || mime !== note?.mime)) { |
| 85 | + && (type !== (await getExtendedWidgetType(note, noteContext)) || mime !== note?.mime)) { |
84 | 86 | // this needs to have a triggerEvent so that e.g., note type (not in the component subtree) is updated |
85 | 87 | parentComponent.triggerEvent("noteTypeMimeChanged", { noteId: note.noteId }); |
86 | 88 | } else { |
@@ -212,7 +214,7 @@ export default function NoteDetail() { |
212 | 214 | isVisible={type === itemType} |
213 | 215 | isFullHeight={isFullHeight} |
214 | 216 | props={props} |
215 | | - /> |
| 217 | + />; |
216 | 218 | })} |
217 | 219 | </div> |
218 | 220 | ); |
@@ -254,7 +256,7 @@ function useNoteInfo() { |
254 | 256 | const [ mime, setMime ] = useState<string>(); |
255 | 257 |
|
256 | 258 | function refresh() { |
257 | | - getWidgetType(actualNote, noteContext).then(type => { |
| 259 | + getExtendedWidgetType(actualNote, noteContext).then(type => { |
258 | 260 | setNote(actualNote); |
259 | 261 | setType(type); |
260 | 262 | setMime(actualNote?.mime); |
@@ -282,12 +284,12 @@ async function getCorrespondingWidget(type: ExtendedNoteType): Promise<null | Ty |
282 | 284 | } else if (isValidElement(result)) { |
283 | 285 | // Direct VNode provided. |
284 | 286 | return result; |
285 | | - } else { |
286 | | - return result; |
287 | 287 | } |
| 288 | + return result; |
| 289 | + |
288 | 290 | } |
289 | 291 |
|
290 | | -async function getWidgetType(note: FNote | null | undefined, noteContext: NoteContext | undefined): Promise<ExtendedNoteType | undefined> { |
| 292 | +export async function getExtendedWidgetType(note: FNote | null | undefined, noteContext: NoteContext | undefined): Promise<ExtendedNoteType | undefined> { |
291 | 293 | if (!noteContext) return undefined; |
292 | 294 | if (!note) { |
293 | 295 | // If the note is null, then it's a new tab. If it's undefined, then it's not loaded yet. |
@@ -324,7 +326,7 @@ async function getWidgetType(note: FNote | null | undefined, noteContext: NoteCo |
324 | 326 | return resultingType; |
325 | 327 | } |
326 | 328 |
|
327 | | -function checkFullHeight(noteContext: NoteContext | undefined, type: ExtendedNoteType | undefined) { |
| 329 | +export function checkFullHeight(noteContext: NoteContext | undefined, type: ExtendedNoteType | undefined) { |
328 | 330 | if (!noteContext) return false; |
329 | 331 |
|
330 | 332 | // https://github.com/zadam/trilium/issues/2522 |
|
0 commit comments