feat: use last community in community form

This commit is contained in:
Xyphyn committed 2023-08-08 15:21:25 -07:00
1 parent d22d9b09fd
commit 6c7073fcfc
6 files changed
+70 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
"version": "0.5.0",
"version": "0.5.1",
"private": true,
"scripts": {
"dev": "vite dev",
+19 -7
View File
@@ -19,6 +19,13 @@
*/
export let editingPost: Post | undefined = undefined
export let passedCommunity:
| {
id: number
name: string
}
| undefined = undefined
let data: {
community: number | null
title: string
@@ -65,14 +72,19 @@
data.title = editingPost.name
}
const list = await getClient().listCommunities({
auth: $profile?.jwt,
type_: 'Subscribed',
sort: 'Active',
limit: 40,
})
if (passedCommunity) {
data.community = passedCommunity.id
communitySearch = passedCommunity.name
} else {
const list = await getClient().listCommunities({
auth: $profile?.jwt,
type_: 'Subscribed',
sort: 'Active',
limit: 40,
})
communities = list.communities.map((c) => c.community)
communities = list.communities.map((c) => c.community)
}
})
async function submit() {
+25
View File
@@ -0,0 +1,25 @@
interface SessionStorage {
lastSeenCommunity: // prettier-ignore
{
id: number
name: string
} | undefined
postData: {}
}
export const setSessionStorage = (
key: keyof SessionStorage,
value: SessionStorage[typeof key]
) => {
if (value == undefined) {
sessionStorage.removeItem(key)
} else {
sessionStorage.setItem(key, JSON.stringify(value))
}
}
export const getSessionStorage = (
key: keyof SessionStorage
): SessionStorage[typeof key] => {
return JSON.parse(sessionStorage.getItem(key)!)
}
+3
View File
@@ -17,3 +17,6 @@ export const searchParam = (
invalidateAll: true,
})
}
export const fullCommunityName = (name: string, actorId: string) =>
`${name}@${new URL(actorId).hostname}`
+13 -1
View File
@@ -14,11 +14,23 @@
import Pageination from '$lib/components/ui/Pageination.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Sort from '$lib/components/lemmy/Sort.svelte'
import { searchParam } from '$lib/util.js'
import { fullCommunityName, searchParam } from '$lib/util.js'
import { onDestroy, onMount } from 'svelte'
import { setSessionStorage } from '$lib/session.js'
export let data
let sidebar: boolean = false
onMount(() => {
setSessionStorage('lastSeenCommunity', {
id: data.community.community.id,
name: fullCommunityName(
data.community.community.name,
data.community.community.actor_id
),
})
})
</script>
<svelte:head>
+9 -1
View File
@@ -4,12 +4,17 @@
import Card from '$lib/components/ui/Card.svelte'
import { profile } from '$lib/auth.js'
import { onMount } from 'svelte'
import { getSessionStorage } from '$lib/session.js'
onMount(() => {
if (!$profile?.jwt) {
goto('/login')
}
})
let community = getSessionStorage('lastSeenCommunity') as
| { id: number; name: string }
| undefined
</script>
<svelte:head>
@@ -17,5 +22,8 @@
</svelte:head>
<Card class="p-6 max-w-2xl mx-auto">
<PostForm on:submit={(e) => goto(`/post/${e.detail.post.id}`)} />
<PostForm
passedCommunity={community}
on:submit={(e) => goto(`/post/${e.detail.post.id}`)}
/>
</Card>