Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib/modules/market/model/market.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export const $likes = createStore<RecordModel[]>([]);
// it doesn't need patching when downloads/likes move elsewhere
export const $watchface = createStore<RecordModel | null>(null);
export const $watchfaceLoading = marketApi.loadWatchfaceFx.pending;
// the owner, or a moderator (a `users` flag a superuser sets in the PocketBase admin UI): who
// may delete or unpublish the face — the watchfaces rules' test, so the menu never offers what
// the server refuses
export const $canModerate = combine($watchface, authModel.$user, (wf, user) =>
Boolean(wf && user && (wf.owner === user.id || user.moderator === true)),
);
export const $items = createStore<RecordModel[]>([]);
// creators over the "Top creators" thresholds — see lib/top-creators. Derived from the
// catalog and likes the page already holds, so it follows a like or a download as they land.
Expand Down Expand Up @@ -336,6 +342,25 @@ sample({
clock: marketApi.removeFx.done,
target: marketApi.loadMarketFx,
});
// deleted or unpublished from its own showcase page: nothing left to show there (a moderator
// can't even view an unpublished face), and the market shelf has to drop it
sample({
clock: marketApi.removeFx.done,
source: $watchface,
filter: (wf, { params }) => wf?.id === params.id,
target: navigateToMarketFx,
});
sample({
clock: marketApi.togglePublishFx.doneData,
source: $watchface,
filter: (wf, r) => wf?.id === r.id && !r.published,
target: navigateToMarketFx,
});
sample({
clock: marketApi.togglePublishFx.doneData,
filter: (r) => !r.published,
target: marketApi.loadMarketFx,
});

sample({
clock: publishToggleRequested,
Expand Down
34 changes: 34 additions & 0 deletions src/lib/modules/market/pages/watchface.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Badge } from "$lib/shared/components/badge";
import { Button } from "$lib/shared/components/button";
import { Icon } from "$lib/shared/components/icon";
import { Menu, MenuItem } from "$lib/shared/components/menu";
import { Skeleton } from "$lib/shared/components/skeleton";
import { downloadUrl, fileUrl } from "$lib/shared/api";
import { authModel } from "$lib/modules/auth/model";
Expand Down Expand Up @@ -41,6 +42,9 @@
$likePending: likePending,
editRequested,
dialScreenSet,
$canModerate: canModerate,
removeRequested,
publishToggleRequested,
} = marketModel;
const {
$bleInfo: bleInfo,
Expand All @@ -60,6 +64,10 @@
const likeCount = $derived($likes.filter((l) => l.watchface === id).length);
const liked = $derived($likes.some((l) => l.watchface === id && l.user === $user?.id));

function remove() {
if (wf && confirm($t.confirmDelete(wf.name))) removeRequested(wf);
}

// ponytail: Web Share where it exists, clipboard everywhere else — no share-sheet dependency
let copied = $state(false);

Expand Down Expand Up @@ -106,6 +114,32 @@
/>
{compact(likeCount)}
</button>
<!-- the face's other actions; add a row here, and widen the {#if} when it isn't
moderator-only -->
{#if $canModerate}
<Menu align="end">
{#snippet trigger({ toggle })}
<button
class="round type-small"
title={$t.more}
aria-label={$t.more}
onclick={toggle}
>
<Icon name="more_horiz" size={22} />
</button>
{/snippet}
{#if wf.published}
<MenuItem onClick={() => publishToggleRequested(wf)}>
<Icon name="visibility_off" size={20} />
{$t.unpublish}
</MenuItem>
{/if}
<MenuItem danger onClick={remove}>
<Icon name="delete" size={20} />
{$t.delete}
</MenuItem>
</Menu>
{/if}
</div>
{/if}
</div>
Expand Down
Loading