feat: add community creation
This commit is contained in:
1 parent
98a5a2f6f2
commit
7e76b1684c
8 files changed
+185
-6
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.7.8",
|
"version": "0.8.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
export let multiple = false
|
export let multiple = false
|
||||||
export let files: FileList | null | undefined = null
|
export let files: FileList | null | undefined = null
|
||||||
export let image = false
|
export let image = false
|
||||||
|
export let label: string | undefined = undefined
|
||||||
|
|
||||||
let previewURL = ''
|
let previewURL = ''
|
||||||
let dragover = false
|
let dragover = false
|
||||||
@@ -14,7 +15,11 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label
|
<div>
|
||||||
|
{#if label}
|
||||||
|
<span class="block my-1 text-sm font-bold">{label}</span>
|
||||||
|
{/if}
|
||||||
|
<label
|
||||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-lg
|
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-lg
|
||||||
border border-slate-300 dark:border-zinc-700 bg-white dark:bg-black
|
border border-slate-300 dark:border-zinc-700 bg-white dark:bg-black
|
||||||
cursor-pointer min-h-36 transition-colors {dragover
|
cursor-pointer min-h-36 transition-colors {dragover
|
||||||
@@ -29,7 +34,7 @@
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:dragleave|preventDefault={() => (dragover = false)}
|
on:dragleave|preventDefault={() => (dragover = false)}
|
||||||
>
|
>
|
||||||
{#if image && files}
|
{#if image && files}
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
<img
|
<img
|
||||||
@@ -44,4 +49,5 @@
|
|||||||
<p class="text-sm opacity-50">Attach a file</p>
|
<p class="text-sm opacity-50">Attach a file</p>
|
||||||
{/if}
|
{/if}
|
||||||
<input type="file" bind:files {accept} class="hidden" {multiple} />
|
<input type="file" bind:files {accept} class="hidden" {multiple} />
|
||||||
</label>
|
</label>
|
||||||
|
</div>
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import type { CommunityView } from 'lemmy-js-client'
|
import type { CommunityView } from 'lemmy-js-client'
|
||||||
import {
|
import {
|
||||||
Calendar,
|
Calendar,
|
||||||
@@ -43,6 +44,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
||||||
|
addSubscription(community_view.community, !subscribed)
|
||||||
|
|
||||||
loading.subscribing = false
|
loading.subscribing = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@
|
|||||||
<div class="block my-1 font-bold text-sm">{label}</div>
|
<div class="block my-1 font-bold text-sm">{label}</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="flex flex-col border border-slate-200 dark:border-zinc-800 rounded-md
|
class="flex flex-col border border-slate-300 dark:border-zinc-800 rounded-md
|
||||||
overflow-hidden focus-within:border-black focus-within:dark:border-white transition-colors"
|
overflow-hidden focus-within:border-black focus-within:dark:border-white transition-colors"
|
||||||
>
|
>
|
||||||
{#if previewing}
|
{#if previewing}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
InformationCircle,
|
InformationCircle,
|
||||||
MagnifyingGlass,
|
MagnifyingGlass,
|
||||||
Moon,
|
Moon,
|
||||||
|
Newspaper,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
Plus,
|
Plus,
|
||||||
Sun,
|
Sun,
|
||||||
@@ -153,6 +154,14 @@
|
|||||||
<Icon src={PencilSquare} mini width={16} />
|
<Icon src={PencilSquare} mini width={16} />
|
||||||
Post
|
Post
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
<MenuButton
|
||||||
|
link
|
||||||
|
href="/create/community"
|
||||||
|
disabled={$profile?.jwt == undefined}
|
||||||
|
>
|
||||||
|
<Icon src={Newspaper} mini width={16} />
|
||||||
|
Community
|
||||||
|
</MenuButton>
|
||||||
{#if !$profile?.jwt}
|
{#if !$profile?.jwt}
|
||||||
<span class="text-sm mx-4 my-1 py-1">
|
<span class="text-sm mx-4 my-1 py-1">
|
||||||
<Link highlight href="/login">Log in</Link> to create content.
|
<Link highlight href="/login">Log in</Link> to create content.
|
||||||
|
|||||||
+32
-1
@@ -1,6 +1,6 @@
|
|||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { MyUserInfo, PersonView } from 'lemmy-js-client'
|
import type { Community, MyUserInfo, PersonView } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export const blockUser = async (block: boolean, id: number) => {
|
export const blockUser = async (block: boolean, id: number) => {
|
||||||
@@ -17,3 +17,34 @@ export const blockUser = async (block: boolean, id: number) => {
|
|||||||
|
|
||||||
export const isBlocked = (me: MyUserInfo, user: number) =>
|
export const isBlocked = (me: MyUserInfo, user: number) =>
|
||||||
me.person_blocks.map((b) => b.target.id).includes(user)
|
me.person_blocks.map((b) => b.target.id).includes(user)
|
||||||
|
|
||||||
|
export const addSubscription = (
|
||||||
|
community: Community,
|
||||||
|
subscribe: boolean = true
|
||||||
|
) => {
|
||||||
|
const p = get(profile)
|
||||||
|
|
||||||
|
if (!p?.user) return
|
||||||
|
|
||||||
|
if (subscribe) {
|
||||||
|
profile.set({
|
||||||
|
...p,
|
||||||
|
user: {
|
||||||
|
...p.user,
|
||||||
|
follows: [
|
||||||
|
...p.user.follows,
|
||||||
|
{
|
||||||
|
community: community,
|
||||||
|
follower: p.user.local_user_view.person,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
p.user.follows.splice(
|
||||||
|
p.user.follows.findIndex((i) => i.community.id == community.id),
|
||||||
|
1
|
||||||
|
)
|
||||||
|
profile.set(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
import { searchParam } from '$lib/util.js'
|
import { searchParam } from '$lib/util.js'
|
||||||
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -96,6 +97,11 @@
|
|||||||
res.community_view.subscribed != 'NotSubscribed'
|
res.community_view.subscribed != 'NotSubscribed'
|
||||||
? 'Subscribed'
|
? 'Subscribed'
|
||||||
: 'NotSubscribed'
|
: 'NotSubscribed'
|
||||||
|
|
||||||
|
addSubscription(
|
||||||
|
community.community,
|
||||||
|
res.community_view.subscribed == 'Subscribed'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
color={community.subscribed == 'Subscribed'
|
color={community.subscribed == 'Subscribed'
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||||
|
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||||
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||||
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
|
|
||||||
|
let formData: {
|
||||||
|
name: string
|
||||||
|
displayName: string
|
||||||
|
icon: FileList | null
|
||||||
|
banner: FileList | null
|
||||||
|
sidebar: string
|
||||||
|
nsfw: boolean
|
||||||
|
postsLockedToModerators: boolean
|
||||||
|
submitting: boolean
|
||||||
|
} = {
|
||||||
|
name: '',
|
||||||
|
displayName: '',
|
||||||
|
icon: null,
|
||||||
|
banner: null,
|
||||||
|
sidebar: '',
|
||||||
|
nsfw: false,
|
||||||
|
postsLockedToModerators: false,
|
||||||
|
submitting: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!$profile?.jwt) return
|
||||||
|
if (formData.name == '' || formData.displayName == '') return
|
||||||
|
|
||||||
|
formData.submitting = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
let icon = formData.icon ? await uploadImage(formData.icon[0]) : undefined
|
||||||
|
let banner = formData.banner
|
||||||
|
? await uploadImage(formData.banner[0])
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
const res = await getClient().createCommunity({
|
||||||
|
auth: $profile.jwt,
|
||||||
|
name: formData.name,
|
||||||
|
title: formData.displayName,
|
||||||
|
description: formData.sidebar,
|
||||||
|
nsfw: formData.nsfw,
|
||||||
|
posting_restricted_to_mods: formData.postsLockedToModerators,
|
||||||
|
icon: icon,
|
||||||
|
banner: banner,
|
||||||
|
})
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: 'Your community was created.',
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
|
||||||
|
if ($profile.user) {
|
||||||
|
$profile.user = {
|
||||||
|
...$profile.user,
|
||||||
|
moderates: [
|
||||||
|
...$profile.user.moderates,
|
||||||
|
{
|
||||||
|
community: res.community_view.community,
|
||||||
|
moderator: $profile.user.local_user_view.person,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
addSubscription(res.community_view.community, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
goto(
|
||||||
|
`/c/${res.community_view.community.name}@${
|
||||||
|
new URL(res.community_view.community.actor_id).hostname
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: err as any,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
formData.submitting = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form
|
||||||
|
on:submit|preventDefault={submit}
|
||||||
|
class="flex flex-col gap-4 h-full max-w-2xl mx-auto"
|
||||||
|
>
|
||||||
|
<h1 class="text-2xl font-bold">Create Community</h1>
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
label="Name"
|
||||||
|
bind:value={formData.name}
|
||||||
|
on:input={() => {
|
||||||
|
formData.name = formData.name.toLowerCase().replaceAll(' ', '_')
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput required label="Display name" bind:value={formData.displayName} />
|
||||||
|
<FileInput label="Icon" bind:files={formData.icon} image />
|
||||||
|
<FileInput label="Banner" bind:files={formData.banner} image />
|
||||||
|
<MarkdownEditor previewButton label="Sidebar" bind:value={formData.sidebar} />
|
||||||
|
|
||||||
|
<Checkbox bind:checked={formData.nsfw}>NSFW</Checkbox>
|
||||||
|
<Checkbox bind:checked={formData.postsLockedToModerators}>
|
||||||
|
Only moderators can post
|
||||||
|
</Checkbox>
|
||||||
|
<Button
|
||||||
|
submit
|
||||||
|
color="primary"
|
||||||
|
size="lg"
|
||||||
|
class="mt-auto"
|
||||||
|
loading={formData.submitting}
|
||||||
|
disabled={formData.submitting}
|
||||||
|
>
|
||||||
|
Create
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
Reference in new issue
Block a user