feat: Add search function

This commit is contained in:
Xyphyn committed 2023-07-26 11:39:54 -07:00
1 parent 91134d05e4
commit 1dd179d636
22 files changed
+455 -70

No files matched your search

@@ -0,0 +1,41 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import Card from '$lib/components/ui/Card.svelte'
import { getInstance } from '$lib/lemmy.js'
import type { CommentView } from 'lemmy-js-client'
export let comment: CommentView
</script>
<Card class="flex flex-col bg-white rounded-md p-5 flex-1 gap-1">
<div class="flex flex-row justify-between items-center">
<PostMeta
community={comment.community}
deleted={false}
featured={false}
nsfw={comment.post.nsfw}
published={new Date(comment.post.published)}
saved={false}
/>
<Button
color="secondary"
href="/post/{comment.post.id}#{comment.comment.id}"
size="sm"
class="self-start"
>
Jump
</Button>
</div>
<a href="/post/{getInstance()}/{comment.post.id}" class="font-bold">
{comment.post.name}
</a>
<div class="list-none">
<Comment
postId={comment.post.id}
node={{ children: [], comment_view: comment, depth: 1 }}
replying={false}
/>
</div>
</Card>
@@ -0,0 +1,132 @@
<script lang="ts">
import Button from '$lib/components/input/Button.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'
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { authData, getClient } from '$lib/lemmy.js'
import { Color } from '$lib/ui/colors.js'
import type { CommunityView } from 'lemmy-js-client'
import {
Calendar,
ChatBubbleOvalLeftEllipsis,
Icon,
PencilSquare,
UserGroup,
} from 'svelte-hero-icons'
export let community_view: CommunityView
let loading = {
blocking: false,
subscribing: false,
}
async function subscribe() {
if (!$authData) return
loading.subscribing = true
const subscribed =
community_view.subscribed == 'Subscribed' ||
community_view.subscribed == 'Pending'
try {
await getClient().followCommunity({
auth: $authData.token,
community_id: community_view.community.id,
follow: !subscribed,
})
} catch (error) {
addToast('Error', error as any, ToastType.error)
}
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
loading.subscribing = false
}
async function block() {
if (!$authData) return
loading.blocking = true
const blocked = community_view.blocked
try {
await getClient().blockCommunity({
auth: $authData.token,
community_id: community_view.community.id,
block: !blocked,
})
} catch (error) {
addToast('Error', error as any, ToastType.error)
}
community_view.blocked = !blocked
loading.blocking = false
}
</script>
<StickyCard>
<div class="flex flex-row gap-3 items-center">
<Avatar
width={42}
url={community_view.community.icon ??
`https://api.dicebear.com/6.x/initials/svg?seed=${community_view.community.name}`}
alt={community_view.community.name}
/>
<div class="flex flex-col">
<h1 class="font-bold text-base">
{community_view.community.title}
</h1>
<span class="opacity-60 text-sm">
!{community_view.community.name}@{new URL(
community_view.community.actor_id
).hostname}
</span>
</div>
</div>
<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>
{#if $authData}
<div class="w-full mt-2 flex flex-col gap-2">
<Button
disabled={loading.subscribing}
loading={loading.subscribing}
color="ghost"
size="lg"
on:click={subscribe}
>
{community_view.subscribed == 'Subscribed' ||
community_view.subscribed == 'Pending'
? 'Unsubscribe'
: 'Subscribe'}
</Button>
<Button
disabled={loading.blocking}
loading={loading.blocking}
color="danger"
size="lg"
on:click={block}
>
{community_view.blocked ? 'Unblock' : 'Block'}
</Button>
</div>
{/if}
<Markdown source={community_view.community.description} />
</StickyCard>
@@ -0,0 +1,74 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import type { CommunityView } from 'lemmy-js-client'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import {
ChatBubbleOvalLeftEllipsis,
Icon,
PencilSquare,
UserGroup,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
export let community: CommunityView
</script>
<div
class="py-4 border-b border-black/20 dark:border-white/20
flex flex-col gap-1 text-sm max-w-full"
>
<div class="flex flex-row items-center">
<span
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
>
<CommunityLink avatar community={community.community} />
</span>
<div class="ml-auto">
<Subscribe {community} let:subscribe let:subscribing>
<Button
disabled={subscribing}
loading={subscribing}
on:click={async () => {
const res = await subscribe()
if (res) {
community.subscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
}
}}
color={community.subscribed == 'Subscribed' ? 'primary' : 'ghost'}
>
{community.subscribed == 'Subscribed' ? 'Subscribed' : 'Subscribe'}
</Button>
</Subscribe>
</div>
</div>
<span class="opacity-80 mb-2">
{new URL(community.community.actor_id).hostname}
</span>
<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>
{Intl.NumberFormat('en', { notation: 'compact' }).format(
community.counts.subscribers
)}
</span>
</div>
<div class="flex flex-row gap-1 items-center">
<Icon src={PencilSquare} mini width={16} />
<span>
{Intl.NumberFormat('en', { notation: 'compact' }).format(
community.counts.posts
)}
</span>
</div>
<div class="flex flex-row gap-1 items-center">
<Icon src={ChatBubbleOvalLeftEllipsis} mini width={16} />
<FormattedNumber number={community.counts.comments} />
</div>
</div>
</div>
@@ -0,0 +1,28 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { Community } from 'lemmy-js-client'
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
return `/c/${community.name}@${domain}`
}
</script>
<a
class="items-center flex flex-row gap-2 hover:underline"
href={linkFromCommunity(community)}
>
{#if avatar}
<Avatar
url={community.icon ??
`https://api.dicebear.com/6.x/initials/svg?seed=${community.name}`}
alt={community.name}
width={avatarSize}
/>
{/if}
{community.title}
</a>
+38 -40
View File
@@ -16,7 +16,7 @@
<Card class="bg-white flex flex-col w-full p-5 gap-2.5">
<div class="flex flex-row w-full gap-2.5">
<div class="flex flex-col gap-2.5 grow">
<div class="flex flex-col gap-1 grow">
<PostMeta
community={post.community}
user={post.creator}
@@ -38,23 +38,21 @@
</div>
{#if $userSettings.showCompactPosts && (post.post.thumbnail_url || isImage(post.post.url))}
<div class="flex-none w-24 h-24">
<a
href="/post/{getInstance()}/{post.post.id}"
>
<a href="/post/{getInstance()}/{post.post.id}">
{#if post.post.thumbnail_url}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.thumbnail_url}?thumbnail=256&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.thumbnail_url}?thumbnail=256&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{:else}
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=256&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=256&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md h-24 w-24 border border-slate-200 dark:border-zinc-700"
/>
{/if}
</a>
</div>
@@ -71,30 +69,30 @@
{/if}
{#if isImage(post.post.url)}
<div class="self-start" class:blur-3xl={post.post.nsfw}>
<picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
>
<source
srcset="{post.post.url}?thumbnail=256&format=webp"
media="(max-width: 256px)"
/>
<source
srcset="{post.post.url}?thumbnail=512&format=webp"
media="(max-width: 512px)"
/>
<source
srcset="{post.post.url}?thumbnail=720&format=webp"
media="(max-width: 720px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=1024&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md max-h-[50vh] w-full"
width={512}
height={300}
/>
</picture>
<picture
class="rounded-md overflow-hidden max-h-[min(50vh,500px)] w-full max-w-full"
>
<source
srcset="{post.post.url}?thumbnail=256&format=webp"
media="(max-width: 256px)"
/>
<source
srcset="{post.post.url}?thumbnail=512&format=webp"
media="(max-width: 512px)"
/>
<source
srcset="{post.post.url}?thumbnail=720&format=webp"
media="(max-width: 720px)"
/>
<!-- svelte-ignore a11y-missing-attribute -->
<img
src="{post.post.url}?thumbnail=1024&format=webp"
loading="lazy"
class="object-cover bg-slate-100 rounded-md max-h-[50vh] w-full"
width={512}
height={300}
/>
</picture>
</div>
{:else if post.post.thumbnail_url && post.post.url}
<PostLink
+14 -10
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Badge from '$lib/components/ui/Badge.svelte'
import UserLink from '$lib/components/user/UserLink.svelte'
@@ -8,12 +8,12 @@
import { Bookmark, Icon, InformationCircle, Trash } from 'svelte-hero-icons'
export let community: Community
export let user: Person
export let user: Person | undefined = undefined
export let published: Date
// Score
export let upvotes: number
export let downvotes: number
export let upvotes: number | undefined = undefined
export let downvotes: number | undefined = undefined
// Badges
export let nsfw: boolean
@@ -27,13 +27,17 @@
<div class="flex flex-col text-xs">
<CommunityLink {community} />
<span class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1">
<UserLink {user} />
<span>•</span>
{#if user}
<UserLink {user} />
<span>•</span>
{/if}
<RelativeDate date={published} />
<span>•</span>
<span>
{Math.floor((upvotes / (upvotes + downvotes || 1)) * 100)}%
</span>
{#if upvotes && downvotes}
<span>•</span>
<span>
{Math.floor((upvotes / (upvotes + downvotes || 1)) * 100)}%
</span>
{/if}
</span>
</div>
@@ -0,0 +1,35 @@
<script lang="ts">
import type { PersonView } from 'lemmy-js-client'
import {
ChatBubbleOvalLeftEllipsis,
Icon,
PencilSquare,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import UserLink from '$lib/components/user/UserLink.svelte'
export let user: PersonView
</script>
<div
class="py-2
flex flex-col gap-3 text-sm max-w-full"
>
<div class="flex flex-row items-center">
<span
class="break-words max-w-full w-max text-base font-bold text-sky-400 hover:underline"
>
<UserLink avatar user={user.person} />
</span>
</div>
<div class="flex flex-row gap-3 items-center">
<div class="flex flex-row gap-1 items-center" title="Post count">
<Icon src={PencilSquare} mini width={16} />
<FormattedNumber number={user.counts.post_count} />
</div>
<div class="flex flex-row gap-1 items-center" title="Comment count">
<Icon src={ChatBubbleOvalLeftEllipsis} mini width={16} />
<FormattedNumber number={user.counts.comment_count} />
</div>
</div>
</div>