fix: store.set is not a function, close #375
This commit is contained in:
1 parent
3631cb4627
commit
ababbb4371
6 files changed
+81
-28
No files matched your search
+27
-5
@@ -19,6 +19,7 @@ import {
|
|||||||
writable,
|
writable,
|
||||||
type Readable,
|
type Readable,
|
||||||
type Writable,
|
type Writable,
|
||||||
|
type Updater,
|
||||||
} from 'svelte/store'
|
} from 'svelte/store'
|
||||||
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
@@ -102,9 +103,31 @@ let fetchUser = {
|
|||||||
prevProfile: -1,
|
prevProfile: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export let profile: Readable<Profile> = derived(
|
function profileStore(
|
||||||
profileData,
|
data: Writable<ProfileData>,
|
||||||
(pd, set, update) => {
|
fn: (
|
||||||
|
values: ProfileData,
|
||||||
|
set: (value: Profile) => void,
|
||||||
|
update: (fn: Updater<Profile>) => void
|
||||||
|
) => any
|
||||||
|
) {
|
||||||
|
const derive: Readable<Profile> = derived(data, fn)
|
||||||
|
const { subscribe } = derive
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
set: (value: Profile) => {
|
||||||
|
data.update((data) => {
|
||||||
|
let index = data.profiles.findIndex((t) => t.id == value.id)
|
||||||
|
data.profiles[index] = value
|
||||||
|
return data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export let profile: Readable<Profile> & { set: (v: Profile) => void } =
|
||||||
|
profileStore(profileData, (pd, set, update) => {
|
||||||
const profile =
|
const profile =
|
||||||
pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile()
|
pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile()
|
||||||
|
|
||||||
@@ -154,8 +177,7 @@ export let profile: Readable<Profile> = derived(
|
|||||||
fetchUser.loading = false
|
fetchUser.loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
export let notifications = writable<Notifications>({
|
export let notifications = writable<Notifications>({
|
||||||
applications: 0,
|
applications: 0,
|
||||||
|
|||||||
@@ -75,6 +75,15 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
if ($profile.user) {
|
if ($profile.user) {
|
||||||
|
const c = $profile.user.moderates
|
||||||
|
.map((m) => m.community.id)
|
||||||
|
.indexOf(res.community_view.community.id)
|
||||||
|
if (c != -1) {
|
||||||
|
$profile.user.moderates[c] = {
|
||||||
|
community: res.community_view.community,
|
||||||
|
moderator: $profile.user.local_user_view.person,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$profile.user = {
|
$profile.user = {
|
||||||
...$profile.user,
|
...$profile.user,
|
||||||
moderates: [
|
moderates: [
|
||||||
@@ -85,6 +94,7 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addSubscription(res.community_view.community, true)
|
addSubscription(res.community_view.community, true)
|
||||||
}
|
}
|
||||||
@@ -106,7 +116,10 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
<form
|
||||||
|
on:submit|preventDefault={submit}
|
||||||
|
class="flex flex-col gap-4 h-full w-full"
|
||||||
|
>
|
||||||
<slot name="formtitle">
|
<slot name="formtitle">
|
||||||
<Header>{$t('routes.createCommunity')}</Header>
|
<Header>{$t('routes.createCommunity')}</Header>
|
||||||
</slot>
|
</slot>
|
||||||
|
|||||||
@@ -360,6 +360,12 @@
|
|||||||
"title": "Reset Theme",
|
"title": "Reset Theme",
|
||||||
"description": "This will reset all of your colors to the default. It is recommended to export your theme before this."
|
"description": "This will reset all of your colors to the default. It is recommended to export your theme before this."
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"community": {
|
||||||
|
"settings": {
|
||||||
|
"team": "Team",
|
||||||
|
"settings": "Settings"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cards": {
|
"cards": {
|
||||||
|
|||||||
+13
-10
@@ -22,20 +22,23 @@ export const addSubscription = (
|
|||||||
community: Community,
|
community: Community,
|
||||||
subscribe: boolean = true
|
subscribe: boolean = true
|
||||||
) => {
|
) => {
|
||||||
const pd = get(profileData)
|
const p = get(profile)
|
||||||
const p = pd.profiles.find((p) => p.id == pd.profile)
|
|
||||||
|
|
||||||
if (!p?.user) return
|
if (!p.user) return
|
||||||
|
|
||||||
if (subscribe) {
|
const index = p.user.follows.map((f) => f.community.id).indexOf(community.id)
|
||||||
profileData.set(pd)
|
|
||||||
|
if (subscribe && index == -1) {
|
||||||
|
p.user.follows.push({
|
||||||
|
// @ts-ignore
|
||||||
|
follower: p.user.follows[0]?.follower,
|
||||||
|
community: community,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
p.user.follows.splice(
|
p.user.follows.splice(index, 1)
|
||||||
p.user.follows.findIndex((i) => i.community.id == community.id),
|
|
||||||
1
|
|
||||||
)
|
|
||||||
profileData.set(pd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profile.set(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
|
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
|
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
||||||
|
import { contentPadding } from '$lib/components/ui/layout/Shell.svelte'
|
||||||
|
import { t } from '$lib/translations.js'
|
||||||
import { fullCommunityName } from '$lib/util.js'
|
import { fullCommunityName } from '$lib/util.js'
|
||||||
import type { PageData } from './$types.js'
|
import type { PageData } from './$types.js'
|
||||||
|
|
||||||
@@ -14,14 +17,22 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col gap-4 h-full">
|
<div class="flex flex-col gap-4 h-full">
|
||||||
<MultiSelect
|
<div
|
||||||
headless
|
class="sticky mx-auto z-50 max-w-full min-w-0 flex items-center gap-2"
|
||||||
options={[`${communityUrl}/settings`, `${communityUrl}/settings/team`]}
|
style="top: max(1.5rem, {$contentPadding.top}px);"
|
||||||
optionNames={['Settings', 'Team']}
|
>
|
||||||
selected={$page.url.pathname}
|
<Tabs
|
||||||
on:select={(e) => {
|
routes={[
|
||||||
goto(e.detail)
|
{
|
||||||
}}
|
href: `${communityUrl}/settings`,
|
||||||
/>
|
name: $t('routes.community.settings.settings'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${communityUrl}/team`,
|
||||||
|
name: $t('routes.community.settings.team'),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
></Tabs>
|
||||||
|
</div>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
@@ -2,6 +2,4 @@
|
|||||||
import CommunityForm from '$lib/components/lemmy/community/CommunityForm.svelte'
|
import CommunityForm from '$lib/components/lemmy/community/CommunityForm.svelte'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class=" max-w-2xl mx-auto">
|
<CommunityForm />
|
||||||
<CommunityForm />
|
|
||||||
</div>
|
|
||||||
Reference in new issue
Block a user