From 7925e631065c6a7cd609b37c2785fb9e6d538b2f Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sat, 15 Feb 2025 15:54:43 +0100 Subject: [PATCH] Yay lazy loading At long last. --- src/components/ModalVault.svelte | 49 +++-- src/components/lazy-loader/LazyLoader.svelte | 208 ++++++++++++++++++ src/components/lazy-loader/Placeholder.svelte | 15 ++ 3 files changed, 253 insertions(+), 19 deletions(-) create mode 100644 src/components/lazy-loader/LazyLoader.svelte create mode 100644 src/components/lazy-loader/Placeholder.svelte diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index ad55ae0..e4e8f64 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -28,6 +28,7 @@ import { cancelable, CancelablePromise } from 'cancelable-promise' import { debounce } from 'lodash-es' import type OmnisearchPlugin from '../main' + import LazyLoader from './lazy-loader/LazyLoader.svelte' export let modal: OmnisearchVaultModal export let previousQuery: string | undefined @@ -111,9 +112,7 @@ async function prevSearchHistory() { // Filter out the empty string, if it's there - const history = (await plugin.searchHistory.getHistory()).filter( - s => s - ) + const history = (await plugin.searchHistory.getHistory()).filter(s => s) if (++historySearchIndex >= history.length) { historySearchIndex = 0 } @@ -122,9 +121,7 @@ } async function nextSearchHistory() { - const history = (await plugin.searchHistory.getHistory()).filter( - s => s - ) + const history = (await plugin.searchHistory.getHistory()).filter(s => s) if (--historySearchIndex < 0) { historySearchIndex = history.length ? history.length - 1 : 0 } @@ -240,10 +237,18 @@ // Generate link let link: string if (file && active) { - link = plugin.app.fileManager.generateMarkdownLink(file, active.path, "", selectedNote.displayTitle) + link = plugin.app.fileManager.generateMarkdownLink( + file, + active.path, + '', + selectedNote.displayTitle + ) } else { - const maybeDisplayTitle = selectedNote.displayTitle === "" ? "" : `|${selectedNote.displayTitle}` - link = `[[${selectedNote.basename}.${getExtension(selectedNote.path)}${maybeDisplayTitle}]]` + const maybeDisplayTitle = + selectedNote.displayTitle === '' ? '' : `|${selectedNote.displayTitle}` + link = `[[${selectedNote.basename}.${getExtension( + selectedNote.path + )}${maybeDisplayTitle}]]` } // Inject link @@ -255,7 +260,7 @@ modal.close() } - function switchToInFileModal(): void { + function switchToInFileModal(): void { // Do nothing if the selectedNote is a PDF, // or if there is 0 match (e.g indexing in progress) if ( @@ -323,15 +328,21 @@ {#each resultNotes as result, i} - + + + {/each}
{#if !resultNotes.length && searchQuery && !searching} diff --git a/src/components/lazy-loader/LazyLoader.svelte b/src/components/lazy-loader/LazyLoader.svelte new file mode 100644 index 0000000..fa942bf --- /dev/null +++ b/src/components/lazy-loader/LazyLoader.svelte @@ -0,0 +1,208 @@ +
+ {#if loaded} +
+ Lazy load content +
+ {#if !contentShow && placeholder} + + {/if} + {:else if placeholder} + + {/if} +
+ + \ No newline at end of file diff --git a/src/components/lazy-loader/Placeholder.svelte b/src/components/lazy-loader/Placeholder.svelte new file mode 100644 index 0000000..cc5f9c4 --- /dev/null +++ b/src/components/lazy-loader/Placeholder.svelte @@ -0,0 +1,15 @@ +{#if placeholder} +
+ {#if typeof placeholder === 'string'} +
{placeholder}
+ {:else if ['function', 'object'].includes(typeof placeholder)} + + {/if} +
+{/if} + + \ No newline at end of file