misc: more clearly indicate selected community

This commit is contained in:
Xylight committed 2024-02-26 16:24:27 -08:00
1 parent ea72f6697f
commit ac504b8bce
4 files changed
+42 -41

No files matched your search

+35 -26
View File
@@ -11,6 +11,7 @@
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import { Button } from 'mono-svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
export let edit = false
@@ -19,15 +20,10 @@
*/
export let editingPost: Post | undefined = undefined
export let passedCommunity:
| {
id: number
name: string
}
| undefined = undefined
export let passedCommunity: Community | undefined = undefined
export let data: {
community: number | null
community: Community | null
title: string
body: string
image: FileList | null
@@ -59,7 +55,7 @@
}
if (passedCommunity) {
data.community = passedCommunity.id
data.community = passedCommunity
communitySearch = passedCommunity.name
console.log(communitySearch)
} else {
@@ -125,7 +121,7 @@
: undefined
data.url = image || data.url || undefined
const post = await client().createPost({
community_id: data.community!,
community_id: data.community!.id,
name: data.title,
body: data.body,
url: data.url,
@@ -213,25 +209,14 @@
</h1>
</slot>
{#if !edit && data}
<div>
<div class="flex flex-row">
<span class="block my-1 font-bold text-sm">
Community <span class="text-red-500">*</span>
</span>
{#if data.community}
<Icon
src={Check}
mini
size="20"
class="text-green-600 ml-auto inline"
/>
{/if}
</div>
{#if !data.community}
<ObjectAutocomplete
bind:q={communitySearch}
bind:items={communities}
jwt={$profile?.jwt}
listing_type="All"
label="Community"
required
on:select={(e) => {
const c = e.detail
if (!c) {
@@ -239,11 +224,35 @@
return
}
data.community = c.id
communitySearch = `${c.name}@${new URL(c.actor_id).hostname}`
communitySearch = ''
data.community = c
}}
/>
</div>
{:else}
<div class="flex flex-col gap-1">
<span class="font-medium text-sm">Community</span>
<Button
class="w-full !bg-white dark:!bg-black h-[38px]"
on:click={() => (data.community = null)}
alignment="left"
size="sm"
>
<Avatar
url={data.community.icon}
alt={data.community.name}
width={24}
slot="prefix"
/>
<div class="flex flex-col gap-0">
<span class="text-xs">{data.community.name}</span>
<span class="text-[10px] leading-3">
{new URL(data.community.actor_id).hostname}
</span>
</div>
</Button>
</div>
{/if}
{/if}
<TextInput
required
+3 -6
View File
@@ -1,14 +1,11 @@
import type { Community } from 'lemmy-js-client'
import { writable } from 'svelte/store'
interface SessionStorage {
lastSeenCommunity: // prettier-ignore
{
id: number
name: string
} | undefined
lastSeenCommunity: Community | undefined
postDraft:
| {
community: number | null
community: Community | null
title: string
body: string
image: FileList | null
+4 -7
View File
@@ -28,13 +28,10 @@
onMount(() => {
if (browser)
setSessionStorage('lastSeenCommunity', {
id: data.community.community_view.community.id,
name: fullCommunityName(
data.community.community_view.community.name,
data.community.community_view.community.actor_id
),
})
setSessionStorage(
'lastSeenCommunity',
data.community.community_view.community
)
})
onDestroy(() => {
@@ -161,8 +161,6 @@
community={post.post_view.community}
user={post.post_view.creator}
bind:subscribed={post.community_view.subscribed}
upvotes={post.post_view.counts.upvotes}
downvotes={post.post_view.counts.downvotes}
deleted={post.post_view.post.deleted}
removed={post.post_view.post.removed}
locked={post.post_view.post.locked}