diff --git a/src/routes/inbox/InboxItem.svelte b/src/routes/inbox/InboxItem.svelte
index 6a470795..65c1698c 100644
--- a/src/routes/inbox/InboxItem.svelte
+++ b/src/routes/inbox/InboxItem.svelte
@@ -23,19 +23,17 @@
function isPrivateMessage(
item: CommentReplyView | PersonMentionView | PrivateMessageView
- ) {
+ ): item is PrivateMessageView {
return 'private_message' in item
}
- // I hate how you can't type cast in Svelte easily
- const replyItem = item as CommentReplyView | PersonMentionView
- const messageItem = item as PrivateMessageView
-
let replying = false
let reply = ''
let loading = false
- async function replyToMessage() {
+ async function replyToMessage(
+ message: PrivateMessageView | CommentReplyView | PersonMentionView
+ ) {
if (!$authData) return
loading = true
@@ -44,7 +42,7 @@
await getClient().createPrivateMessage({
auth: $authData.token,
content: reply,
- recipient_id: messageItem.creator.id,
+ recipient_id: message.creator.id,
})
addToast(
@@ -75,28 +73,26 @@
overflow-hidden {read ? 'opacity-50' : ''}"
>
- {replyItem.creator.display_name ?? replyItem.creator.name}
+ {item.creator.display_name ?? item.creator.name}
replied to you in
- {replyItem.post.name}
+ {item.post.name}
-
- Jump
-
+ Jump
@@ -107,26 +103,26 @@
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
>
- {#if messageItem.creator.id == $user?.person.id}
+ {#if item.creator.id == $user?.person.id}
You
{:else}
-
+
{/if}
messaged
- {#if messageItem.recipient.id == $user?.person.id}
+ {#if item.recipient.id == $user?.person.id}
You
{:else}
-
+
{/if}
-
+
- {#if messageItem.recipient.id == $user?.person.id}
+ {#if item.recipient.id == $user?.person.id}
{/if}
- {#if replying}
+ {#if isPrivateMessage(item)}
@@ -142,7 +138,7 @@
disabled={loading}
{loading}
large
- on:click={replyToMessage}
+ on:click={() => replyToMessage(item)}
color={Color.accent}
>
Submit
diff --git a/src/routes/saved/+page.svelte b/src/routes/saved/+page.svelte
index 1e5f3b9e..75b210af 100644
--- a/src/routes/saved/+page.svelte
+++ b/src/routes/saved/+page.svelte
@@ -10,11 +10,8 @@
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
+ const isComment = (item: CommentView | PostView): item is CommentView =>
+ 'comment' in item
@@ -41,20 +38,18 @@
{item.post.name}
-
- Jump
-
+
Jump
{:else}
-
+
{/if}
{/each}
diff --git a/src/routes/u/[name]/+page.svelte b/src/routes/u/[name]/+page.svelte
index b7271b37..e1cf6fea 100644
--- a/src/routes/u/[name]/+page.svelte
+++ b/src/routes/u/[name]/+page.svelte
@@ -25,34 +25,20 @@
user: GetPersonDetailsResponse
}
- interface Item {
- post: boolean
- comment: boolean
- item: CommentView & PostView
- }
+ const isComment = (item: CommentView | PostView): item is CommentView =>
+ 'comment' in item
- function getDateOfItem(item: Item): number {
- if (item.post) {
- return Date.parse(item.item.post.published)
- } else if (item.comment) {
- return Date.parse(item.item.comment.published)
+ function getDateOfItem(item: CommentView | PostView): number {
+ if (isComment(item)) {
+ return Date.parse(item.comment.published)
} else {
- return Date.now()
+ return Date.parse(item.post.published)
}
}
- const items: Item[] = [...data.user.comments, ...data.user.posts]
- .map((i) => {
- const post = 'read' in i
- const comment = !post
-
- return {
- post: post,
- comment: comment,
- item: i as CommentView & PostView,
- }
- })
- .sort((a, b) => getDateOfItem(b) - getDateOfItem(a))
+ const items = [...data.user.comments, ...data.user.posts].sort(
+ (a, b) => getDateOfItem(b) - getDateOfItem(a)
+ )
@@ -62,31 +48,30 @@
{#each items as item}
- {#if item.post}
-
- {:else}
-
+ {#if isComment(item)}
-
+
- {item.item.post.name}
+ {item.post.name}
-
- Jump
-
+
Jump
+ {:else}
+
{/if}
{/each}