feat: disable community creation on sites with it disabled

This commit is contained in:
Xyphyn committed 2023-08-13 14:32:45 -07:00
1 parent 8484ff5ed7
commit 8192239dc3
3 files changed
+18 -12

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
"version": "0.8.0",
"version": "0.8.1",
"private": true,
"scripts": {
"dev": "vite dev",
+15 -10
View File
@@ -1,10 +1,10 @@
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
import { toast } from '$lib/components/ui/toasts/toasts.js'
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
import { getClient } from '$lib/lemmy.js'
import { getClient, site } from '$lib/lemmy.js'
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
import { userSettings } from '$lib/settings.js'
import type { MyUserInfo } from 'lemmy-js-client'
import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
const getDefaultProfile = (): Profile => ({
@@ -81,11 +81,12 @@ profile.subscribe(async (p) => {
instance.set(p.instance)
// fetch the user because p.user is undefined
const user = await userFromJwt(p.jwt, p.instance)
site.set(user?.site)
profile.update(() => ({
...p,
user: user,
username: user?.local_user_view.person.name,
user: user!.user,
username: user?.user.local_user_view.person.name,
}))
})
@@ -119,7 +120,7 @@ export async function setUser(jwt: string, inst: string, username: string) {
profile.set({
...newProfile,
user: user,
user: user!.user,
})
return {
@@ -134,14 +135,18 @@ export async function setUser(jwt: string, inst: string, username: string) {
async function userFromJwt(
jwt: string,
instance: string
): Promise<PersonData | undefined> {
const myUser = (await getClient(instance).getSite({ auth: jwt })).my_user
): Promise<{ user: PersonData; site: GetSiteResponse } | undefined> {
const site = await getClient(instance).getSite({ auth: jwt })
const myUser = site.my_user
if (!myUser) return undefined
return {
unreads: 0,
reports: 0,
...myUser,
user: {
unreads: 0,
reports: 0,
...myUser,
},
site: site,
}
}
+2 -1
View File
@@ -157,7 +157,8 @@
<MenuButton
link
href="/create/community"
disabled={$profile?.jwt == undefined}
disabled={$profile?.jwt == undefined ||
$site?.site_view.local_site.community_creation_admin_only}
>
<Icon src={Newspaper} mini width={16} />
Community