cleanup: use ReactiveState to provide $state with sveltekit (#492)
This commit is contained in:
1 parent
589db4dcc7
commit
7c46e616f8
18 files changed
+168
-168
No files matched your search
@@ -3,16 +3,16 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{data.community.community_view.community.title}</title>
|
||||
<title>{data.community.value.community_view.community.title}</title>
|
||||
|
||||
<meta
|
||||
name="og:title"
|
||||
content={data.community.community_view.community.title}
|
||||
content={data.community.value.community_view.community.title}
|
||||
/>
|
||||
{#if data.community.community_view.community.description}
|
||||
{#if data.community.value.community_view.community.description}
|
||||
<meta
|
||||
name="og:description"
|
||||
content={data.community.community_view.community.description}
|
||||
content={data.community.value.community_view.community.description}
|
||||
/>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte'
|
||||
|
||||
export async function load(req: any) {
|
||||
const community = await getClient(undefined, req.fetch).getCommunity({
|
||||
@@ -7,7 +8,7 @@ export async function load(req: any) {
|
||||
})
|
||||
|
||||
return {
|
||||
community: community,
|
||||
community: new ReactiveState(community),
|
||||
slots: {
|
||||
sidebar: {
|
||||
component: CommunityCard,
|
||||
|
||||
@@ -21,11 +21,7 @@
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
|
||||
let { data: pageData } = $props()
|
||||
let data = $state(pageData)
|
||||
$effect(() => {
|
||||
data = pageData
|
||||
})
|
||||
let { data } = $props()
|
||||
|
||||
let sidebar: boolean = $state(false)
|
||||
|
||||
@@ -33,14 +29,14 @@
|
||||
if (browser)
|
||||
setSessionStorage(
|
||||
'lastSeenCommunity',
|
||||
data.community.community_view.community,
|
||||
data.community.value.community_view.community,
|
||||
)
|
||||
|
||||
resumables.add({
|
||||
name: data.community.community_view.community.title,
|
||||
name: data.community.value.community_view.community.title,
|
||||
type: 'community',
|
||||
url: page.url.toString(),
|
||||
avatar: data.community.community_view.community.icon,
|
||||
avatar: data.community.value.community_view.community.icon,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -60,8 +56,8 @@
|
||||
{/snippet}
|
||||
<div>
|
||||
<CommunityCard
|
||||
bind:community_view={data.community.community_view}
|
||||
moderators={data.community.moderators}
|
||||
bind:community_view={data.community.value.community_view}
|
||||
moderators={data.community.value.moderators}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -71,11 +67,11 @@
|
||||
<Header pageHeader>
|
||||
<div class="flex flex-col w-full">
|
||||
<CommunityHeader
|
||||
bind:community={data.community.community_view.community}
|
||||
bind:subscribed={data.community.community_view.subscribed}
|
||||
blocked={data.community.community_view.blocked}
|
||||
moderators={data.community.moderators}
|
||||
counts={data.community.community_view.counts}
|
||||
bind:community={data.community.value.community_view.community}
|
||||
bind:subscribed={data.community.value.community_view.subscribed}
|
||||
blocked={data.community.value.community_view.blocked}
|
||||
moderators={data.community.value.moderators}
|
||||
counts={data.community.value.community_view.counts}
|
||||
class="w-full relative"
|
||||
/>
|
||||
</div>
|
||||
@@ -85,7 +81,7 @@
|
||||
</Header>
|
||||
|
||||
{#if profile.data.user}
|
||||
{#if !data.community.discussion_languages.every( (l) => profile.data.user?.discussion_languages.includes(l), ) && profile.data.user.discussion_languages.length > 0}
|
||||
{#if !data.community.value.discussion_languages.every( (l) => profile.data.user?.discussion_languages.includes(l), ) && profile.data.user.discussion_languages.length > 0}
|
||||
<Note class="!p-1 !pl-3 flex-col md:flex-row">
|
||||
{$t('routes.community.languageWarning')}
|
||||
<Button
|
||||
@@ -104,7 +100,7 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if data.community.community_view.blocked}
|
||||
{#if data.community.value.community_view.blocked}
|
||||
<Placeholder
|
||||
icon={XMark}
|
||||
title="Blocked"
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
let communityUrl = $derived(
|
||||
`/c/${fullCommunityName(
|
||||
data.community.community_view.community.name,
|
||||
data.community.community_view.community.actor_id,
|
||||
data.community.value.community_view.community.name,
|
||||
data.community.value.community_view.community.actor_id,
|
||||
)}`,
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -10,23 +10,26 @@
|
||||
<Header pageHeader>
|
||||
<span>Settings</span>
|
||||
{#snippet extended()}
|
||||
<CommunityTitle community={data.community.community_view.community} />
|
||||
<CommunityTitle
|
||||
community={data.community.value.community_view.community}
|
||||
/>
|
||||
{/snippet}
|
||||
</Header>
|
||||
<CommunityForm
|
||||
edit={data.community.community_view.community.id}
|
||||
edit={data.community.value.community_view.community.id}
|
||||
formData={{
|
||||
name: data.community.community_view.community.name,
|
||||
displayName: data.community.community_view.community.title,
|
||||
nsfw: data.community.community_view.community.nsfw,
|
||||
name: data.community.value.community_view.community.name,
|
||||
displayName: data.community.value.community_view.community.title,
|
||||
nsfw: data.community.value.community_view.community.nsfw,
|
||||
postsLockedToModerators:
|
||||
data.community.community_view.community.posting_restricted_to_mods,
|
||||
sidebar: data.community.community_view.community.description ?? '',
|
||||
icon: data.community.community_view.community.icon,
|
||||
banner: data.community.community_view.community.banner,
|
||||
visibility: data.community.community_view.community.visibility,
|
||||
data.community.value.community_view.community
|
||||
.posting_restricted_to_mods,
|
||||
sidebar: data.community.value.community_view.community.description ?? '',
|
||||
icon: data.community.value.community_view.community.icon,
|
||||
banner: data.community.value.community_view.community.banner,
|
||||
visibility: data.community.value.community_view.community.visibility,
|
||||
submitting: false,
|
||||
languages: data.community.discussion_languages,
|
||||
languages: data.community.value.discussion_languages,
|
||||
}}
|
||||
>
|
||||
{#snippet formtitle()}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
data: PageData
|
||||
}
|
||||
|
||||
let { data: pageData }: Props = $props()
|
||||
let data = $state(pageData)
|
||||
let { data }: Props = $props()
|
||||
|
||||
let formData = $state({
|
||||
newModerator: '',
|
||||
@@ -33,10 +32,10 @@
|
||||
const addModRes = await getClient().addModToCommunity({
|
||||
added: true,
|
||||
person_id: Number(formData.newModerator),
|
||||
community_id: data.community.community_view.community.id,
|
||||
community_id: data.community.value.community_view.community.id,
|
||||
})
|
||||
|
||||
data.community.moderators = addModRes.moderators
|
||||
data.community.value.moderators = addModRes.moderators
|
||||
toast({
|
||||
content: $t('toast.addMod'),
|
||||
type: 'success',
|
||||
@@ -52,10 +51,10 @@
|
||||
const addModRes = await getClient().addModToCommunity({
|
||||
added: true,
|
||||
person_id: res.person.person.id,
|
||||
community_id: data.community.community_view.community.id,
|
||||
community_id: data.community.value.community_view.community.id,
|
||||
})
|
||||
|
||||
data.community.moderators = addModRes.moderators
|
||||
data.community.value.moderators = addModRes.moderators
|
||||
|
||||
toast({
|
||||
content: $t('toast.addMod'),
|
||||
@@ -86,11 +85,11 @@
|
||||
try {
|
||||
const res = await getClient().addModToCommunity({
|
||||
added: false,
|
||||
community_id: data.community.community_view.community.id,
|
||||
community_id: data.community.value.community_view.community.id,
|
||||
person_id: id,
|
||||
})
|
||||
|
||||
data.community.moderators = res.moderators
|
||||
data.community.value.moderators = res.moderators
|
||||
|
||||
toast({
|
||||
content: $t('toast.updateMods'),
|
||||
@@ -107,7 +106,7 @@
|
||||
|
||||
<Header pageHeader>Moderators</Header>
|
||||
<ul class="divide-y divide-slate-200 dark:divide-zinc-800">
|
||||
{#each data.community.moderators as moderator (moderator.moderator.id)}
|
||||
{#each data.community.value.moderators as moderator (moderator.moderator.id)}
|
||||
<div
|
||||
class="py-4 flex items-center gap-2 justify-between"
|
||||
animate:flip={{ duration: 300 }}
|
||||
|
||||
Reference in new issue
Block a user