feat: add community creation
This commit is contained in:
1 parent
98a5a2f6f2
commit
7e76b1684c
8 files changed
+210
-31
No files matched your search
@@ -5,6 +5,7 @@
|
||||
export let multiple = false
|
||||
export let files: FileList | null | undefined = null
|
||||
export let image = false
|
||||
export let label: string | undefined = undefined
|
||||
|
||||
let previewURL = ''
|
||||
let dragover = false
|
||||
@@ -14,34 +15,39 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<label
|
||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-lg
|
||||
<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
|
||||
border border-slate-300 dark:border-zinc-700 bg-white dark:bg-black
|
||||
cursor-pointer min-h-36 transition-colors {dragover
|
||||
? 'border-sky-500 text-sky-500'
|
||||
: ''}
|
||||
? 'border-sky-500 text-sky-500'
|
||||
: ''}
|
||||
"
|
||||
on:drop|preventDefault={(event) => (files = event.dataTransfer?.files)}
|
||||
on:dragover|preventDefault={(event) => {
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
dragover = true
|
||||
}
|
||||
}}
|
||||
on:dragleave|preventDefault={() => (dragover = false)}
|
||||
>
|
||||
{#if image && files}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={previewURL}
|
||||
on:load={() => {
|
||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||
}}
|
||||
class="w-full max-w-sm h-full rounded-lg"
|
||||
/>
|
||||
{:else}
|
||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||
<p class="text-sm opacity-50">Attach a file</p>
|
||||
{/if}
|
||||
<input type="file" bind:files {accept} class="hidden" {multiple} />
|
||||
</label>
|
||||
on:drop|preventDefault={(event) => (files = event.dataTransfer?.files)}
|
||||
on:dragover|preventDefault={(event) => {
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
dragover = true
|
||||
}
|
||||
}}
|
||||
on:dragleave|preventDefault={() => (dragover = false)}
|
||||
>
|
||||
{#if image && files}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<img
|
||||
src={previewURL}
|
||||
on:load={() => {
|
||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||
}}
|
||||
class="w-full max-w-sm h-full rounded-lg"
|
||||
/>
|
||||
{:else}
|
||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||
<p class="text-sm opacity-50">Attach a file</p>
|
||||
{/if}
|
||||
<input type="file" bind:files {accept} class="hidden" {multiple} />
|
||||
</label>
|
||||
</div>
|
||||
@@ -9,6 +9,7 @@
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import type { CommunityView } from 'lemmy-js-client'
|
||||
import {
|
||||
Calendar,
|
||||
@@ -43,6 +44,7 @@
|
||||
}
|
||||
|
||||
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
||||
addSubscription(community_view.community, !subscribed)
|
||||
|
||||
loading.subscribing = false
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
<div class="block my-1 font-bold text-sm">{label}</div>
|
||||
{/if}
|
||||
<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"
|
||||
>
|
||||
{#if previewing}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
InformationCircle,
|
||||
MagnifyingGlass,
|
||||
Moon,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
Plus,
|
||||
Sun,
|
||||
@@ -153,6 +154,14 @@
|
||||
<Icon src={PencilSquare} mini width={16} />
|
||||
Post
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
link
|
||||
href="/create/community"
|
||||
disabled={$profile?.jwt == undefined}
|
||||
>
|
||||
<Icon src={Newspaper} mini width={16} />
|
||||
Community
|
||||
</MenuButton>
|
||||
{#if !$profile?.jwt}
|
||||
<span class="text-sm mx-4 my-1 py-1">
|
||||
<Link highlight href="/login">Log in</Link> to create content.
|
||||
|
||||
+32
-1
@@ -1,6 +1,6 @@
|
||||
import { profile } from '$lib/auth.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'
|
||||
|
||||
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) =>
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user