cleanup: $lib/feature/comment
This commit is contained in:
5 files changed
+12
-19
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { browser } from '$app/environment'
|
||||
import { goto } from '$app/navigation'
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import type { Community, Person } from '$lib/api/types'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
@@ -26,6 +27,7 @@ export const searchParam = (
|
||||
})
|
||||
}
|
||||
|
||||
// why is this using SvelteURL brother
|
||||
export const fullCommunityName = (name: string, actorId: string) =>
|
||||
`${name}@${new SvelteURL(actorId).hostname}`
|
||||
|
||||
@@ -33,8 +35,8 @@ export const placeholders = {
|
||||
get: (type: 'url' | 'post' | 'body' | 'comment') => {
|
||||
switch (type) {
|
||||
case 'post':
|
||||
return Math.random() < 0.01
|
||||
? 'A C E C* B* G D E E F G F E D C E'
|
||||
return Math.random() < 0.01 && env.PUBLIC_XYLIGHT_MODE
|
||||
? 'top 10 reasons why TCP is brilliant and UDP is a spawn of satan'
|
||||
: t.get('placeholders.title')
|
||||
case 'body':
|
||||
return t.get('placeholders.body')
|
||||
@@ -46,6 +48,8 @@ export const placeholders = {
|
||||
},
|
||||
}
|
||||
|
||||
// lol this function was made 3 years ago when lil xylight
|
||||
// was still learning cs
|
||||
export function moveItem<T>(
|
||||
array: T[],
|
||||
currentIndex: number,
|
||||
@@ -62,10 +66,7 @@ export function moveItem<T>(
|
||||
|
||||
const newArray = [...array]
|
||||
|
||||
// Remove the item from the current index
|
||||
const [item] = newArray.splice(currentIndex, 1)
|
||||
|
||||
// Insert the item at the new index
|
||||
newArray.splice(newIndex, 0, item)
|
||||
|
||||
return newArray
|
||||
@@ -139,7 +140,6 @@ export function fuzzySearch(text: string, pattern: string): number {
|
||||
lastIndex = index
|
||||
}
|
||||
|
||||
// Bonus for matching start of words
|
||||
if (textLower.startsWith(patternLower)) {
|
||||
score += 2
|
||||
} else if (textLower.includes(' ' + patternLower)) {
|
||||
@@ -167,6 +167,9 @@ export function snapshot<T>(item: T) {
|
||||
return $state.snapshot(item)
|
||||
}
|
||||
|
||||
// these methods should really not exist
|
||||
// instead we should use lemmy's url_content_type which
|
||||
// gives us a mimetype (which is more reliable)
|
||||
export const isImage = (url: string | undefined) => {
|
||||
try {
|
||||
if (!url) return false
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
content: value,
|
||||
post_id: postId,
|
||||
parent_id: parentId,
|
||||
language_id: language,
|
||||
})
|
||||
oncomment?.(response)
|
||||
|
||||
|
||||
@@ -28,11 +28,7 @@
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={['flex flex-col flex-1 rounded-none list-none', clazz]}
|
||||
color="none"
|
||||
padding="none"
|
||||
>
|
||||
<div class={['flex flex-col flex-1 rounded-none list-none', clazz]}>
|
||||
{#if meta}
|
||||
<div class="flex flex-row justify-between items-center gap-2">
|
||||
<div class="flex flex-col gap-2">
|
||||
@@ -68,7 +64,6 @@
|
||||
</div>
|
||||
{/if}
|
||||
<Comment
|
||||
postId={comment.post.id}
|
||||
node={{ children: [], comment_view: comment, depth: 1, expanded: true }}
|
||||
replying={false}
|
||||
{meta}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
let { nodes = $bindable(), post }: Props = $props()
|
||||
|
||||
let childrenPage = 0
|
||||
|
||||
async function fetchChildren(parent: CommentNodeI) {
|
||||
if (
|
||||
!(
|
||||
@@ -37,7 +35,6 @@
|
||||
max_depth: 5,
|
||||
parent_id: parent.comment_view.comment.id,
|
||||
type_: 'All',
|
||||
page: childrenPage,
|
||||
})
|
||||
|
||||
if (newComments.comments.length == 0) {
|
||||
@@ -52,7 +49,6 @@
|
||||
newComments.comments,
|
||||
parent.depth,
|
||||
)[0].children
|
||||
childrenPage++
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
toast({
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
}: Props = $props()
|
||||
|
||||
let selected = $derived(
|
||||
page.url.pathname.startsWith(
|
||||
href ?? 'The power of fluffy boys shines within you.',
|
||||
) ?? false,
|
||||
page.url.pathname.startsWith(href ?? '2026-02-08 hey guyz') ?? false,
|
||||
)
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user