diff --git a/package.json b/package.json index 2ed184ad..d15a8bd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "0.7.8", + "version": "0.8.0", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/lib/components/input/FileInput.svelte b/src/lib/components/input/FileInput.svelte index 613c25e3..3bc9fcdf 100644 --- a/src/lib/components/input/FileInput.svelte +++ b/src/lib/components/input/FileInput.svelte @@ -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 @@ } - + diff --git a/src/lib/components/lemmy/community/CommunityCard.svelte b/src/lib/components/lemmy/community/CommunityCard.svelte index d5cb1477..20ee40ea 100644 --- a/src/lib/components/lemmy/community/CommunityCard.svelte +++ b/src/lib/components/lemmy/community/CommunityCard.svelte @@ -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 } diff --git a/src/lib/components/markdown/MarkdownEditor.svelte b/src/lib/components/markdown/MarkdownEditor.svelte index 8702c327..ebe21b22 100644 --- a/src/lib/components/markdown/MarkdownEditor.svelte +++ b/src/lib/components/markdown/MarkdownEditor.svelte @@ -116,7 +116,7 @@
{label}
{/if}
{#if previewing} diff --git a/src/lib/components/ui/Navbar.svelte b/src/lib/components/ui/Navbar.svelte index ab21efcd..f22db2d5 100644 --- a/src/lib/components/ui/Navbar.svelte +++ b/src/lib/components/ui/Navbar.svelte @@ -28,6 +28,7 @@ InformationCircle, MagnifyingGlass, Moon, + Newspaper, PencilSquare, Plus, Sun, @@ -153,6 +154,14 @@ Post + + + Community + {#if !$profile?.jwt} Log in to create content. diff --git a/src/lib/lemmy/user.ts b/src/lib/lemmy/user.ts index e1350cf5..fea26b47 100644 --- a/src/lib/lemmy/user.ts +++ b/src/lib/lemmy/user.ts @@ -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) + } +} diff --git a/src/routes/communities/+page.svelte b/src/routes/communities/+page.svelte index b8fca01f..966885e8 100644 --- a/src/routes/communities/+page.svelte +++ b/src/routes/communities/+page.svelte @@ -15,6 +15,7 @@ import Button from '$lib/components/input/Button.svelte' import Pageination from '$lib/components/ui/Pageination.svelte' import { searchParam } from '$lib/util.js' + import { addSubscription } from '$lib/lemmy/user.js' export let data @@ -96,6 +97,11 @@ res.community_view.subscribed != 'NotSubscribed' ? 'Subscribed' : 'NotSubscribed' + + addSubscription( + community.community, + res.community_view.subscribed == 'Subscribed' + ) } }} color={community.subscribed == 'Subscribed' diff --git a/src/routes/create/community/+page.svelte b/src/routes/create/community/+page.svelte new file mode 100644 index 00000000..32c9bffd --- /dev/null +++ b/src/routes/create/community/+page.svelte @@ -0,0 +1,125 @@ + + +
+

Create Community

+ { + formData.name = formData.name.toLowerCase().replaceAll(' ', '_') + }} + /> + + + + + + NSFW + + Only moderators can post + + +