Handle deleted threads

This commit is contained in:
Jon Staab
2024-10-24 11:52:02 -07:00
parent 33c8142eda
commit dd7c0f3b07
13 changed files with 102 additions and 68 deletions

5
.gitignore vendored
View File

@@ -18,10 +18,9 @@ vite.config.js.timestamp-*
vite.config.ts.timestamp-* vite.config.ts.timestamp-*
# Generated assets # Generated assets
static/favicons
static/apple-touch-icon-180x180.png
static/favicon.ico static/favicon.ico
static/maskable-icon-512x512.png
static/pwa-64x64.png static/pwa-64x64.png
static/pwa-192x192.png static/pwa-192x192.png
static/pwa-512x512.png static/pwa-512x512.png
static/apple-touch-icon-180x180.png
static/maskable-icon-512x512.png

View File

@@ -15,12 +15,12 @@
<meta name="twitter:description" content="{DESCRIPTION}" /> <meta name="twitter:description" content="{DESCRIPTION}" />
<meta name="twitter:image" content="/maskable-icon-512x512.png" /> <meta name="twitter:image" content="/maskable-icon-512x512.png" />
<link rel="icon" href="/favicon.ico" sizes="48x48" /> <link rel="icon" href="/favicon.ico" sizes="48x48" />
<link rel="icon" href="/pwa-64x64.ico" sizes="any" type="image/png" /> <link rel="icon" href="/pwa-64x64.png" sizes="any" type="image/png" />
<link rel="icon" href="/pwa-192x192.ico" sizes="any" type="image/png" /> <link rel="icon" href="/pwa-192x192.png" sizes="any" type="image/png" />
<link rel="icon" href="/pwa-512x512.ico" sizes="any" type="image/png" /> <link rel="icon" href="/pwa-512x512.png" sizes="any" type="image/png" />
<link rel="icon" href="/pwa-64x64.ico" sizes="64x64" type="image/png" /> <link rel="icon" href="/pwa-64x64.png" sizes="64x64" type="image/png" />
<link rel="icon" href="/pwa-192x192.ico" sizes="192x192" type="image/png" /> <link rel="icon" href="/pwa-192x192.png" sizes="192x192" type="image/png" />
<link rel="icon" href="/pwa-512x512.ico" sizes="512x512" type="image/png" /> <link rel="icon" href="/pwa-512x512.png" sizes="512x512" type="image/png" />
<link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-touch-icon-180x180.png" /> <link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-touch-icon-180x180.png" />
%sveltekit.head% %sveltekit.head%
</head> </head>

View File

@@ -100,7 +100,7 @@
setTimeout(() => { setTimeout(() => {
loading = false loading = false
}, 3000) }, 5000)
</script> </script>
<div class="relative flex h-full w-full flex-col"> <div class="relative flex h-full w-full flex-col">

View File

@@ -11,28 +11,28 @@
</script> </script>
<div class="column menu gap-2"> <div class="column menu gap-2">
<Link href="/settings/profile"> <Link replaceState href="/settings/profile">
<CardButton> <CardButton>
<div slot="icon"><Icon icon="user-rounded" size={7} /></div> <div slot="icon"><Icon icon="user-rounded" size={7} /></div>
<div slot="title">Profile</div> <div slot="title">Profile</div>
<div slot="info">Customize your user profile</div> <div slot="info">Customize your user profile</div>
</CardButton> </CardButton>
</Link> </Link>
<Link href="/settings/relays"> <Link replaceState href="/settings/relays">
<CardButton> <CardButton>
<div slot="icon"><Icon icon="server" size={7} /></div> <div slot="icon"><Icon icon="server" size={7} /></div>
<div slot="title">Relays</div> <div slot="title">Relays</div>
<div slot="info">Control how {PLATFORM_NAME} talks to the network</div> <div slot="info">Control how {PLATFORM_NAME} talks to the network</div>
</CardButton> </CardButton>
</Link> </Link>
<Link href="/settings"> <Link replaceState href="/settings">
<CardButton> <CardButton>
<div slot="icon"><Icon icon="settings" size={7} /></div> <div slot="icon"><Icon icon="settings" size={7} /></div>
<div slot="title">Settings</div> <div slot="title">Settings</div>
<div slot="info">Get into the details about how {PLATFORM_NAME} works</div> <div slot="info">Get into the details about how {PLATFORM_NAME} works</div>
</CardButton> </CardButton>
</Link> </Link>
<Link href="/settings/about"> <Link replaceState href="/settings/about">
<CardButton> <CardButton>
<div slot="icon"><Icon icon="code-2" size={7} /></div> <div slot="icon"><Icon icon="code-2" size={7} /></div>
<div slot="title">About</div> <div slot="title">About</div>

