Skip to content

Commit 9fce6c6

Browse files
authored
Ensure new entry is shown in editor and deep linking always works (#1595)
1 parent 80a3be6 commit 9fce6c6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

frontend/viewer/src/SvelteUxProjectView.svelte

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
} else if (currEntryId !== $selectedEntry?.id) {
168168
$state.userPickedEntry = true;
169169
navigateToEntryId = currEntryId;
170-
refreshSelection();
170+
void refreshSelection();
171171
}
172172
});
173173
@@ -185,21 +185,28 @@
185185
$: {
186186
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
187187
$entries;
188-
refreshSelection();
188+
void refreshSelection();
189189
}
190190
191-
//selection handling, make sure the selected entry is always in the list of entries
192-
function refreshSelection() {
191+
async function findEntry(id: string): Promise<IEntry | undefined> {
192+
const entry = $entries?.find(e => e.id === id);
193+
if (entry) return entry;
194+
if ($selectedEntry?.id === id) return $selectedEntry;
195+
return await lexboxApi.getEntry(id);
196+
}
197+
198+
//selection handling, make sure we preserve selection even if the entry is not in server-page
199+
async function refreshSelection() {
193200
if (!$entries) return;
194201
195202
if (navigateToEntryId) {
196-
const entry = $entries.find(e => e.id === navigateToEntryId);
203+
const entry = await findEntry(navigateToEntryId);
197204
if (entry) {
198205
$selectedEntry = entry;
199206
$state.userPickedEntry = true;
200207
}
201208
} else if ($selectedEntry !== undefined) {
202-
const entry = $entries.find(e => e.id === $selectedEntry!.id);
209+
const entry = await findEntry($selectedEntry.id);
203210
if (entry !== $selectedEntry) {
204211
$selectedEntry = entry;
205212
}

0 commit comments

Comments
 (0)