feat: Add post uploading
This commit is contained in:
1 parent
5f674d4691
commit
1842139af9
31 files changed
+560
-225
No files matched your search
+4
-13
@@ -17,7 +17,6 @@ export function handleError({ error, event }) {
|
||||
export async function handle({ event, resolve }) {
|
||||
// annoying hack to fix lemmy's 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('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), {
|
||||
status: data.status,
|
||||
})
|
||||
} catch (error) {
|
||||
console.log('Caught the thing')
|
||||
|
||||
return new Response(JSON.stringify({ message: 'i hate everything' }), {
|
||||
status: 500,
|
||||
})
|
||||
}
|
||||
return new Response(JSON.stringify(json), {
|
||||
status: data.status,
|
||||
})
|
||||
} catch (error) {
|
||||
return new Response(
|
||||
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 avatar: boolean = false
|
||||
export let avatarSize: number = 24
|
||||
|
||||
function linkFromCommunity(community: Community) {
|
||||
const domain = new URL(community.actor_id).hostname
|
||||
@@ -19,8 +20,8 @@
|
||||
src={community.icon ??
|
||||
`https://api.dicebear.com/6.x/initials/svg?seed=${community.name}`}
|
||||
alt=""
|
||||
width={24}
|
||||
height={24}
|
||||
width={avatarSize}
|
||||
height={avatarSize}
|
||||
class="rounded-full aspect-square object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
export let loading = false
|
||||
export let large = false
|
||||
export let disabled = false
|
||||
export let submit = false
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
</script>
|
||||
@@ -19,6 +20,7 @@
|
||||
: 'px-3 py-1.5'} rounded-md {color} text-sm transition-all {disabled
|
||||
? 'opacity-50 pointer-events-none'
|
||||
: ''}"
|
||||
type={submit ? 'submit' : 'button'}
|
||||
>
|
||||
<div
|
||||
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 value: string = ''
|
||||
export let maxlength: number = -1
|
||||
export let required = false
|
||||
|
||||
function typeAction(node: Node) {
|
||||
// @ts-ignore
|
||||
@@ -24,6 +25,9 @@
|
||||
class="font-bold text-sm text-left mb-1 cursor-pointer w-max self-start"
|
||||
>
|
||||
{label}
|
||||
{#if required}
|
||||
<span class="text-red-500">*</span>
|
||||
{/if}
|
||||
</span>
|
||||
{/if}
|
||||
<input
|
||||
|
||||
@@ -1,76 +1,64 @@
|
||||
<script lang="ts">
|
||||
import type {
|
||||
CommentView,
|
||||
GetPostResponse,
|
||||
PostView,
|
||||
Comment,
|
||||
} from 'lemmy-js-client'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowUp,
|
||||
ChatBubbleLeft,
|
||||
ChatBubbleOvalLeft,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
EllipsisHorizontal,
|
||||
Icon,
|
||||
Square2Stack,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||
import { isImage, isVideo } from '$lib/ui/image.js'
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import PostVote from '$lib/components/lemmy/PostVote.svelte'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.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
|
||||
export { postRes as post }
|
||||
|
||||
let vote = postRes.my_vote
|
||||
let deleting = false
|
||||
|
||||
async function upvote() {
|
||||
async function deletePost() {
|
||||
if (!$authData) return
|
||||
|
||||
const upvoted = postRes.my_vote == 1
|
||||
deleting = true
|
||||
|
||||
await getClient()
|
||||
.likePost({
|
||||
score: upvoted ? 0 : 1,
|
||||
auth: $authData.token,
|
||||
post_id: postRes.post.id,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
await getClient().deletePost({
|
||||
auth: $authData.token,
|
||||
deleted: true,
|
||||
post_id: postRes.post.id,
|
||||
})
|
||||
|
||||
async function downvote() {
|
||||
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)
|
||||
deleting = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
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"
|
||||
>
|
||||
<Card class="bg-white flex flex-col overflow-hidden max-w-xl w-full relative">
|
||||
<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">
|
||||
<CommunityLink avatar community={postRes.community} />
|
||||
<span class="flex flex-row gap-2 text-xs items-center">
|
||||
<CommunityLink avatarSize={20} avatar community={postRes.community} />
|
||||
<span class="opacity-60">
|
||||
<UserLink user={postRes.creator} />
|
||||
</span>
|
||||
<div class="ml-auto" />
|
||||
<UserLink user={postRes.creator} />
|
||||
<span class="opacity-50">
|
||||
<span class="opacity-50 capitalize">
|
||||
<RelativeDate date={new Date(postRes.post.published)} />
|
||||
</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}
|
||||
</a>
|
||||
{#if postRes.post.url}
|
||||
@@ -100,7 +88,10 @@
|
||||
</a>
|
||||
{/if}
|
||||
{#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}
|
||||
</p>
|
||||
{/if}
|
||||
@@ -113,10 +104,10 @@
|
||||
/>
|
||||
|
||||
<a
|
||||
class="flex flex-row items-center gap-1 p-1.5 px-3 rounded-md
|
||||
bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200
|
||||
class="flex flex-row items-center gap-1 p-1 px-3 rounded-md
|
||||
bg-slate-100 dark:bg-zinc-800 hover:bg-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}"
|
||||
>
|
||||
<Icon src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
||||
@@ -124,5 +115,29 @@
|
||||
<FormattedNumber number={postRes.counts.comments} />
|
||||
</span>
|
||||
</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>
|
||||
</Card>
|
||||
@@ -37,39 +37,41 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex flex-row items-center gap-1 rounded-md transition-colors
|
||||
cursor-pointer border border-slate-200 dark:border-zinc-800
|
||||
<slot {upvote} {downvote} {vote} {score}>
|
||||
<div
|
||||
class="flex flex-row items-center gap-1 rounded-md transition-colors
|
||||
cursor-pointer border border-slate-200 dark:border-zinc-700 px-1 py-[2px]
|
||||
{// upvote
|
||||
vote == 1
|
||||
? 'bg-orange-600/20 text-orange-500'
|
||||
: // downvote
|
||||
vote == -1
|
||||
? 'bg-blue-600/40 text-blue-400'
|
||||
: // no vote
|
||||
'bg-slate-100 dark:bg-zinc-900 hover:bg-slate-200 dark:hover:bg-zinc-700'}"
|
||||
>
|
||||
<button
|
||||
aria-label="Upvote"
|
||||
class="p-1 px-1.5"
|
||||
on:click={() => {
|
||||
vote = vote == 1 ? 0 : 1
|
||||
upvote()
|
||||
}}
|
||||
vote == 1
|
||||
? 'bg-orange-600/20 text-orange-500'
|
||||
: // downvote
|
||||
vote == -1
|
||||
? 'bg-blue-600/40 text-blue-400'
|
||||
: // no vote
|
||||
'bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200 dark:hover:bg-zinc-700'}"
|
||||
>
|
||||
<Icon src={ChevronUp} mini width={20} height={20} />
|
||||
</button>
|
||||
<span class="text-sm">
|
||||
<FormattedNumber number={score} />
|
||||
</span>
|
||||
<button
|
||||
aria-label="Downvote"
|
||||
class="p-1 px-1.5"
|
||||
on:click={() => {
|
||||
vote = vote == -1 ? 0 : -1
|
||||
downvote()
|
||||
}}
|
||||
>
|
||||
<Icon src={ChevronDown} mini width={20} height={20} />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
aria-label="Upvote"
|
||||
class="p-0.5 px-1"
|
||||
on:click={() => {
|
||||
vote = vote == 1 ? 0 : 1
|
||||
upvote()
|
||||
}}
|
||||
>
|
||||
<Icon src={ChevronUp} mini width={20} height={20} />
|
||||
</button>
|
||||
<span class="text-sm">
|
||||
<FormattedNumber number={score} />
|
||||
</span>
|
||||
<button
|
||||
aria-label="Downvote"
|
||||
class="p-0.5 px-1"
|
||||
on:click={() => {
|
||||
vote = vote == -1 ? 0 : -1
|
||||
downvote()
|
||||
}}
|
||||
>
|
||||
<Icon src={ChevronDown} mini width={20} height={20} />
|
||||
</button>
|
||||
</div>
|
||||
</slot>
|
||||
@@ -16,6 +16,7 @@
|
||||
import CommentForm from './CommentForm.svelte'
|
||||
import { page } from '$app/stores'
|
||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
|
||||
export let node: CommentNodeI
|
||||
|
||||
@@ -59,7 +60,7 @@
|
||||
|
||||
<li
|
||||
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()}"
|
||||
>
|
||||
@@ -105,7 +106,7 @@
|
||||
max-w-full"
|
||||
>
|
||||
<div class="max-w-full break-words">
|
||||
<SvelteMarkdown source={node.comment_view.comment.content} />
|
||||
<Markdown source={node.comment_view.comment.content} />
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
|
||||
@@ -35,7 +35,11 @@
|
||||
ToastType.success
|
||||
)
|
||||
} 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
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<script lang="ts">
|
||||
import MarkdownLink from '$lib/components/markdown/MarkdownLink.svelte'
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
|
||||
export let source: string
|
||||
export let source: string | undefined
|
||||
</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>
|
||||
|
||||
<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
|
||||
flex-col gap-4 p-4 rounded-md {clazz}"
|
||||
flex-col p-1 rounded-md {clazz}"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import Logo from '$lib/components/ui/Logo.svelte'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
@@ -15,8 +16,11 @@
|
||||
ArrowLeftOnRectangle,
|
||||
ArrowRightOnRectangle,
|
||||
Cog6Tooth,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
Inbox,
|
||||
PencilSquare,
|
||||
Plus,
|
||||
UserCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
</script>
|
||||
@@ -28,7 +32,7 @@
|
||||
<div class="flex flex-row gap-2 items-center mr-auto">
|
||||
<a href="/" class="flex flex-row items-center gap-2">
|
||||
<Logo width={40} />
|
||||
<div class="flex flex-col">
|
||||
<div class="sm:flex flex-col hidden">
|
||||
<span class="font-bold">Xylemmy</span>
|
||||
<span
|
||||
class="text-xs opacity-50
|
||||
@@ -43,10 +47,27 @@
|
||||
</div>
|
||||
</a>
|
||||
</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>
|
||||
<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"
|
||||
slot="button"
|
||||
>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<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
|
||||
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
|
||||
|
||||
let element: any
|
||||
|
||||
export let preventDefault = false
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
@@ -31,7 +33,11 @@
|
||||
class="overflow-visible z-30 {absolute
|
||||
? 'absolute'
|
||||
: 'relative'} cursor-auto {clazz}"
|
||||
on:click={() => (open = !open)}
|
||||
on:click={(e) => {
|
||||
if (preventDefault) e.preventDefault()
|
||||
|
||||
open = !open
|
||||
}}
|
||||
bind:this={element}
|
||||
>
|
||||
<slot name="button" />
|
||||
@@ -42,7 +48,7 @@
|
||||
start: 0.95,
|
||||
easing: expoOut,
|
||||
}}
|
||||
class="absolute {rtl
|
||||
class="absolute max-h-64 overflow-auto {rtl
|
||||
? 'origin-top-right right-0'
|
||||
: 'origin-top-left left-0'}
|
||||
{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 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 {
|
||||
if (!instance) {
|
||||
instance = get(authData)?.instance ?? DEFAULT_INSTANCE_URL
|
||||
@@ -31,7 +39,7 @@ if (typeof localStorage != 'undefined') {
|
||||
try {
|
||||
authData.set(JSON.parse(localStorage.getItem('user') ?? ''))
|
||||
} catch (error) {
|
||||
localStorage.removeItem('user')
|
||||
// keep authdata until we can verify that the user is infact invalid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-11
@@ -23,6 +23,10 @@
|
||||
export let data
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Xylemmy</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-row gap-4">
|
||||
<div class="flex flex-col gap-4 max-w-full">
|
||||
<div class="flex flex-col sm:flex-row gap-4 max-w-full">
|
||||
@@ -60,18 +64,20 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Link
|
||||
href={(function () {
|
||||
<Button
|
||||
on:click={() => {
|
||||
$page.url.searchParams.set(
|
||||
'page',
|
||||
((Number($page.url.searchParams.get('page')) || 1) + 1).toString()
|
||||
)
|
||||
|
||||
return $page.url.toString()
|
||||
})()}
|
||||
goto($page.url.toString(), {
|
||||
invalidateAll: true,
|
||||
})
|
||||
}}
|
||||
>
|
||||
Next
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ml-auto hidden lg:block max-w-sm w-full">
|
||||
@@ -104,12 +110,14 @@
|
||||
</Card>
|
||||
{:then site}
|
||||
<Card>
|
||||
<Avatar
|
||||
width={64}
|
||||
url={site.site_view.site.icon ?? ''}
|
||||
alt={site.site_view.site.name}
|
||||
/>
|
||||
<span class="flex flex-row items-center gap-1 text-sm">
|
||||
{#if site.site_view.site.icon}
|
||||
<Avatar
|
||||
width={64}
|
||||
url={site.site_view.site.icon}
|
||||
alt={site.site_view.site.name}
|
||||
/>
|
||||
{/if}
|
||||
<span class="flex flex-row items-center gap-1 text-sm capitalize">
|
||||
<Icon src={Calendar} width={16} height={16} mini />
|
||||
<RelativeDate date={new Date(site.site_view.site.published)} />
|
||||
</span>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import Card from '$lib/components/ui/StickyCard.svelte'
|
||||
import CommunityCard from '$lib/components/community/CommunityCard.svelte'
|
||||
|
||||
export let data
|
||||
</script>
|
||||
@@ -56,8 +57,8 @@
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<Card>
|
||||
{#await data.streamed.community}
|
||||
{#await data.streamed.community}
|
||||
<Card>
|
||||
<div
|
||||
class="w-[64px] h-[64px] rounded-full bg-slate-200
|
||||
dark:bg-zinc-700 animate-pulse"
|
||||
@@ -82,41 +83,12 @@
|
||||
class="w-24 h-4 bg-slate-200 dark:bg-zinc-700 animate-pulse
|
||||
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}
|
||||
</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>
|
||||
{/await}
|
||||
</Card>
|
||||
</Card>
|
||||
{/await}
|
||||
</div>
|
||||
@@ -2,14 +2,14 @@ import { authData, getClient } from '$lib/lemmy.js'
|
||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||
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 sort: SortType =
|
||||
(req.url.searchParams.get('sort') as SortType) || 'Active'
|
||||
|
||||
return {
|
||||
posts: getClient(req.params).getPosts({
|
||||
posts: getClient().getPosts({
|
||||
limit: 40,
|
||||
community_name: req.params.name,
|
||||
page: page,
|
||||
|
||||
@@ -35,20 +35,18 @@
|
||||
}}
|
||||
/>
|
||||
<div class="flex flex-col sm:flex-row gap-2 sm:ml-auto">
|
||||
<TextInput
|
||||
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
|
||||
dark:bg-zinc-900 rounded-md"
|
||||
bind:value={search}
|
||||
/>
|
||||
<Link
|
||||
href={(function () {
|
||||
<TextInput class="rounded-md" bind:value={search} />
|
||||
<Button
|
||||
on:click={() => {
|
||||
$page.url.searchParams.set('q', search)
|
||||
return $page.url.toString()
|
||||
})()}
|
||||
goto($page.url.toString(), {
|
||||
invalidateAll: true,
|
||||
})
|
||||
}}
|
||||
color={Color.ghost}
|
||||
>
|
||||
Search
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="flex flex-col">
|
||||
@@ -92,11 +90,11 @@
|
||||
</div>
|
||||
</div>
|
||||
{#if !community.community.local}
|
||||
<span class="opacity-80">
|
||||
<span class="opacity-80 mb-2">
|
||||
{new URL(community.community.actor_id).hostname}
|
||||
</span>
|
||||
{/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">
|
||||
<Icon src={UserGroup} width={16} mini />
|
||||
<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 { get } from 'svelte/store'
|
||||
|
||||
export function load({ url }) {
|
||||
const type = url.searchParams.get('listingType') as ListingType
|
||||
@@ -10,17 +11,19 @@ export function load({ url }) {
|
||||
return getClient().search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: 'Active',
|
||||
sort: 'TopAll',
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
auth: get(authData)?.token,
|
||||
})
|
||||
} else {
|
||||
return getClient().listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: 'Active',
|
||||
sort: 'TopAll',
|
||||
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
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Inbox</title>
|
||||
</svelte:head>
|
||||
|
||||
<h1 class="font-bold text-3xl">Inbox</h1>
|
||||
<div class="flex flex-col gap-4 list-none my-4">
|
||||
{#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>
|
||||
|
||||
<svelte:head>Login</svelte:head>
|
||||
|
||||
<Card class="mx-auto p-6">
|
||||
<form on:submit|preventDefault={logIn} class="flex flex-col gap-4">
|
||||
<h1 class="font-bold text-lg">Log in</h1>
|
||||
@@ -76,6 +78,7 @@
|
||||
disabled={data.loading}
|
||||
large
|
||||
color={Color.accent}
|
||||
submit
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
import { page } from '$app/stores'
|
||||
import { onMount } from 'svelte'
|
||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -85,7 +86,10 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<title>{data.post.post_view.post.name}</title>
|
||||
<svelte:head>
|
||||
<title>{data.post.post_view.post.name}</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<span class="flex flex-row gap-2 text-sm opacity-80 items-center">
|
||||
<CommunityLink avatar community={postData.community} />
|
||||
@@ -118,7 +122,7 @@
|
||||
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
|
||||
dark:bg-zinc-900 p-2 text-sm rounded-md leading-5"
|
||||
>
|
||||
<SvelteMarkdown source={post.body} />
|
||||
<Markdown source={post.body} />
|
||||
</p>
|
||||
{/if}
|
||||
<div class="w-max">
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
|
||||
import Link from '$lib/components/input/Link.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 Card from '$lib/components/ui/Card.svelte'
|
||||
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||
@@ -21,6 +22,10 @@
|
||||
}
|
||||
</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-col gap-4 max-w-full">
|
||||
{#each data.user.comments as item}
|
||||
@@ -79,7 +84,7 @@
|
||||
{data.user.person_view.person.name}
|
||||
</h1>
|
||||
{#if data.user.person_view.person.bio}
|
||||
<SvelteMarkdown source={data.user.person_view.person.bio} />
|
||||
<Markdown source={data.user.person_view.person.bio} />
|
||||
{/if}
|
||||
</StickyCard>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user