View File

@@ -17,7 +17,7 @@
<div class="column menu gap-2"> <div class="column menu gap-2">
{#if PLATFORM_RELAY} {#if PLATFORM_RELAY}
<Link href={makeSpacePath(PLATFORM_RELAY)}> <Link replaceState href={makeSpacePath(PLATFORM_RELAY)}>
<CardButton> <CardButton>
<div slot="icon"><SpaceAvatar url={PLATFORM_RELAY} /></div> <div slot="icon"><SpaceAvatar url={PLATFORM_RELAY} /></div>
<div slot="title"><RelayName url={PLATFORM_RELAY} /></div> <div slot="title"><RelayName url={PLATFORM_RELAY} /></div>
@@ -27,7 +27,7 @@
<Divider /> <Divider />
{:else if getMembershipUrls($userMembership).length > 0} {:else if getMembershipUrls($userMembership).length > 0}
{#each getMembershipUrls($userMembership) as url (url)} {#each getMembershipUrls($userMembership) as url (url)}
<Link href={makeSpacePath(url)}> <Link replaceState href={makeSpacePath(url)}>
<CardButton> <CardButton>
<div slot="icon"><SpaceAvatar {url} /></div> <div slot="icon"><SpaceAvatar {url} /></div>
<div slot="title"><RelayName {url} /></div> <div slot="title"><RelayName {url} /></div>

View File

@@ -2,7 +2,7 @@
import {type Instance} from "tippy.js" import {type Instance} from "tippy.js"
import type {NativeEmoji} from "emoji-picker-element/shared" import type {NativeEmoji} from "emoji-picker-element/shared"
import {max} from "@welshman/lib" import {max} from "@welshman/lib"
import {deriveEvents} from "@welshman/store" import {deriveEvents, deriveIsDeleted} from "@welshman/store"
import type {TrustedEvent} from "@welshman/util" import type {TrustedEvent} from "@welshman/util"
import {pubkey, repository, formatTimestampRelative} from "@welshman/app" import {pubkey, repository, formatTimestampRelative} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
@@ -18,6 +18,8 @@
export let event export let event
export let showActivity = false export let showActivity = false
const deleted = deriveIsDeleted(repository, event)
const replies = deriveEvents(repository, {filters: [{kinds: [REPLY], "#E": [event.id]}]}) const replies = deriveEvents(repository, {filters: [{kinds: [REPLY], "#E": [event.id]}]})
const showPopover = () => popover.show() const showPopover = () => popover.show()
@@ -47,6 +49,11 @@
<ReactionSummary {event} {onReactionClick} /> <ReactionSummary {event} {onReactionClick} />
</Button> </Button>
<div class="flex flex-grow justify-end gap-2"> <div class="flex flex-grow justify-end gap-2">
{#if $deleted}
<div class="btn btn-error btn-xs rounded-full">
Deleted
</div>
{/if}
{#if showActivity} {#if showActivity}
<div class="flex-inline btn btn-neutral btn-xs gap-1 rounded-full"> <div class="flex-inline btn btn-neutral btn-xs gap-1 rounded-full">
<Icon icon="reply" /> <Icon icon="reply" />

View File

@@ -18,11 +18,13 @@
} }
const onMouseMove = throttle(300, ({clientX, clientY}: any) => { const onMouseMove = throttle(300, ({clientX, clientY}: any) => {
if (popover) {
const {x, y, width, height} = popover.popper.getBoundingClientRect() const {x, y, width, height} = popover.popper.getBoundingClientRect()
if (!between([x, x + width], clientX) || !between([y - 30, y + height + 30], clientY)) { if (!between([x, x + width], clientX) || !between([y - 30, y + height + 30], clientY)) {
popover.hide() popover.hide()
} }
}
}) })
let popover: Instance let popover: Instance

View File

@@ -3,12 +3,13 @@
export let href export let href
export let external = false export let external = false
export let replaceState = false
const go = (e: Event) => { const go = (e: Event) => {
if (!external) { if (!external) {
e.preventDefault() e.preventDefault()
goto(href) goto(href, {replaceState})
} }
} }
</script> </script>

View File

@@ -1,20 +1,26 @@
<script lang="ts"> <script lang="ts">
import {onMount} from "svelte" import {onMount} from "svelte"
import {page} from "$app/stores" import {page} from "$app/stores"
import {load} from "@welshman/app" import {subscribe} from "@welshman/app"
import {DELETE, NOTE} from "@welshman/util"
import Page from "@lib/components/Page.svelte" import Page from "@lib/components/Page.svelte"
import Delay from "@lib/components/Delay.svelte" import Delay from "@lib/components/Delay.svelte"
import SecondaryNav from "@lib/components/SecondaryNav.svelte" import SecondaryNav from "@lib/components/SecondaryNav.svelte"
import MenuSpace from "@app/components/MenuSpace.svelte" import MenuSpace from "@app/components/MenuSpace.svelte"
import {decodeRelay, MEMBERSHIPS} from "@app/state" import {decodeRelay, MEMBERSHIPS, MESSAGE, REPLY} from "@app/state"
$: url = decodeRelay($page.params.relay) $: url = decodeRelay($page.params.relay)
onMount(() => { onMount(() => {
load({ const sub = subscribe({
filters: [{kinds: [MEMBERSHIPS], "#r": [url]}], filters: [
{kinds: [DELETE], "#k": [NOTE, REPLY, MESSAGE].map(String)},
{kinds: [MEMBERSHIPS], "#r": [url]},
],
relays: [url], relays: [url],
}) })
return () => sub.close()
}) })
</script> </script>

View File

@@ -13,15 +13,18 @@
import MenuSpace from "@app/components/MenuSpace.svelte" import MenuSpace from "@app/components/MenuSpace.svelte"
import ThreadItem from "@app/components/ThreadItem.svelte" import ThreadItem from "@app/components/ThreadItem.svelte"
import ThreadCreate from "@app/components/ThreadCreate.svelte" import ThreadCreate from "@app/components/ThreadCreate.svelte"
import {deriveEventsForUrl, decodeRelay} from "@app/state" import {REPLY, deriveEventsForUrl, decodeRelay} from "@app/state"
import {pushModal, pushDrawer} from "@app/modal" import {pushModal, pushDrawer} from "@app/modal"
const url = decodeRelay($page.params.relay) const url = decodeRelay($page.params.relay)
const kinds = [NOTE] const events = deriveEventsForUrl(url, [NOTE])
const feed = makeIntersectionFeed(makeRelayFeed(url), feedFromFilter({kinds}))
const events = deriveEventsForUrl(url, kinds)
const loader = feedLoader.getLoader(feed, {})
const mutedPubkeys = getPubkeyTagValues(getListTags($userMutes)) const mutedPubkeys = getPubkeyTagValues(getListTags($userMutes))
const feed = makeIntersectionFeed(makeRelayFeed(url), feedFromFilter({kinds: [NOTE, REPLY]}))
const loader = feedLoader.getLoader(feed, {
onExhausted: () => {
loading = false
},
})
const openMenu = () => pushDrawer(MenuSpace, {url}) const openMenu = () => pushDrawer(MenuSpace, {url})
@@ -32,6 +35,8 @@
let element: Element let element: Element
onMount(() => { onMount(() => {
// Why is element not defined sometimes? SVELTEKIT
if (element) {
const scroller = createScroller({ const scroller = createScroller({
element, element,
onScroll: async () => { onScroll: async () => {
@@ -43,11 +48,8 @@
}) })
return () => scroller.stop() return () => scroller.stop()
}
}) })
setTimeout(() => {
loading = false
}, 3000)
</script> </script>
<div class="relative flex h-screen flex-col"> <div class="relative flex h-screen flex-col">

View File

@@ -97,7 +97,7 @@
setTimeout(() => { setTimeout(() => {
loading = false loading = false
}, 3000) }, 5000)
</script> </script>
<div class="relative flex h-full flex-col"> <div class="relative flex h-full flex-col">

View File

@@ -63,7 +63,7 @@
setTimeout(() => { setTimeout(() => {
loading = false loading = false
}, 3000) }, 5000)
</script> </script>
<div class="relative flex h-screen flex-col"> <div class="relative flex h-screen flex-col">

View File

@@ -1,10 +1,12 @@
<script lang="ts"> <script lang="ts">
import {sortBy} from "@welshman/lib" import {onMount} from 'svelte'
import {sortBy, sleep} from "@welshman/lib"
import {page} from "$app/stores" import {page} from "$app/stores"
import {repository} from "@welshman/app" import {repository, subscribe} from "@welshman/app"
import type {Thunk} from "@welshman/app" import type {Thunk} from "@welshman/app"
import {deriveEvents} from "@welshman/store" import {deriveEvents} from "@welshman/store"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
import Spinner from "@lib/components/Spinner.svelte"
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
import Content from "@app/components/Content.svelte" import Content from "@app/components/Content.svelte"
import NoteCard from "@app/components/NoteCard.svelte" import NoteCard from "@app/components/NoteCard.svelte"
@@ -15,7 +17,8 @@
const {relay, id} = $page.params const {relay, id} = $page.params
const url = decodeRelay(relay) const url = decodeRelay(relay)
const event = deriveEvent(id) const event = deriveEvent(id)
const replies = deriveEvents(repository, {filters: [{kinds: [REPLY], "#E": [id]}]}) const filters = [{kinds: [REPLY], "#E": [id]}]
const replies = deriveEvents(repository, {filters})
const back = () => history.back() const back = () => history.back()
@@ -30,10 +33,17 @@
const onReplySubmit = (thunk: Thunk) => {} const onReplySubmit = (thunk: Thunk) => {}
let showReply = false let showReply = false
onMount(() => {
const sub = subscribe({filters, relays: [url]})
return () => sub.close()
})
</script> </script>
<div class="relative flex flex-col-reverse gap-3 p-2"> <div class="relative flex flex-col-reverse gap-3 p-2">
<div class="absolute left-[51px] top-20 h-[calc(100%-200px)] w-[2px] bg-neutral" /> <div class="absolute left-[51px] top-20 h-[calc(100%-200px)] w-[2px] bg-neutral" />
{#if $event}
{#if !showReply} {#if !showReply}
<div class="flex justify-end p-2"> <div class="flex justify-end p-2">
<Button class="btn btn-primary" on:click={openReply}> <Button class="btn btn-primary" on:click={openReply}>
@@ -56,6 +66,13 @@
</div> </div>
<ThreadActions event={$event} {url} /> <ThreadActions event={$event} {url} />
</NoteCard> </NoteCard>
{:else}
{#await sleep(5000)}
<Spinner loading>Loading thread...</Spinner>
{:then}
<p>Failed to load thread.</p>
{/await}
{/if}
<Button class="mb-2 mt-5 flex items-center gap-2" on:click={back}> <Button class="mb-2 mt-5 flex items-center gap-2" on:click={back}>
<Icon icon="alt-arrow-left" /> <Icon icon="alt-arrow-left" />
Go back Go back