feat: use last community in community form
This commit is contained in:
1 parent
d22d9b09fd
commit
6c7073fcfc
6 files changed
+70
-10
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -19,6 +19,13 @@
|
|||||||
*/
|
*/
|
||||||
export let editingPost: Post | undefined = undefined
|
export let editingPost: Post | undefined = undefined
|
||||||
|
|
||||||
|
export let passedCommunity:
|
||||||
|
| {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
| undefined = undefined
|
||||||
|
|
||||||
let data: {
|
let data: {
|
||||||
community: number | null
|
community: number | null
|
||||||
title: string
|
title: string
|
||||||
@@ -65,14 +72,19 @@
|
|||||||
data.title = editingPost.name
|
data.title = editingPost.name
|
||||||
}
|
}
|
||||||
|
|
||||||
const list = await getClient().listCommunities({
|
if (passedCommunity) {
|
||||||
auth: $profile?.jwt,
|
data.community = passedCommunity.id
|
||||||
type_: 'Subscribed',
|
communitySearch = passedCommunity.name
|
||||||
sort: 'Active',
|
} else {
|
||||||
limit: 40,
|
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() {
|
async function submit() {
|
||||||
|
|||||||
@@ -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)!)
|
||||||
|
}
|
||||||
@@ -17,3 +17,6 @@ export const searchParam = (
|
|||||||
invalidateAll: true,
|
invalidateAll: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fullCommunityName = (name: string, actorId: string) =>
|
||||||
|
`${name}@${new URL(actorId).hostname}`
|
||||||
@@ -14,11 +14,23 @@
|
|||||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import Sort from '$lib/components/lemmy/Sort.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
|
export let data
|
||||||
|
|
||||||
let sidebar: boolean = false
|
let sidebar: boolean = false
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
setSessionStorage('lastSeenCommunity', {
|
||||||
|
id: data.community.community.id,
|
||||||
|
name: fullCommunityName(
|
||||||
|
data.community.community.name,
|
||||||
|
data.community.community.actor_id
|
||||||
|
),
|
||||||
|
})
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
|
|||||||
@@ -4,12 +4,17 @@
|
|||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import { getSessionStorage } from '$lib/session.js'
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!$profile?.jwt) {
|
if (!$profile?.jwt) {
|
||||||
goto('/login')
|
goto('/login')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let community = getSessionStorage('lastSeenCommunity') as
|
||||||
|
| { id: number; name: string }
|
||||||
|
| undefined
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -17,5 +22,8 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Card class="p-6 max-w-2xl mx-auto">
|
<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>
|
</Card>
|
||||||
Reference in new issue
Block a user