feat: Add post uploading
This commit is contained in:
1 parent
5f674d4691
commit
1842139af9
31 files changed
+517
-182
No files matched your search
@@ -17,7 +17,6 @@ export function handleError({ error, event }) {
|
|||||||
export async function handle({ event, resolve }) {
|
export async function handle({ event, resolve }) {
|
||||||
// annoying hack to fix lemmy's CORS
|
// annoying hack to fix lemmy's CORS
|
||||||
if (event.url.pathname.startsWith('/cors')) {
|
if (event.url.pathname.startsWith('/cors')) {
|
||||||
// cut off the 1st slash (empty), and remove the /cors
|
|
||||||
event.request.headers.delete('origin')
|
event.request.headers.delete('origin')
|
||||||
event.request.headers.delete('host')
|
event.request.headers.delete('host')
|
||||||
|
|
||||||
@@ -55,19 +54,11 @@ export async function handle({ event, resolve }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const json = await data.json()
|
const json = await data.json()
|
||||||
|
|
||||||
return new Response(JSON.stringify(json), {
|
return new Response(JSON.stringify(json), {
|
||||||
status: data.status,
|
status: data.status,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
console.log('Caught the thing')
|
|
||||||
|
|
||||||
return new Response(JSON.stringify({ message: 'i hate everything' }), {
|
|
||||||
status: 500,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
|
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||||
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
|
import type { CommunityView } from 'lemmy-js-client'
|
||||||
|
import {
|
||||||
|
Calendar,
|
||||||
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
Icon,
|
||||||
|
PencilSquare,
|
||||||
|
UserGroup,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
|
import SvelteMarkdown from 'svelte-markdown'
|
||||||
|
|
||||||
|
export let community_view: CommunityView
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<StickyCard>
|
||||||
|
<Avatar
|
||||||
|
width={48}
|
||||||
|
url={community_view.community.icon ??
|
||||||
|
`https://api.dicebear.com/6.x/initials/svg?seed=${community_view.community.name}`}
|
||||||
|
alt={community_view.community.name}
|
||||||
|
/>
|
||||||
|
<span class="flex flex-row items-center gap-1 text-sm">
|
||||||
|
<Icon src={Calendar} width={16} height={16} mini />
|
||||||
|
<RelativeDate date={new Date(community_view.community.published)} />
|
||||||
|
</span>
|
||||||
|
<div class="text-sm flex flex-row flex-wrap gap-3">
|
||||||
|
<span class="flex flex-row items-center gap-1">
|
||||||
|
<Icon src={UserGroup} width={16} height={16} mini />
|
||||||
|
<FormattedNumber number={community_view.counts.subscribers} />
|
||||||
|
</span>
|
||||||
|
<span class="flex flex-row items-center gap-1">
|
||||||
|
<Icon src={PencilSquare} width={16} height={16} mini />
|
||||||
|
<FormattedNumber number={community_view.counts.posts} />
|
||||||
|
</span>
|
||||||
|
<span class="flex flex-row items-center gap-1">
|
||||||
|
<Icon src={ChatBubbleOvalLeftEllipsis} width={16} height={16} mini />
|
||||||
|
<FormattedNumber number={community_view.counts.comments} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<h1 class="font-bold text-lg">
|
||||||
|
{community_view.community.name}
|
||||||
|
</h1>
|
||||||
|
<Markdown source={community_view.community.description} />
|
||||||
|
</StickyCard>
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
export let community: Community
|
export let community: Community
|
||||||
export let avatar: boolean = false
|
export let avatar: boolean = false
|
||||||
|
export let avatarSize: number = 24
|
||||||
|
|
||||||
function linkFromCommunity(community: Community) {
|
function linkFromCommunity(community: Community) {
|
||||||
const domain = new URL(community.actor_id).hostname
|
const domain = new URL(community.actor_id).hostname
|
||||||
@@ -19,8 +20,8 @@
|
|||||||
src={community.icon ??
|
src={community.icon ??
|
||||||
`https://api.dicebear.com/6.x/initials/svg?seed=${community.name}`}
|
`https://api.dicebear.com/6.x/initials/svg?seed=${community.name}`}
|
||||||
alt=""
|
alt=""
|
||||||
width={24}
|
width={avatarSize}
|
||||||
height={24}
|
height={avatarSize}
|
||||||
class="rounded-full aspect-square object-cover"
|
class="rounded-full aspect-square object-cover"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
export let loading = false
|
export let loading = false
|
||||||
export let large = false
|
export let large = false
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
|
export let submit = false
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
</script>
|
</script>
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
: 'px-3 py-1.5'} rounded-md {color} text-sm transition-all {disabled
|
: 'px-3 py-1.5'} rounded-md {color} text-sm transition-all {disabled
|
||||||
? 'opacity-50 pointer-events-none'
|
? 'opacity-50 pointer-events-none'
|
||||||
: ''}"
|
: ''}"
|
||||||
|
type={submit ? 'submit' : 'button'}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex flex-row items-center justify-center gap-2"
|
class="flex flex-row items-center justify-center gap-2"
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
|
export let accept = 'image/*,video/*'
|
||||||
|
export let multiple = false
|
||||||
|
export let files: FileList | null | undefined = null
|
||||||
|
export let image = false
|
||||||
|
|
||||||
|
let previewURL = ''
|
||||||
|
let dragover = false
|
||||||
|
|
||||||
|
$: if (files) {
|
||||||
|
previewURL = URL.createObjectURL(files[0])
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<label
|
||||||
|
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-lg border border-black border-dashed cursor-pointer min-h-36 transition-colors dark:border-white {dragover
|
||||||
|
? '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>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Color } from '$lib/ui/colors'
|
||||||
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
|
|
||||||
|
type T = $$Generic
|
||||||
|
|
||||||
|
export let options: T[]
|
||||||
|
export let optionNames: Map<any, string> = new Map()
|
||||||
|
export let selected: T
|
||||||
|
|
||||||
|
let open = false
|
||||||
|
|
||||||
|
optionNames.set(null, 'None')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Menu rtl={false} preventDefault>
|
||||||
|
<button
|
||||||
|
class="flex flex-row gap-2 items-center px-3 py-1.5 w-full text-sm
|
||||||
|
transition-all max-w-64 rounded-md bg-slate-100 border border-slate-200
|
||||||
|
dark:bg-zinc-800 dark:border-zinc-700"
|
||||||
|
slot="button"
|
||||||
|
type="button"
|
||||||
|
on:click|preventDefault
|
||||||
|
>
|
||||||
|
{optionNames.get(selected) || selected}
|
||||||
|
</button>
|
||||||
|
{#each options as option}
|
||||||
|
<MenuButton on:click={() => (selected = option)}>
|
||||||
|
{optionNames.get(option) || option}
|
||||||
|
</MenuButton>
|
||||||
|
{/each}
|
||||||
|
</Menu>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
|
||||||
|
export let label: string = ''
|
||||||
|
export let placeholder: string = ''
|
||||||
|
export let value: string = ''
|
||||||
|
export let maxlength: number = -1
|
||||||
|
export let rows: number = 3
|
||||||
|
|
||||||
|
let clazz = ''
|
||||||
|
export { clazz as class }
|
||||||
|
|
||||||
|
const dispatcher = createEventDispatcher()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<label class="flex flex-col items-center {clazz}">
|
||||||
|
{#if label != ''}
|
||||||
|
<span
|
||||||
|
class="font-bold text-sm text-left mb-1 cursor-pointer w-max self-start"
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
<textarea
|
||||||
|
bind:value
|
||||||
|
on:input={(e) => dispatcher('input', e)}
|
||||||
|
{placeholder}
|
||||||
|
{maxlength}
|
||||||
|
{rows}
|
||||||
|
class="w-full px-3 text-sm py-2.5 bg-transparent border border-black/20
|
||||||
|
dark:border-white/20 dark:focus:border-white focus:outline-none
|
||||||
|
focus:border-black transition-colors rounded-md {clazz}"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
export let placeholder: string = ''
|
export let placeholder: string = ''
|
||||||
export let value: string = ''
|
export let value: string = ''
|
||||||
export let maxlength: number = -1
|
export let maxlength: number = -1
|
||||||
|
export let required = false
|
||||||
|
|
||||||
function typeAction(node: Node) {
|
function typeAction(node: Node) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -24,6 +25,9 @@
|
|||||||
class="font-bold text-sm text-left mb-1 cursor-pointer w-max self-start"
|
class="font-bold text-sm text-left mb-1 cursor-pointer w-max self-start"
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
|
{#if required}
|
||||||
|
<span class="text-red-500">*</span>
|
||||||
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -1,76 +1,64 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {
|
import type { PostView } from 'lemmy-js-client'
|
||||||
CommentView,
|
|
||||||
GetPostResponse,
|
|
||||||
PostView,
|
|
||||||
Comment,
|
|
||||||
} from 'lemmy-js-client'
|
|
||||||
import {
|
import {
|
||||||
ArrowDown,
|
|
||||||
ArrowUp,
|
|
||||||
ChatBubbleLeft,
|
|
||||||
ChatBubbleOvalLeft,
|
ChatBubbleOvalLeft,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
EllipsisHorizontal,
|
||||||
ChevronDown,
|
|
||||||
ChevronUp,
|
|
||||||
Icon,
|
Icon,
|
||||||
|
Square2Stack,
|
||||||
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||||
import { isImage, isVideo } from '$lib/ui/image.js'
|
import { isImage, isVideo } from '$lib/ui/image.js'
|
||||||
import { authData, getClient } from '$lib/lemmy.js'
|
|
||||||
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import {
|
||||||
|
DEFAULT_INSTANCE_URL,
|
||||||
|
authData,
|
||||||
|
getClient,
|
||||||
|
user,
|
||||||
|
} from '$lib/lemmy.js'
|
||||||
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
|
import { Color } from '$lib/ui/colors.js'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
|
||||||
let postRes: PostView
|
let postRes: PostView
|
||||||
export { postRes as post }
|
export { postRes as post }
|
||||||
|
|
||||||
let vote = postRes.my_vote
|
let deleting = false
|
||||||
|
|
||||||
async function upvote() {
|
async function deletePost() {
|
||||||
if (!$authData) return
|
if (!$authData) return
|
||||||
|
|
||||||
const upvoted = postRes.my_vote == 1
|
deleting = true
|
||||||
|
|
||||||
await getClient()
|
await getClient().deletePost({
|
||||||
.likePost({
|
|
||||||
score: upvoted ? 0 : 1,
|
|
||||||
auth: $authData.token,
|
auth: $authData.token,
|
||||||
|
deleted: true,
|
||||||
post_id: postRes.post.id,
|
post_id: postRes.post.id,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function downvote() {
|
deleting = false
|
||||||
if (!$authData) return
|
|
||||||
|
|
||||||
const upvoted = postRes.my_vote == -1
|
|
||||||
|
|
||||||
await getClient()
|
|
||||||
.likePost({
|
|
||||||
score: upvoted ? 0 : -1,
|
|
||||||
auth: $authData.token,
|
|
||||||
post_id: postRes.post.id,
|
|
||||||
})
|
|
||||||
.catch((_) => undefined)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<Card class="bg-white flex flex-col overflow-hidden max-w-xl w-full relative">
|
||||||
class="bg-white dark:bg-zinc-900 border dark:border-zinc-800 border-slate-200
|
|
||||||
rounded-md flex flex-col overflow-hidden max-w-xl w-full"
|
|
||||||
>
|
|
||||||
<div class="flex flex-col gap-2 bg-white dark:bg-zinc-900 p-4 rounded-md">
|
<div class="flex flex-col gap-2 bg-white dark:bg-zinc-900 p-4 rounded-md">
|
||||||
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
<span class="flex flex-row gap-2 text-xs items-center">
|
||||||
<CommunityLink avatar community={postRes.community} />
|
<CommunityLink avatarSize={20} avatar community={postRes.community} />
|
||||||
<div class="ml-auto" />
|
<span class="opacity-60">
|
||||||
<UserLink user={postRes.creator} />
|
<UserLink user={postRes.creator} />
|
||||||
<span class="opacity-50">
|
</span>
|
||||||
|
<div class="ml-auto" />
|
||||||
|
<span class="opacity-50 capitalize">
|
||||||
<RelativeDate date={new Date(postRes.post.published)} />
|
<RelativeDate date={new Date(postRes.post.published)} />
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<a href="/post/{postRes.post.id}" class="font-bold text-lg">
|
<a href="/post/{postRes.post.id}" class="font-bold">
|
||||||
{postRes.post.name}
|
{postRes.post.name}
|
||||||
</a>
|
</a>
|
||||||
{#if postRes.post.url}
|
{#if postRes.post.url}
|
||||||
@@ -100,7 +88,10 @@
|
|||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
{#if postRes.post.body}
|
{#if postRes.post.body}
|
||||||
<p class="text-sm max-h-24 line-clamp-3">
|
<p
|
||||||
|
class="text-sm max-h-[74px] line-clamp-3 bg-slate-100 dark:bg-zinc-800 border
|
||||||
|
border-slate200 dark:border-zinc-700 rounded-md p-2 mt-2"
|
||||||
|
>
|
||||||
{postRes.post.body}
|
{postRes.post.body}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -113,10 +104,10 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
class="flex flex-row items-center gap-1 p-1.5 px-3 rounded-md
|
class="flex flex-row items-center gap-1 p-1 px-3 rounded-md
|
||||||
bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200
|
bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200
|
||||||
dark:hover:bg-zinc-700 transition-colors border border-slate-200
|
dark:hover:bg-zinc-700 transition-colors border border-slate-200
|
||||||
dark:border-zinc-800"
|
dark:border-zinc-700"
|
||||||
href="/post/{postRes.post.id}"
|
href="/post/{postRes.post.id}"
|
||||||
>
|
>
|
||||||
<Icon src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
<Icon src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
||||||
@@ -124,5 +115,29 @@
|
|||||||
<FormattedNumber number={postRes.counts.comments} />
|
<FormattedNumber number={postRes.counts.comments} />
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
<Menu top absolute class="bottom-0 right-0 m-5 z-40">
|
||||||
|
<Button slot="button">
|
||||||
|
<Icon src={EllipsisHorizontal} width={16} mini />
|
||||||
|
</Button>
|
||||||
|
<span class="mx-4 text-xs opacity-80 text-left my-2">Post Actions</span>
|
||||||
|
<MenuButton
|
||||||
|
on:click={() => {
|
||||||
|
navigator.clipboard.writeText(
|
||||||
|
`${$page.url.origin}/post/${
|
||||||
|
$authData?.instance ?? DEFAULT_INSTANCE_URL
|
||||||
|
}/${postRes.post.id}`
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon src={Square2Stack} width={16} mini />
|
||||||
|
Copy Link
|
||||||
|
</MenuButton>
|
||||||
|
{#if $user?.person_view.person.id == postRes.post.creator_id}
|
||||||
|
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
||||||
|
<Icon src={Trash} width={16} mini />
|
||||||
|
Delete
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Card>
|
||||||
@@ -37,9 +37,10 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<slot {upvote} {downvote} {vote} {score}>
|
||||||
<div
|
<div
|
||||||
class="flex flex-row items-center gap-1 rounded-md transition-colors
|
class="flex flex-row items-center gap-1 rounded-md transition-colors
|
||||||
cursor-pointer border border-slate-200 dark:border-zinc-800
|
cursor-pointer border border-slate-200 dark:border-zinc-700 px-1 py-[2px]
|
||||||
{// upvote
|
{// upvote
|
||||||
vote == 1
|
vote == 1
|
||||||
? 'bg-orange-600/20 text-orange-500'
|
? 'bg-orange-600/20 text-orange-500'
|
||||||
@@ -47,11 +48,11 @@
|
|||||||
vote == -1
|
vote == -1
|
||||||
? 'bg-blue-600/40 text-blue-400'
|
? 'bg-blue-600/40 text-blue-400'
|
||||||
: // no vote
|
: // no vote
|
||||||
'bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200 dark:hover:bg-zinc-700'}"
|
'bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200 dark:hover:bg-zinc-700'}"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
aria-label="Upvote"
|
aria-label="Upvote"
|
||||||
class="p-1 px-1.5"
|
class="p-0.5 px-1"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
vote = vote == 1 ? 0 : 1
|
vote = vote == 1 ? 0 : 1
|
||||||
upvote()
|
upvote()
|
||||||
@@ -64,7 +65,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
aria-label="Downvote"
|
aria-label="Downvote"
|
||||||
class="p-1 px-1.5"
|
class="p-0.5 px-1"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
vote = vote == -1 ? 0 : -1
|
vote = vote == -1 ? 0 : -1
|
||||||
downvote()
|
downvote()
|
||||||
@@ -73,3 +74,4 @@
|
|||||||
<Icon src={ChevronDown} mini width={20} height={20} />
|
<Icon src={ChevronDown} mini width={20} height={20} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</slot>
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
import CommentForm from './CommentForm.svelte'
|
import CommentForm from './CommentForm.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
|
||||||
export let node: CommentNodeI
|
export let node: CommentNodeI
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@
|
|||||||
|
|
||||||
<li
|
<li
|
||||||
class="py-3 {$page.url.hash == `#${node.comment_view.comment.id}`
|
class="py-3 {$page.url.hash == `#${node.comment_view.comment.id}`
|
||||||
? 'bg-slate-300 dark:bg-zinc-800'
|
? 'bg-slate-200 dark:bg-zinc-800'
|
||||||
: ''}"
|
: ''}"
|
||||||
id="#{node.comment_view.comment.id.toString()}"
|
id="#{node.comment_view.comment.id.toString()}"
|
||||||
>
|
>
|
||||||
@@ -105,7 +106,7 @@
|
|||||||
max-w-full"
|
max-w-full"
|
||||||
>
|
>
|
||||||
<div class="max-w-full break-words">
|
<div class="max-w-full break-words">
|
||||||
<SvelteMarkdown source={node.comment_view.comment.content} />
|
<Markdown source={node.comment_view.comment.content} />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row gap-2 items-center">
|
<div class="flex flex-row gap-2 items-center">
|
||||||
<div class="flex flex-row gap-2 items-center">
|
<div class="flex flex-row gap-2 items-center">
|
||||||
|
|||||||
@@ -35,7 +35,11 @@
|
|||||||
ToastType.success
|
ToastType.success
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
addToast('Error', 'Failed to comment.', ToastType.error)
|
addToast(
|
||||||
|
'Error',
|
||||||
|
'Failed to comment. (Sometimes this error appears even when successful.)',
|
||||||
|
ToastType.error
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import MarkdownLink from '$lib/components/markdown/MarkdownLink.svelte'
|
||||||
import SvelteMarkdown from 'svelte-markdown'
|
import SvelteMarkdown from 'svelte-markdown'
|
||||||
|
|
||||||
export let source: string
|
export let source: string | undefined
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SvelteMarkdown {source} />
|
<SvelteMarkdown
|
||||||
|
{source}
|
||||||
|
renderers={{
|
||||||
|
link: MarkdownLink,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let href: string
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a {href} class="text-sky-400 hover:underline"><slot /></a>
|
||||||
@@ -4,9 +4,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="bg-white border border-slate-200
|
class="bg-white shadow-lg border-slate-200
|
||||||
dark:border-zinc-800 dark:bg-zinc-900 break-words
|
dark:border-zinc-800 dark:bg-zinc-900 break-words
|
||||||
flex-col gap-4 p-4 rounded-md {clazz}"
|
flex-col p-1 rounded-md {clazz}"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import Logo from '$lib/components/ui/Logo.svelte'
|
import Logo from '$lib/components/ui/Logo.svelte'
|
||||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
@@ -15,8 +16,11 @@
|
|||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
ArrowRightOnRectangle,
|
ArrowRightOnRectangle,
|
||||||
Cog6Tooth,
|
Cog6Tooth,
|
||||||
|
GlobeAlt,
|
||||||
Icon,
|
Icon,
|
||||||
Inbox,
|
Inbox,
|
||||||
|
PencilSquare,
|
||||||
|
Plus,
|
||||||
UserCircle,
|
UserCircle,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
</script>
|
</script>
|
||||||
@@ -28,7 +32,7 @@
|
|||||||
<div class="flex flex-row gap-2 items-center mr-auto">
|
<div class="flex flex-row gap-2 items-center mr-auto">
|
||||||
<a href="/" class="flex flex-row items-center gap-2">
|
<a href="/" class="flex flex-row items-center gap-2">
|
||||||
<Logo width={40} />
|
<Logo width={40} />
|
||||||
<div class="flex flex-col">
|
<div class="sm:flex flex-col hidden">
|
||||||
<span class="font-bold">Xylemmy</span>
|
<span class="font-bold">Xylemmy</span>
|
||||||
<span
|
<span
|
||||||
class="text-xs opacity-50
|
class="text-xs opacity-50
|
||||||
@@ -43,10 +47,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<Link href="/communities">Communities</Link>
|
<div class="flex flex-row gap-2">
|
||||||
|
<Link href="/communities">
|
||||||
|
<Icon src={GlobeAlt} width={16} />
|
||||||
|
<span class="hidden sm:inline ml-1">Communities</span>
|
||||||
|
</Link>
|
||||||
|
<Menu>
|
||||||
|
<Button color={Color.accent} slot="button">
|
||||||
|
<Icon src={Plus} width={16} />
|
||||||
|
<span class="hidden sm:inline">Create</span>
|
||||||
|
</Button>
|
||||||
|
<span class="text-xs opacity-80 text-left mx-4 my-2">Create</span>
|
||||||
|
<MenuButton link href="/create/post">
|
||||||
|
<Icon src={PencilSquare} mini width={16} />
|
||||||
|
Post
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
<Menu>
|
<Menu>
|
||||||
<button
|
<button
|
||||||
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100 dark:bg-zinc-800"
|
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100
|
||||||
|
dark:bg-zinc-800"
|
||||||
aria-label="Profile"
|
aria-label="Profile"
|
||||||
slot="button"
|
slot="button"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div
|
<div
|
||||||
class="sticky top-4 bg-white border border-slate-200
|
class="sticky top-4 bg-white shadow-lg border-slate-200
|
||||||
dark:border-zinc-800 dark:bg-zinc-900 break-words hidden lg:flex
|
dark:border-zinc-800 dark:bg-zinc-900 break-words hidden lg:flex
|
||||||
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-2rem)] overflow-auto"
|
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-2rem)] overflow-auto"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
export let top = false
|
export let top = false
|
||||||
|
|
||||||
let element: any
|
let element: any
|
||||||
|
|
||||||
|
export let preventDefault = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:body
|
<svelte:body
|
||||||
@@ -31,7 +33,11 @@
|
|||||||
class="overflow-visible z-30 {absolute
|
class="overflow-visible z-30 {absolute
|
||||||
? 'absolute'
|
? 'absolute'
|
||||||
: 'relative'} cursor-auto {clazz}"
|
: 'relative'} cursor-auto {clazz}"
|
||||||
on:click={() => (open = !open)}
|
on:click={(e) => {
|
||||||
|
if (preventDefault) e.preventDefault()
|
||||||
|
|
||||||
|
open = !open
|
||||||
|
}}
|
||||||
bind:this={element}
|
bind:this={element}
|
||||||
>
|
>
|
||||||
<slot name="button" />
|
<slot name="button" />
|
||||||
@@ -42,7 +48,7 @@
|
|||||||
start: 0.95,
|
start: 0.95,
|
||||||
easing: expoOut,
|
easing: expoOut,
|
||||||
}}
|
}}
|
||||||
class="absolute {rtl
|
class="absolute max-h-64 overflow-auto {rtl
|
||||||
? 'origin-top-right right-0'
|
? 'origin-top-right right-0'
|
||||||
: 'origin-top-left left-0'}
|
: 'origin-top-left left-0'}
|
||||||
{top ? 'bottom-[100%] origin-bottom-left' : 'top-[100%]'}
|
{top ? 'bottom-[100%] origin-bottom-left' : 'top-[100%]'}
|
||||||
|
|||||||
+9
-1
@@ -9,6 +9,14 @@ import { PUBLIC_PROXY_URL } from '$env/static/public'
|
|||||||
export const DEFAULT_INSTANCE_URL = 'lemm.ee'
|
export const DEFAULT_INSTANCE_URL = 'lemm.ee'
|
||||||
export let instance_url = writable(DEFAULT_INSTANCE_URL)
|
export let instance_url = writable(DEFAULT_INSTANCE_URL)
|
||||||
|
|
||||||
|
export function buildBaseUrl(instance?: string) {
|
||||||
|
if (!instance) {
|
||||||
|
instance = get(authData)?.instance ?? DEFAULT_INSTANCE_URL
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${PUBLIC_PROXY_URL}/cors/${instance}`
|
||||||
|
}
|
||||||
|
|
||||||
export function getClient(instance?: string): LemmyHttp {
|
export function getClient(instance?: string): LemmyHttp {
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
instance = get(authData)?.instance ?? DEFAULT_INSTANCE_URL
|
instance = get(authData)?.instance ?? DEFAULT_INSTANCE_URL
|
||||||
@@ -31,7 +39,7 @@ if (typeof localStorage != 'undefined') {
|
|||||||
try {
|
try {
|
||||||
authData.set(JSON.parse(localStorage.getItem('user') ?? ''))
|
authData.set(JSON.parse(localStorage.getItem('user') ?? ''))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
localStorage.removeItem('user')
|
// keep authdata until we can verify that the user is infact invalid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-7
@@ -23,6 +23,10 @@
|
|||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Xylemmy</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-row gap-4">
|
<div class="flex flex-row gap-4">
|
||||||
<div class="flex flex-col gap-4 max-w-full">
|
<div class="flex flex-col gap-4 max-w-full">
|
||||||
<div class="flex flex-col sm:flex-row gap-4 max-w-full">
|
<div class="flex flex-col sm:flex-row gap-4 max-w-full">
|
||||||
@@ -60,18 +64,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Link
|
<Button
|
||||||
href={(function () {
|
on:click={() => {
|
||||||
$page.url.searchParams.set(
|
$page.url.searchParams.set(
|
||||||
'page',
|
'page',
|
||||||
((Number($page.url.searchParams.get('page')) || 1) + 1).toString()
|
((Number($page.url.searchParams.get('page')) || 1) + 1).toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
return $page.url.toString()
|
goto($page.url.toString(), {
|
||||||
})()}
|
invalidateAll: true,
|
||||||
|
})
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Next
|
Next
|
||||||
</Link>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-auto hidden lg:block max-w-sm w-full">
|
<div class="ml-auto hidden lg:block max-w-sm w-full">
|
||||||
@@ -104,12 +110,14 @@
|
|||||||
</Card>
|
</Card>
|
||||||
{:then site}
|
{:then site}
|
||||||
<Card>
|
<Card>
|
||||||
|
{#if site.site_view.site.icon}
|
||||||
<Avatar
|
<Avatar
|
||||||
width={64}
|
width={64}
|
||||||
url={site.site_view.site.icon ?? ''}
|
url={site.site_view.site.icon}
|
||||||
alt={site.site_view.site.name}
|
alt={site.site_view.site.name}
|
||||||
/>
|
/>
|
||||||
<span class="flex flex-row items-center gap-1 text-sm">
|
{/if}
|
||||||
|
<span class="flex flex-row items-center gap-1 text-sm capitalize">
|
||||||
<Icon src={Calendar} width={16} height={16} mini />
|
<Icon src={Calendar} width={16} height={16} mini />
|
||||||
<RelativeDate date={new Date(site.site_view.site.published)} />
|
<RelativeDate date={new Date(site.site_view.site.published)} />
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import Card from '$lib/components/ui/StickyCard.svelte'
|
import Card from '$lib/components/ui/StickyCard.svelte'
|
||||||
|
import CommunityCard from '$lib/components/community/CommunityCard.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
@@ -56,8 +57,8 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Card>
|
|
||||||
{#await data.streamed.community}
|
{#await data.streamed.community}
|
||||||
|
<Card>
|
||||||
<div
|
<div
|
||||||
class="w-[64px] h-[64px] rounded-full bg-slate-200
|
class="w-[64px] h-[64px] rounded-full bg-slate-200
|
||||||
dark:bg-zinc-700 animate-pulse"
|
dark:bg-zinc-700 animate-pulse"
|
||||||
@@ -82,41 +83,12 @@
|
|||||||
class="w-24 h-4 bg-slate-200 dark:bg-zinc-700 animate-pulse
|
class="w-24 h-4 bg-slate-200 dark:bg-zinc-700 animate-pulse
|
||||||
rounded-md"
|
rounded-md"
|
||||||
/>
|
/>
|
||||||
{:then community}
|
|
||||||
<Avatar
|
|
||||||
width={48}
|
|
||||||
url={community.community_view.community.icon ??
|
|
||||||
`https://api.dicebear.com/6.x/initials/svg?seed=${community.community_view.community.name}`}
|
|
||||||
alt={community.community_view.community.name}
|
|
||||||
/>
|
|
||||||
<span class="flex flex-row items-center gap-1 text-sm">
|
|
||||||
<Icon src={Calendar} width={16} height={16} mini />
|
|
||||||
<RelativeDate
|
|
||||||
date={new Date(community.community_view.community.published)}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
<div class="text-sm flex flex-row flex-wrap gap-3">
|
|
||||||
<span class="flex flex-row items-center gap-1">
|
|
||||||
<Icon src={UserGroup} width={16} height={16} mini />
|
|
||||||
<FormattedNumber
|
|
||||||
number={community.community_view.counts.subscribers}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
<span class="flex flex-row items-center gap-1">
|
|
||||||
<Icon src={PencilSquare} width={16} height={16} mini />
|
|
||||||
<FormattedNumber number={community.community_view.counts.posts} />
|
|
||||||
</span>
|
|
||||||
<span class="flex flex-row items-center gap-1">
|
|
||||||
<Icon src={ChatBubbleOvalLeftEllipsis} width={16} height={16} mini />
|
|
||||||
<FormattedNumber number={community.community_view.counts.comments} />
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<h1 class="font-bold text-lg">
|
|
||||||
{community.community_view.community.name}
|
|
||||||
</h1>
|
|
||||||
<SvelteMarkdown source={community.community_view.community.description} />
|
|
||||||
{:catch}
|
|
||||||
<p>Failed to load community. This is likely an issue on Lemmy's end.</p>
|
|
||||||
{/await}
|
|
||||||
</Card>
|
</Card>
|
||||||
|
{:then community}
|
||||||
|
<CommunityCard community_view={community.community_view} />
|
||||||
|
{:catch}
|
||||||
|
<Card>
|
||||||
|
<p>Failed to load community. This is likely an issue on Lemmy's end.</p>
|
||||||
|
</Card>
|
||||||
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
@@ -2,14 +2,14 @@ import { authData, getClient } from '$lib/lemmy.js'
|
|||||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export function load(req: any) {
|
export async function load(req: any) {
|
||||||
const page = Number(req.url.searchParams.get('page') || 1) || 1
|
const page = Number(req.url.searchParams.get('page') || 1) || 1
|
||||||
|
|
||||||
const sort: SortType =
|
const sort: SortType =
|
||||||
(req.url.searchParams.get('sort') as SortType) || 'Active'
|
(req.url.searchParams.get('sort') as SortType) || 'Active'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts: getClient(req.params).getPosts({
|
posts: getClient().getPosts({
|
||||||
limit: 40,
|
limit: 40,
|
||||||
community_name: req.params.name,
|
community_name: req.params.name,
|
||||||
page: page,
|
page: page,
|
||||||
|
|||||||
@@ -35,20 +35,18 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div class="flex flex-col sm:flex-row gap-2 sm:ml-auto">
|
<div class="flex flex-col sm:flex-row gap-2 sm:ml-auto">
|
||||||
<TextInput
|
<TextInput class="rounded-md" bind:value={search} />
|
||||||
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
|
<Button
|
||||||
dark:bg-zinc-900 rounded-md"
|
on:click={() => {
|
||||||
bind:value={search}
|
|
||||||
/>
|
|
||||||
<Link
|
|
||||||
href={(function () {
|
|
||||||
$page.url.searchParams.set('q', search)
|
$page.url.searchParams.set('q', search)
|
||||||
return $page.url.toString()
|
goto($page.url.toString(), {
|
||||||
})()}
|
invalidateAll: true,
|
||||||
|
})
|
||||||
|
}}
|
||||||
color={Color.ghost}
|
color={Color.ghost}
|
||||||
>
|
>
|
||||||
Search
|
Search
|
||||||
</Link>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul class="flex flex-col">
|
<ul class="flex flex-col">
|
||||||
@@ -92,11 +90,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if !community.community.local}
|
{#if !community.community.local}
|
||||||
<span class="opacity-80">
|
<span class="opacity-80 mb-2">
|
||||||
{new URL(community.community.actor_id).hostname}
|
{new URL(community.community.actor_id).hostname}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex flex-row gap-3 items-center mt-2">
|
<div class="flex flex-row gap-3 items-center">
|
||||||
<div class="flex flex-row gap-1 items-center">
|
<div class="flex flex-row gap-1 items-center">
|
||||||
<Icon src={UserGroup} width={16} mini />
|
<Icon src={UserGroup} width={16} mini />
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { getClient } from '$lib/lemmy.js'
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
import type { ListingType } from 'lemmy-js-client'
|
import type { ListingType } from 'lemmy-js-client'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export function load({ url }) {
|
export function load({ url }) {
|
||||||
const type = url.searchParams.get('listingType') as ListingType
|
const type = url.searchParams.get('listingType') as ListingType
|
||||||
@@ -10,17 +11,19 @@ export function load({ url }) {
|
|||||||
return getClient().search({
|
return getClient().search({
|
||||||
limit: 40,
|
limit: 40,
|
||||||
page: page,
|
page: page,
|
||||||
sort: 'Active',
|
sort: 'TopAll',
|
||||||
type_: 'Communities',
|
type_: 'Communities',
|
||||||
listing_type: type,
|
listing_type: type,
|
||||||
q: query,
|
q: query,
|
||||||
|
auth: get(authData)?.token,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return getClient().listCommunities({
|
return getClient().listCommunities({
|
||||||
limit: 40,
|
limit: 40,
|
||||||
page: page,
|
page: page,
|
||||||
sort: 'Active',
|
sort: 'TopAll',
|
||||||
type_: type,
|
type_: type,
|
||||||
|
auth: get(authData)?.token,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||||
|
import SelectMenu from '$lib/components/input/SelectMenu.svelte'
|
||||||
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import Loading from '$lib/components/ui/Loading.svelte'
|
||||||
|
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import { authData, buildBaseUrl, getClient } from '$lib/lemmy.js'
|
||||||
|
import { Color } from '$lib/ui/colors.js'
|
||||||
|
import type { Community } from 'lemmy-js-client'
|
||||||
|
import { list } from 'postcss'
|
||||||
|
import { onMount } from 'svelte'
|
||||||
|
|
||||||
|
let data: {
|
||||||
|
community: number | null
|
||||||
|
title: string
|
||||||
|
body: string
|
||||||
|
image: FileList | null
|
||||||
|
loading: boolean
|
||||||
|
} = {
|
||||||
|
community: null,
|
||||||
|
title: '',
|
||||||
|
body: '',
|
||||||
|
image: null,
|
||||||
|
loading: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadImage(
|
||||||
|
image: FileList | null | undefined
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (!image || !$authData) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await getClient().uploadImage({
|
||||||
|
image: image[0],
|
||||||
|
auth: $authData.token,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.url) {
|
||||||
|
throw new Error('Failed to upload image')
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.url
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error('Failed to upload image.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!data.community || !data.title || !$authData) return
|
||||||
|
|
||||||
|
data.loading = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
let image = data.image ? await uploadImage(data.image) : undefined
|
||||||
|
|
||||||
|
const post = await getClient().createPost({
|
||||||
|
auth: $authData.token,
|
||||||
|
community_id: data.community,
|
||||||
|
name: data.title,
|
||||||
|
body: data.body,
|
||||||
|
url: image,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!post) throw new Error('Failed to upload post')
|
||||||
|
|
||||||
|
console.log(`Uploading post ${post?.post_view.post.id}`)
|
||||||
|
|
||||||
|
goto(`/post/${post?.post_view.post.id}`)
|
||||||
|
} catch (err) {
|
||||||
|
addToast('Error', err as any, ToastType.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
data.loading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const placeholders = [
|
||||||
|
'Is starting nuclear warfare illegal?',
|
||||||
|
'A cool photo I took before the destruction of mankind!',
|
||||||
|
'AITA for ending all contention and causing world peace?',
|
||||||
|
'BREAKING NEWS: Police break into gun shop, find weapons',
|
||||||
|
]
|
||||||
|
|
||||||
|
const placeholder =
|
||||||
|
placeholders[Math.floor(Math.random() * placeholders.length)]
|
||||||
|
|
||||||
|
const placeholder2 =
|
||||||
|
placeholders[Math.floor(Math.random() * placeholders.length)]
|
||||||
|
|
||||||
|
let communities: Community[] | undefined
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
if (!$authData) {
|
||||||
|
goto('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = await getClient().listCommunities({
|
||||||
|
auth: $authData.token,
|
||||||
|
type_: 'Subscribed',
|
||||||
|
sort: 'New',
|
||||||
|
limit: 40,
|
||||||
|
})
|
||||||
|
|
||||||
|
communities = list.communities.map((c) => c.community)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Create post</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<Card class="p-6 max-w-xl mx-auto">
|
||||||
|
<form on:submit|preventDefault={submit} class="flex flex-col gap-4">
|
||||||
|
<h1 class="font-bold text-xl">Create Post</h1>
|
||||||
|
<div>
|
||||||
|
<span class="block my-1 font-bold text-sm">
|
||||||
|
Community <span class="text-red-500">*</span>
|
||||||
|
</span>
|
||||||
|
{#if communities}
|
||||||
|
<SelectMenu
|
||||||
|
bind:selected={data.community}
|
||||||
|
options={communities.map((c) => c.id)}
|
||||||
|
optionNames={new Map(communities.map((c) => [c.id, c.title]))}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<Loading />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<TextInput required label="Title" bind:value={data.title} {placeholder} />
|
||||||
|
<TextArea label="Body" bind:value={data.body} placeholder={placeholder2} />
|
||||||
|
<div>
|
||||||
|
<span class="block my-1 font-bold text-sm">Image</span>
|
||||||
|
<FileInput
|
||||||
|
accept="image/jpeg,image/png,image/webp"
|
||||||
|
image
|
||||||
|
bind:files={data.image}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
submit
|
||||||
|
color={Color.accent}
|
||||||
|
large
|
||||||
|
loading={data.loading}
|
||||||
|
disabled={data.loading}
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Card>
|
||||||
@@ -4,6 +4,10 @@
|
|||||||
export let data
|
export let data
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Inbox</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<h1 class="font-bold text-3xl">Inbox</h1>
|
<h1 class="font-bold text-3xl">Inbox</h1>
|
||||||
<div class="flex flex-col gap-4 list-none my-4">
|
<div class="flex flex-col gap-4 list-none my-4">
|
||||||
{#if !data.data || (data.data?.length ?? 0) == 0}
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
|
||||||
|
|
||||||
let url = ''
|
|
||||||
|
|
||||||
async function changeInstance() {
|
|
||||||
try {
|
|
||||||
new URL(`https://${url}`)
|
|
||||||
} catch (error) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await fetch('/instance_url', {
|
|
||||||
method: 'POST',
|
|
||||||
body: url,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<form
|
|
||||||
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
|
|
||||||
dark:bg-zinc-900 p-8 flex flex-col gap-4 rounded-md"
|
|
||||||
>
|
|
||||||
<h1 class="font-bold text-lg">Change instance</h1>
|
|
||||||
<p class="text-xs">(Must be exact URL )</p>
|
|
||||||
<input bind:value={url} type="text" />
|
|
||||||
<Button on:click={changeInstance}>change</Button>
|
|
||||||
</form>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { getClient } from '$lib/lemmy.js'
|
|
||||||
import { error } from '@sveltejs/kit'
|
|
||||||
|
|
||||||
export async function POST(event) {
|
|
||||||
try {
|
|
||||||
const text = await event.request.text()
|
|
||||||
const instance = new URL(`https://${text}`)
|
|
||||||
|
|
||||||
event.cookies.set('instance_url', instance.hostname)
|
|
||||||
|
|
||||||
return new Response(instance.hostname)
|
|
||||||
} catch (err) {
|
|
||||||
throw error(400, 'Invalid URL')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -57,6 +57,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>Login</svelte:head>
|
||||||
|
|
||||||
<Card class="mx-auto p-6">
|
<Card class="mx-auto p-6">
|
||||||
<form on:submit|preventDefault={logIn} class="flex flex-col gap-4">
|
<form on:submit|preventDefault={logIn} class="flex flex-col gap-4">
|
||||||
<h1 class="font-bold text-lg">Log in</h1>
|
<h1 class="font-bold text-lg">Log in</h1>
|
||||||
@@ -76,6 +78,7 @@
|
|||||||
disabled={data.loading}
|
disabled={data.loading}
|
||||||
large
|
large
|
||||||
color={Color.accent}
|
color={Color.accent}
|
||||||
|
submit
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -85,7 +86,10 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
<title>{data.post.post_view.post.name}</title>
|
<title>{data.post.post_view.post.name}</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
||||||
<CommunityLink avatar community={postData.community} />
|
<CommunityLink avatar community={postData.community} />
|
||||||
@@ -118,7 +122,7 @@
|
|||||||
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
|
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
|
||||||
dark:bg-zinc-900 p-2 text-sm rounded-md leading-5"
|
dark:bg-zinc-900 p-2 text-sm rounded-md leading-5"
|
||||||
>
|
>
|
||||||
<SvelteMarkdown source={post.body} />
|
<Markdown source={post.body} />
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="w-max">
|
<div class="w-max">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||||
@@ -21,6 +22,10 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
{data.user.person_view.person.name}
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-row gap-4 max-w-full">
|
<div class="flex flex-row gap-4 max-w-full">
|
||||||
<div class="flex flex-col gap-4 max-w-full">
|
<div class="flex flex-col gap-4 max-w-full">
|
||||||
{#each data.user.comments as item}
|
{#each data.user.comments as item}
|
||||||
@@ -79,7 +84,7 @@
|
|||||||
{data.user.person_view.person.name}
|
{data.user.person_view.person.name}
|
||||||
</h1>
|
</h1>
|
||||||
{#if data.user.person_view.person.bio}
|
{#if data.user.person_view.person.bio}
|
||||||
<SvelteMarkdown source={data.user.person_view.person.bio} />
|
<Markdown source={data.user.person_view.person.bio} />
|
||||||
{/if}
|
{/if}
|
||||||
</StickyCard>
|
</StickyCard>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user