diff --git a/src/lib/api/ipc/bookmarks.ts b/src/lib/api/ipc/bookmarks.ts index c235a4157..9e0487eae 100644 --- a/src/lib/api/ipc/bookmarks.ts +++ b/src/lib/api/ipc/bookmarks.ts @@ -5,6 +5,8 @@ export type Bookmark = { timestampMs: number; note: string; deleted: boolean; + updatedTimestampMs: number; + createdTimestampMs: number; }; export const upsert = (params: { diff --git a/src/lib/stores/bookmarks.ts b/src/lib/stores/bookmarks.ts index 8ad1f56a5..fb57356de 100644 --- a/src/lib/stores/bookmarks.ts +++ b/src/lib/stores/bookmarks.ts @@ -1,15 +1,15 @@ -import { writable, type Loadable } from 'svelte-loadable-store'; +import { writable, type Loadable, derived } from 'svelte-loadable-store'; import { bookmarks, type Bookmark } from '$lib/api'; -import { get, type Readable } from '@square/svelte-store'; +import { get as getValue, type Readable } from '@square/svelte-store'; const stores: Record>> = {}; -export default (params: { projectId: string }) => { +export const list = (params: { projectId: string }) => { if (params.projectId in stores) return stores[params.projectId]; const store = writable(bookmarks.list(params), (set) => bookmarks.subscribe(params, (bookmark) => { - const oldValue = get(store); + const oldValue = getValue(store); if (oldValue.isLoading) { bookmarks.list(params).then(set); } else { @@ -20,3 +20,8 @@ export default (params: { projectId: string }) => { stores[params.projectId] = store; return store as Readable>; }; + +export const get = (params: { projectId: string; timestampMs: number }) => + derived(list({ projectId: params.projectId }), (bookmarks) => + bookmarks.find((b) => b.timestampMs === params.timestampMs) + ); diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index 465161bef..d7eab9103 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -1,5 +1,5 @@ export { default as user } from './user'; -export { default as bookmarks } from './bookmarks'; +export * as bookmarks from './bookmarks'; export { default as deltas } from './deltas'; export { default as sessions } from './sessions'; export { default as files } from './files'; diff --git a/src/routes/projects/[projectId]/player/[date]/SessionCard.svelte b/src/routes/projects/[projectId]/player/[date]/SessionCard.svelte index a678d04bd..12203c8d3 100644 --- a/src/routes/projects/[projectId]/player/[date]/SessionCard.svelte +++ b/src/routes/projects/[projectId]/player/[date]/SessionCard.svelte @@ -11,7 +11,7 @@ export let currentFilepath: string; export let deltas: Record; - $: bookmarks = derived(stores.bookmarks({ projectId: session.projectId }), (bookmarks) => { + $: bookmarks = derived(stores.bookmarks.list({ projectId: session.projectId }), (bookmarks) => { if (bookmarks.isLoading) return []; const timestamps = Object.values(deltas ?? {}).flatMap((deltas) => deltas.map((d) => d.timestampMs) diff --git a/src/routes/projects/[projectId]/player/[date]/[sessionId]/+page.svelte b/src/routes/projects/[projectId]/player/[date]/[sessionId]/+page.svelte index 4dd6c1d90..d1436c688 100644 --- a/src/routes/projects/[projectId]/player/[date]/[sessionId]/+page.svelte +++ b/src/routes/projects/[projectId]/player/[date]/[sessionId]/+page.svelte @@ -32,6 +32,7 @@ import { unsubscribe } from '$lib/utils'; import { hotkeys, stores } from '$lib'; import Filename from './Filename.svelte'; + import Bookmark from './Bookmark.svelte'; export let data: PageData; const { currentFilepath, currentTimestamp } = data; @@ -48,7 +49,7 @@ const fileFilter = derived(page, (page) => page.url.searchParams.get('file')); const projectId = derived(page, (page) => page.params.projectId); - $: bookmarks = stores.bookmarks({ projectId: $projectId }); + $: bookmarks = stores.bookmarks.list({ projectId: $projectId }); const richSessions = asyncDerived( [dateSessions, fileFilter, projectId], @@ -231,15 +232,7 @@ {#if currentDelta} -
+
+ +
+ +
{/if}
+ import { events, stores } from '$lib'; + import { format } from 'date-fns'; + + export let projectId: string; + export let timestampMs: number; + + $: bookmark = stores.bookmarks.get({ projectId, timestampMs }); + + +{#if !$bookmark.isLoading && $bookmark.value && $bookmark.value.note.length && !$bookmark.value.deleted} + +{/if} diff --git a/src/routes/projects/[projectId]/player/[date]/[sessionId]/Filename.svelte b/src/routes/projects/[projectId]/player/[date]/[sessionId]/Filename.svelte index b1234d81c..a7d0988c3 100644 --- a/src/routes/projects/[projectId]/player/[date]/[sessionId]/Filename.svelte +++ b/src/routes/projects/[projectId]/player/[date]/[sessionId]/Filename.svelte @@ -15,7 +15,13 @@ : bookmarks.value.find((bookmark) => bookmark.timestampMs === timestampMs); -
+
{collapse(filename)}