feat: Add menu origin classes
This commit is contained in:
1 parent
ad0023260d
commit
8eef99cc18
8 files changed
+238
-48
No files matched your search
@@ -1,27 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from 'lemmy-js-client'
|
||||||
import {
|
|
||||||
ChatBubbleOvalLeft,
|
|
||||||
EllipsisHorizontal,
|
|
||||||
Icon,
|
|
||||||
Square2Stack,
|
|
||||||
Trash,
|
|
||||||
} 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 } from '$lib/ui/image.js'
|
import { isImage } from '$lib/ui/image.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 UserLink from '$lib/components/user/UserLink.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import { authData, getClient, getInstance, user } from '$lib/lemmy.js'
|
import { getInstance } 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'
|
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
|
||||||
import PostActions from '$lib/components/lemmy/PostActions.svelte'
|
import PostActions from '$lib/components/lemmy/PostActions.svelte'
|
||||||
|
|
||||||
let postRes: PostView
|
let postRes: PostView
|
||||||
|
|||||||
@@ -55,11 +55,7 @@
|
|||||||
<Icon slot="icon" src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
<Icon slot="icon" src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
||||||
<FormattedNumber number={post.counts.comments} />
|
<FormattedNumber number={post.counts.comments} />
|
||||||
</Link>
|
</Link>
|
||||||
<Menu
|
<Menu origin="top-right" class="ml-auto overflow-auto" let:toggleOpen>
|
||||||
top={bottomMenu ? false : true}
|
|
||||||
class="ml-auto overflow-auto"
|
|
||||||
let:toggleOpen
|
|
||||||
>
|
|
||||||
<Button slot="button" label="Post actions" on:click={toggleOpen}>
|
<Button slot="button" label="Post actions" on:click={toggleOpen}>
|
||||||
<Icon src={EllipsisHorizontal} width={16} mini />
|
<Icon src={EllipsisHorizontal} width={16} mini />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
|
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
||||||
|
|
||||||
export let node: CommentNodeI
|
export let node: CommentNodeI
|
||||||
export let postId: number
|
export let postId: number
|
||||||
@@ -81,21 +82,7 @@
|
|||||||
<Markdown source={node.comment_view.comment.content} />
|
<Markdown source={node.comment_view.comment.content} />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row gap-2 items-center mt-1 h-[26px]">
|
<div class="flex flex-row gap-2 items-center mt-1 h-[26px]">
|
||||||
<CommentVote
|
<CommentActions comment={node.comment_view} bind:replying />
|
||||||
bind:score={node.comment_view.counts.score}
|
|
||||||
bind:vote={node.comment_view.my_vote}
|
|
||||||
commentId={node.comment_view.comment.id}
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="{$userSettings.newComments
|
|
||||||
? Color.borderDark
|
|
||||||
: 'hover:bg-slate-200 hover:dark:bg-zinc-800'} h-full px-2 flex flex-row items-center gap-1
|
|
||||||
rounded-md transition-colors"
|
|
||||||
on:click={() => (replying = !replying)}
|
|
||||||
>
|
|
||||||
<Icon src={ChatBubbleOvalLeft} width={16} height={16} mini />
|
|
||||||
<span class="text-xs">Reply</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if replying}
|
{#if replying}
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { CommentView } from 'lemmy-js-client'
|
||||||
|
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
|
||||||
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
import { Color } from '$lib/ui/colors.js'
|
||||||
|
import {
|
||||||
|
Bookmark,
|
||||||
|
BookmarkSlash,
|
||||||
|
ChatBubbleOvalLeft,
|
||||||
|
EllipsisHorizontal,
|
||||||
|
Icon,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
|
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
|
|
||||||
|
export let comment: CommentView
|
||||||
|
export let replying: boolean = false
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!$authData) return
|
||||||
|
|
||||||
|
const saved = comment.saved
|
||||||
|
|
||||||
|
comment.saved = !saved
|
||||||
|
|
||||||
|
try {
|
||||||
|
await getClient().saveComment({
|
||||||
|
auth: $authData.token,
|
||||||
|
comment_id: comment.comment.id,
|
||||||
|
save: !saved,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
comment.saved = saved
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: error as any,
|
||||||
|
type: ToastType.error,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-row gap-2 items-center mt-1 h-[26px] relative">
|
||||||
|
<CommentVote
|
||||||
|
bind:score={comment.counts.score}
|
||||||
|
bind:vote={comment.my_vote}
|
||||||
|
commentId={comment.comment.id}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
class="{$userSettings.newComments
|
||||||
|
? Color.borderDark
|
||||||
|
: 'hover:bg-slate-200 hover:dark:bg-zinc-800'} h-full px-2 flex flex-row items-center gap-1
|
||||||
|
rounded-md transition-colors"
|
||||||
|
on:click={() => (replying = !replying)}
|
||||||
|
>
|
||||||
|
<Icon src={ChatBubbleOvalLeft} width={16} height={16} mini />
|
||||||
|
<span class="text-xs">Reply</span>
|
||||||
|
</button>
|
||||||
|
<div class="h-full relative">
|
||||||
|
<Menu let:toggleOpen class="h-[26px] top-0" absolute origin="bottom-center">
|
||||||
|
<button
|
||||||
|
slot="button"
|
||||||
|
class="{Color.borderDark} h-full px-1 flex flex-row items-center gap-1
|
||||||
|
rounded-md transition-colors"
|
||||||
|
on:click={toggleOpen}
|
||||||
|
>
|
||||||
|
<Icon src={EllipsisHorizontal} width={16} height={16} mini />
|
||||||
|
</button>
|
||||||
|
<span class="opacity-80 my-1 py-1 text-xs mx-4">Comment actions</span>
|
||||||
|
{#if $authData?.token}
|
||||||
|
<MenuButton on:click={save}>
|
||||||
|
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
||||||
|
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
ArrowRightOnRectangle,
|
ArrowRightOnRectangle,
|
||||||
Beaker,
|
Beaker,
|
||||||
|
Bookmark,
|
||||||
GlobeAlt,
|
GlobeAlt,
|
||||||
Icon,
|
Icon,
|
||||||
Inbox,
|
Inbox,
|
||||||
@@ -55,7 +56,7 @@
|
|||||||
<Icon src={GlobeAlt} width={16} />
|
<Icon src={GlobeAlt} width={16} />
|
||||||
<span class="hidden sm:inline ml-1">Explore</span>
|
<span class="hidden sm:inline ml-1">Explore</span>
|
||||||
</Link>
|
</Link>
|
||||||
<Menu let:toggleOpen>
|
<Menu let:toggleOpen origin="bottom-right">
|
||||||
<Button
|
<Button
|
||||||
color={Color.accent}
|
color={Color.accent}
|
||||||
slot="button"
|
slot="button"
|
||||||
@@ -65,14 +66,14 @@
|
|||||||
<Icon src={Plus} width={18} mini />
|
<Icon src={Plus} width={18} mini />
|
||||||
<span class="hidden sm:inline">Create</span>
|
<span class="hidden sm:inline">Create</span>
|
||||||
</Button>
|
</Button>
|
||||||
<span class="text-xs opacity-80 text-left mx-4 my-1 py-1">Create</span>
|
<li class="text-xs opacity-80 text-left mx-4 my-1 py-1">Create</li>
|
||||||
<MenuButton link href="/create/post">
|
<MenuButton link href="/create/post">
|
||||||
<Icon src={PencilSquare} mini width={16} />
|
<Icon src={PencilSquare} mini width={16} />
|
||||||
Post
|
Post
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
<Menu let:toggleOpen>
|
<Menu let:toggleOpen origin="bottom-right">
|
||||||
<button
|
<button
|
||||||
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100
|
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100
|
||||||
dark:bg-zinc-800 relative"
|
dark:bg-zinc-800 relative"
|
||||||
@@ -115,6 +116,9 @@
|
|||||||
</div>
|
</div>
|
||||||
Inbox
|
Inbox
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
<MenuButton link href="/saved">
|
||||||
|
<Icon src={Bookmark} mini width={16} /> Saved
|
||||||
|
</MenuButton>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
localStorage.removeItem('user')
|
localStorage.removeItem('user')
|
||||||
@@ -125,7 +129,7 @@
|
|||||||
>
|
>
|
||||||
<Icon src={ArrowRightOnRectangle} mini width={16} />Log out
|
<Icon src={ArrowRightOnRectangle} mini width={16} />Log out
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<hr class="opacity-10 w-[90%] my-2 mx-auto" />
|
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
||||||
<li class="text-xs px-4 py-1 my-1 opacity-80">v{__VERSION__}</li>
|
<li class="text-xs px-4 py-1 my-1 opacity-80">v{__VERSION__}</li>
|
||||||
<MenuButton link href="/experiments">
|
<MenuButton link href="/experiments">
|
||||||
<Icon src={Beaker} mini width={16} />
|
<Icon src={Beaker} mini width={16} />
|
||||||
|
|||||||
@@ -10,12 +10,47 @@
|
|||||||
export let itemsClass = ''
|
export let itemsClass = ''
|
||||||
|
|
||||||
export let absolute = false
|
export let absolute = false
|
||||||
|
/**
|
||||||
|
* @deprecated use @var origin instead
|
||||||
|
*/
|
||||||
export let rtl = true
|
export let rtl = true
|
||||||
|
/**
|
||||||
|
* @deprecated use @var origin instead
|
||||||
|
*/
|
||||||
export let top = false
|
export let top = false
|
||||||
|
|
||||||
|
type Origin =
|
||||||
|
| 'top-right'
|
||||||
|
| 'top-left'
|
||||||
|
| 'bottom-right'
|
||||||
|
| 'bottom-left'
|
||||||
|
| 'bottom-center'
|
||||||
|
| 'top-center'
|
||||||
|
|
||||||
|
export let origin: Origin = 'bottom-left'
|
||||||
|
|
||||||
let element: any
|
let element: any
|
||||||
|
|
||||||
export const toggleOpen = () => (open = !open)
|
export const toggleOpen = () => (open = !open)
|
||||||
|
|
||||||
|
function getOriginClass(origin: Origin) {
|
||||||
|
switch (origin) {
|
||||||
|
case 'top-right':
|
||||||
|
return 'bottom-[100%] right-0 origin-bottom'
|
||||||
|
case 'bottom-left':
|
||||||
|
return 'top-[100%] origin-top-left'
|
||||||
|
case 'top-left':
|
||||||
|
return 'top-[100%] left-0 origin-top-left'
|
||||||
|
case 'bottom-right':
|
||||||
|
return 'top-[100%] right-0 origin-top-right'
|
||||||
|
case 'top-center':
|
||||||
|
return 'bottom-[100%] -left-[450%] origin-bottom'
|
||||||
|
case 'bottom-center':
|
||||||
|
return 'top-[100%] -left-[450%] origin-top'
|
||||||
|
default:
|
||||||
|
return 'bottom-[100%] origin-top-left'
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:body
|
<svelte:body
|
||||||
@@ -28,10 +63,11 @@
|
|||||||
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<div
|
<div
|
||||||
class="overflow-visible z-30 {absolute
|
class="overflow-visible {absolute
|
||||||
? 'absolute'
|
? 'absolute'
|
||||||
: 'relative'} cursor-auto {clazz}"
|
: 'relative'} cursor-auto {clazz}"
|
||||||
bind:this={element}
|
bind:this={element}
|
||||||
|
tabindex="-1"
|
||||||
>
|
>
|
||||||
<slot name="button" {toggleOpen} />
|
<slot name="button" {toggleOpen} />
|
||||||
{#if open}
|
{#if open}
|
||||||
@@ -41,13 +77,12 @@
|
|||||||
start: 0.95,
|
start: 0.95,
|
||||||
easing: expoOut,
|
easing: expoOut,
|
||||||
}}
|
}}
|
||||||
class="list-none absolute max-h-64 z-30 overflow-auto {rtl
|
class="list-none absolute max-h-72 z-30 overflow-auto {getOriginClass(
|
||||||
? 'origin-top-right right-0'
|
origin
|
||||||
: 'origin-top-left left-0'}
|
)}
|
||||||
{top ? 'bottom-[100%] origin-bottom-left' : 'top-[100%]'}
|
rounded-md py-2 min-w-[16rem] my-2 flex flex-col shadow-md
|
||||||
rounded-md py-2 min-w-[16rem] my-2 flex flex-col shadow-md {itemsClass
|
bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800
|
||||||
? itemsClass
|
{itemsClass}"
|
||||||
: 'bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800'}"
|
|
||||||
>
|
>
|
||||||
{#if open}
|
{#if open}
|
||||||
<div on:click={toggleOpen}>
|
<div on:click={toggleOpen}>
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
|
import InboxItem from '../inbox/InboxItem.svelte'
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import Post from '$lib/components/lemmy/Post.svelte'
|
||||||
|
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'
|
||||||
|
|
||||||
|
export let data
|
||||||
|
|
||||||
|
const isComment = (item: CommentView | PostView) => 'comment' in item
|
||||||
|
|
||||||
|
// can't do type conversions in the template, so i have to do this
|
||||||
|
const asPost = (item: any) => item as PostView
|
||||||
|
const asComment = (item: any) => item as CommentView
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Saved posts</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<h1 class="text-xl font-bold">Saved Posts</h1>
|
||||||
|
<div class="flex flex-col gap-4 list-none my-4">
|
||||||
|
{#if !data.data || (data.data?.length ?? 0) == 0}
|
||||||
|
<p class="text-center opacity-60 text-lg mx-4">
|
||||||
|
Wow, it's quite empty in here.
|
||||||
|
</p>
|
||||||
|
{:else}
|
||||||
|
{#each data.data as item}
|
||||||
|
{#if isComment(item)}
|
||||||
|
<Card class="flex flex-col bg-white rounded-md p-4 flex-1">
|
||||||
|
<div class="flex flex-row justify-between items-center">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs dark:text-slate-400 text-zinc-600">
|
||||||
|
<CommunityLink avatar community={item.community} />
|
||||||
|
</span>
|
||||||
|
<span class="flex flex-row items-center text-sm font-bold">
|
||||||
|
{item.post.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Link href="/post/{item.post.id}#{asComment(item).comment.id}">
|
||||||
|
Jump
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div class="list-none">
|
||||||
|
<Comment
|
||||||
|
postId={item.post.id}
|
||||||
|
node={{ children: [], comment_view: asComment(item), depth: 1 }}
|
||||||
|
replying={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
{:else}
|
||||||
|
<Post post={asPost(item)} />
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
function getSavedItemPublished(item: PostView | CommentView) {
|
||||||
|
if ('comment' in item) {
|
||||||
|
return item.comment.published
|
||||||
|
} else {
|
||||||
|
return item.post.published
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function load({ url }) {
|
||||||
|
if (!get(authData)) return { posts: [] }
|
||||||
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
|
||||||
|
const client = getClient()
|
||||||
|
|
||||||
|
const [posts, comments] = await Promise.all([
|
||||||
|
client.getPosts({
|
||||||
|
saved_only: true,
|
||||||
|
auth: get(authData)!.token,
|
||||||
|
limit: 20,
|
||||||
|
page: page,
|
||||||
|
sort: 'New',
|
||||||
|
}),
|
||||||
|
|
||||||
|
client.getComments({
|
||||||
|
saved_only: true,
|
||||||
|
auth: get(authData)!.token,
|
||||||
|
limit: 20,
|
||||||
|
page: page,
|
||||||
|
sort: 'New',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
const everything = [...posts.posts, ...comments.comments].sort(
|
||||||
|
(a, b) =>
|
||||||
|
Date.parse(getSavedItemPublished(b)) -
|
||||||
|
Date.parse(getSavedItemPublished(a))
|
||||||
|
)
|
||||||
|
|
||||||
|
return { data: everything }
|
||||||
|
}
|
||||||
Reference in new issue
Block a user