Read the curated photo feeds from wss://nostr.kosmos.org, verify events, cache originals and thumbnails, and let users pick a wallpaper from the Photos section. Nature is the default feed; City Nights is opt-in. Adds the manual publishing scripts, real event fixtures, protocol documentation, and tests with stubbed network connections.
117 lines
4.0 KiB
Plaintext
117 lines
4.0 KiB
Plaintext
import Component from '@glimmer/component';
|
|
import { fn } from '@ember/helper';
|
|
import { on } from '@ember/modifier';
|
|
import { service } from '@ember/service';
|
|
import PhotoThumbnail from '../../../photo-thumbnail.gjs';
|
|
|
|
// One feed card in the Photos settings section. Kept separate from the section
|
|
// shell so the thumbnail grid and feed toggle stay easy to test.
|
|
export default class SettingsPhotoFeedComponent extends Component {
|
|
@service photos;
|
|
|
|
get enabled() {
|
|
return this.photos.isFeedEnabled(this.args.feed.id);
|
|
}
|
|
|
|
get photosForFeed() {
|
|
return this.photos.photosForFeed(this.args.feed.id);
|
|
}
|
|
|
|
get currentPhotoId() {
|
|
return this.photos.currentPhoto?.id ?? null;
|
|
}
|
|
|
|
isCurrent = (photoId) => this.currentPhotoId === photoId;
|
|
|
|
select = async (photoId) => {
|
|
await this.photos.setCurrentPhoto(photoId);
|
|
};
|
|
|
|
<template>
|
|
<section
|
|
class="rounded-xl border border-gray-200 p-4"
|
|
data-test-photo-feed={{@feed.id}}
|
|
>
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div class="min-w-0">
|
|
<h4 class="text-sm font-semibold text-gray-900">
|
|
{{@feed.title}}
|
|
</h4>
|
|
<p class="mt-1 text-sm text-gray-500">
|
|
{{@feed.description}}
|
|
</p>
|
|
</div>
|
|
|
|
<label
|
|
class="relative inline-flex shrink-0 cursor-pointer items-center"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={{this.enabled}}
|
|
data-test-photo-feed-toggle={{@feed.id}}
|
|
{{on "change" (fn @onToggle @feed.id)}}
|
|
class="peer sr-only"
|
|
/>
|
|
<span class="sr-only">{{@feed.title}}</span>
|
|
<span
|
|
class="h-5 w-9 rounded-full bg-gray-200 transition-colors peer-checked:bg-indigo-600 peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-indigo-600"
|
|
></span>
|
|
<span
|
|
class="absolute left-0.5 h-4 w-4 rounded-full bg-white shadow transition-transform peer-checked:translate-x-4"
|
|
></span>
|
|
</label>
|
|
</div>
|
|
|
|
{{#if this.enabled}}
|
|
{{#if this.photosForFeed.length}}
|
|
<ul
|
|
class="mt-4 grid grid-cols-4 gap-2"
|
|
data-test-photo-grid={{@feed.id}}
|
|
>
|
|
{{#each this.photosForFeed key="id" as |photo|}}
|
|
<li>
|
|
<button
|
|
type="button"
|
|
data-test-photo={{photo.id}}
|
|
aria-pressed={{if (this.isCurrent photo.id) "true" "false"}}
|
|
{{on "click" (fn this.select photo.id)}}
|
|
class="group relative block aspect-video w-full overflow-hidden rounded-md bg-gray-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
|
>
|
|
<PhotoThumbnail @photo={{photo}} />
|
|
{{#if (this.isCurrent photo.id)}}
|
|
<span
|
|
class="absolute top-1.5 right-1.5 rounded-full bg-indigo-600 p-1 text-white shadow-sm"
|
|
aria-label="Current wallpaper"
|
|
>
|
|
<svg
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="2.5"
|
|
aria-hidden="true"
|
|
class="size-3"
|
|
>
|
|
<path
|
|
d="m5 13 4 4L19 7"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
/>
|
|
</svg>
|
|
</span>
|
|
{{/if}}
|
|
</button>
|
|
</li>
|
|
{{/each}}
|
|
</ul>
|
|
{{else if this.photos.refreshing}}
|
|
<p class="mt-4 text-sm text-gray-400">Loading photos...</p>
|
|
{{else}}
|
|
<p class="mt-4 text-sm text-gray-400">
|
|
No photos available yet.
|
|
</p>
|
|
{{/if}}
|
|
{{/if}}
|
|
</section>
|
|
</template>
|
|
}
|