From 87612d6507df54ac96e50f71251f38651c161840 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 2 Aug 2023 14:22:27 -0700 Subject: [PATCH] feat: switch to a string instead of enum --- src/lib/auth.ts | 4 +- .../components/lemmy/comment/Comment.svelte | 6 +-- .../lemmy/comment/CommentActions.svelte | 12 +++--- .../lemmy/comment/CommentForm.svelte | 20 ++++----- .../components/lemmy/comment/Comments.svelte | 6 +-- .../lemmy/community/CommunityCard.svelte | 6 +-- .../lemmy/moderation/BanModal.svelte | 10 ++--- .../lemmy/moderation/ModerationMenu.svelte | 10 ++--- .../lemmy/moderation/RemoveModal.svelte | 6 +-- .../lemmy/moderation/ReportModal.svelte | 6 +-- src/lib/components/lemmy/post/Post.svelte | 4 +- .../components/lemmy/post/PostActions.svelte | 8 ++-- src/lib/components/lemmy/post/PostForm.svelte | 6 +-- src/lib/components/ui/toasts/Toast.svelte | 14 +++--- src/lib/components/ui/toasts/toasts.ts | 43 ++++--------------- src/routes/accounts/+page.svelte | 6 +-- src/routes/communities/Subscribe.svelte | 4 +- src/routes/inbox/InboxItem.svelte | 13 +++--- src/routes/login/+page.svelte | 12 ++---- src/routes/moderation/Report.svelte | 8 ++-- src/routes/post/[instance]/[id]/+page.svelte | 4 +- src/routes/settings/+page.svelte | 2 +- src/routes/u/[name]/+page.svelte | 10 ++--- 23 files changed, 92 insertions(+), 128 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index c929b5da..8c8bc566 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -1,5 +1,5 @@ import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js' -import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' +import { toast } from '$lib/components/ui/toasts/toasts.js' import { DEFAULT_INSTANCE_URL, getClient, instance } from '$lib/lemmy.js' import type { MyUserInfo } from 'lemmy-js-client' import { get, writable } from 'svelte/store' @@ -87,7 +87,7 @@ export async function setUser(jwt: string, inst: string, username: string) { if (!user) { toast({ content: 'Failed to fetch your user. Is your instance down?', - type: ToastType.error, + type: 'error', }) } diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 43a8ac85..5c6b5c94 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -16,7 +16,7 @@ import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte' import Modal from '$lib/components/ui/modal/Modal.svelte' import { getClient } from '$lib/lemmy.js' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import { profile } from '$lib/auth.js' export let node: CommentNodeI @@ -52,13 +52,13 @@ toast({ content: 'Successfully edited comment. You may need to refresh to see changes.', - type: ToastType.success, + type: 'success', }) } catch (err) { toast({ // @ts-ignore i hate this content: err, - type: ToastType.error, + type: 'error', }) } }} diff --git a/src/lib/components/lemmy/comment/CommentActions.svelte b/src/lib/components/lemmy/comment/CommentActions.svelte index 116cf3f7..5c4754f7 100644 --- a/src/lib/components/lemmy/comment/CommentActions.svelte +++ b/src/lib/components/lemmy/comment/CommentActions.svelte @@ -18,7 +18,7 @@ Trash, } from 'svelte-hero-icons' import { getClient, getInstance } from '$lib/lemmy.js' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { 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' import Button from '$lib/components/input/Button.svelte' @@ -50,7 +50,7 @@ toast({ content: error as any, - type: ToastType.error, + type: 'error', }) } } @@ -95,7 +95,9 @@ { navigator.clipboard.writeText( - `${$page.url.origin}/post/${getInstance()}/${comment.post.id}?thread=${comment.comment.path}#${comment.comment.id}` + `${$page.url.origin}/post/${getInstance()}/${ + comment.post.id + }?thread=${comment.comment.path}#${comment.comment.id}` ) }} > @@ -126,12 +128,12 @@ }) toast({ content: 'The comment was deleted.', - type: ToastType.success, + type: 'success', }) } catch (error) { toast({ content: 'Failed to delete comment', - type: ToastType.error, + type: 'error', }) } }} diff --git a/src/lib/components/lemmy/comment/CommentForm.svelte b/src/lib/components/lemmy/comment/CommentForm.svelte index 4cae2c10..97e3a3f2 100644 --- a/src/lib/components/lemmy/comment/CommentForm.svelte +++ b/src/lib/components/lemmy/comment/CommentForm.svelte @@ -4,11 +4,11 @@ import type { CommentResponse } from 'lemmy-js-client' import { getClient } from '$lib/lemmy.js' import { createEventDispatcher } from 'svelte' - import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js' import TextArea from '$lib/components/input/TextArea.svelte' import MultiSelect from '$lib/components/input/MultiSelect.svelte' import Markdown from '$lib/components/markdown/Markdown.svelte' import { profile } from '$lib/auth.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' export let postId: number export let parentId: number | undefined = undefined @@ -40,18 +40,16 @@ dispatch('comment', response) value = '' - addToast( - 'Success', - 'Your comment was added. You may need to refresh to see it.', - ToastType.success - ) + toast({ + content: 'Your comment was added. You may need to refresh to see it.', + type: 'success', + }) } catch (err) { console.error(err) - addToast( - 'Error', - 'Failed to comment. (Sometimes this error appears even when successful.)', - ToastType.error - ) + toast({ + content: err as any, + type: 'error', + }) } loading = false diff --git a/src/lib/components/lemmy/comment/Comments.svelte b/src/lib/components/lemmy/comment/Comments.svelte index ded97b53..8286de99 100644 --- a/src/lib/components/lemmy/comment/Comments.svelte +++ b/src/lib/components/lemmy/comment/Comments.svelte @@ -8,7 +8,7 @@ import { getClient } from '$lib/lemmy.js' import type { CommentView, Post } from 'lemmy-js-client' import { fly } from 'svelte/transition' - import { toast, ToastType } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import { profile } from '$lib/auth.js' export let nodes: CommentNodeI[] @@ -53,7 +53,7 @@ loadingChildren = false toast({ content: 'The API returned no comments.', - type: ToastType.error, + type: 'error', }) return } @@ -77,7 +77,7 @@ console.error(error) toast({ content: `Failed to fetch comments. ${error as any}`, - type: ToastType.error, + type: 'error', }) } } diff --git a/src/lib/components/lemmy/community/CommunityCard.svelte b/src/lib/components/lemmy/community/CommunityCard.svelte index 730a5fcd..83c1515a 100644 --- a/src/lib/components/lemmy/community/CommunityCard.svelte +++ b/src/lib/components/lemmy/community/CommunityCard.svelte @@ -5,7 +5,7 @@ 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 { toast } from '$lib/components/ui/toasts/toasts.js' import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' import RelativeDate from '$lib/components/util/RelativeDate.svelte' import { getClient } from '$lib/lemmy.js' @@ -39,7 +39,7 @@ follow: !subscribed, }) } catch (error) { - addToast('Error', error as any, ToastType.error) + toast({ content: error as any, type: 'error' }) } community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed' @@ -58,7 +58,7 @@ block: !blocked, }) } catch (error) { - addToast('Error', error as any, ToastType.error) + toast({ content: error as any, type: 'error' }) } community_view.blocked = !blocked diff --git a/src/lib/components/lemmy/moderation/BanModal.svelte b/src/lib/components/lemmy/moderation/BanModal.svelte index 20fc1cce..aa63ce81 100644 --- a/src/lib/components/lemmy/moderation/BanModal.svelte +++ b/src/lib/components/lemmy/moderation/BanModal.svelte @@ -6,7 +6,7 @@ import Modal from '$lib/components/ui/modal/Modal.svelte' import type { Community, Person, PersonView } from 'lemmy-js-client' import { getClient } from '$lib/lemmy.js' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import TextInput from '$lib/components/input/TextInput.svelte' import { profile } from '$lib/auth.js' @@ -40,7 +40,7 @@ if (date.toLocaleString('en') == 'Invalid Date') { toast({ content: 'Invalid date. It must be an absolute date.', - type: ToastType.error, + type: 'error', }) loading = false @@ -51,7 +51,7 @@ if (date.getTime() < Date.now()) { toast({ content: 'Invalid date. It is before the current time.', - type: ToastType.error, + type: 'error', }) loading = false @@ -75,14 +75,14 @@ content: `Successfully ${ banned ? 'unbanned' : 'banned' } that user. You may need to refresh to see changes.`, - type: ToastType.success, + type: 'success', }) item.banned = !banned } catch (err) { toast({ content: err as any, - type: ToastType.error, + type: 'error', }) } diff --git a/src/lib/components/lemmy/moderation/ModerationMenu.svelte b/src/lib/components/lemmy/moderation/ModerationMenu.svelte index 461ea8ad..a08577e1 100644 --- a/src/lib/components/lemmy/moderation/ModerationMenu.svelte +++ b/src/lib/components/lemmy/moderation/ModerationMenu.svelte @@ -15,7 +15,7 @@ } from 'svelte-hero-icons' import { Color } from '$lib/ui/colors.js' import { isComment, isPost } from '$lib/lemmy/item.js' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import { profile } from '$lib/auth.js' export let item: PostView | CommentView @@ -42,12 +42,12 @@ content: `Successfully ${ lock ? 'locked' : 'unlocked' } that post. You must refresh to see changes.`, - type: ToastType.success, + type: 'success', }) } catch (err) { toast({ content: err as any, - type: ToastType.error, + type: 'error', }) } @@ -73,12 +73,12 @@ content: `Successfully ${ pinned ? 'pinned' : 'unpinned' } that post. You must refresh to see changes.`, - type: ToastType.success, + type: 'success', }) } catch (err) { toast({ content: err as any, - type: ToastType.error, + type: 'error', }) } diff --git a/src/lib/components/lemmy/moderation/RemoveModal.svelte b/src/lib/components/lemmy/moderation/RemoveModal.svelte index 15a44afd..71a42a9a 100644 --- a/src/lib/components/lemmy/moderation/RemoveModal.svelte +++ b/src/lib/components/lemmy/moderation/RemoveModal.svelte @@ -4,7 +4,7 @@ import Comment from '$lib/components/lemmy/comment/Comment.svelte' import Post from '$lib/components/lemmy/post/Post.svelte' import Modal from '$lib/components/ui/modal/Modal.svelte' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import { getClient } from '$lib/lemmy.js' import { isComment, isPost } from '$lib/lemmy/item.js' import type { CommentView, PostView } from 'lemmy-js-client' @@ -54,12 +54,12 @@ content: `Successfully ${ removed ? 'restored' : 'removed' } that submission.`, - type: ToastType.success, + type: 'success', }) } catch (err) { toast({ content: err as any, - type: ToastType.error, + type: 'error', }) } diff --git a/src/lib/components/lemmy/moderation/ReportModal.svelte b/src/lib/components/lemmy/moderation/ReportModal.svelte index 73eb8c36..e4df5e41 100644 --- a/src/lib/components/lemmy/moderation/ReportModal.svelte +++ b/src/lib/components/lemmy/moderation/ReportModal.svelte @@ -4,7 +4,7 @@ import Comment from '$lib/components/lemmy/comment/Comment.svelte' import Post from '$lib/components/lemmy/post/Post.svelte' import Modal from '$lib/components/ui/modal/Modal.svelte' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import { getClient } from '$lib/lemmy.js' import type { CommentView, PostView } from 'lemmy-js-client' import { profile } from '$lib/auth.js' @@ -42,10 +42,10 @@ open = false toast({ content: 'That submission has been reported.', - type: ToastType.success, + type: 'success', }) } catch (err) { - toast({ content: err as any, type: ToastType.error }) + toast({ content: err as any, type: 'error' }) } loading = false diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index 7225236b..c68b78ff 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -7,7 +7,7 @@ import { userSettings } from '$lib/settings.js' import PostLink from '$lib/components/lemmy/post/PostLink.svelte' import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import Markdown from '$lib/components/markdown/Markdown.svelte' export let post: PostView @@ -125,7 +125,7 @@ post.post.url = e.detail.post.url toast({ content: 'The post was edited successfully.', - type: ToastType.success, + type: 'success', }) }} /> diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index ce62d563..c48384b1 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -20,7 +20,7 @@ import Button from '$lib/components/input/Button.svelte' import MenuButton from '$lib/components/ui/menu/MenuButton.svelte' import { page } from '$app/stores' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import { createEventDispatcher } from 'svelte' import Modal from '$lib/components/ui/modal/Modal.svelte' import PostForm from '$lib/components/lemmy/post/PostForm.svelte' @@ -44,12 +44,12 @@ post.post.deleted = !deleted toast({ content: `That post was ${deleted ? 'restored' : 'deleted'}.`, - type: ToastType.success, + type: 'success', }) } catch (err) { toast({ content: err as any, - type: ToastType.error, + type: 'error', }) } } @@ -72,7 +72,7 @@ toast({ content: error as any, - type: ToastType.error, + type: 'error', }) } } diff --git a/src/lib/components/lemmy/post/PostForm.svelte b/src/lib/components/lemmy/post/PostForm.svelte index 793265d2..afb68f1a 100644 --- a/src/lib/components/lemmy/post/PostForm.svelte +++ b/src/lib/components/lemmy/post/PostForm.svelte @@ -6,7 +6,7 @@ import TextArea from '$lib/components/input/TextArea.svelte' import FileInput from '$lib/components/input/FileInput.svelte' import Button from '$lib/components/input/Button.svelte' - import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' + import { toast } from '$lib/components/ui/toasts/toasts.js' import SearchInput from '$lib/components/input/SearchInput.svelte' import { Check, Icon } from 'svelte-hero-icons' import { profile } from '$lib/auth.js' @@ -77,7 +77,7 @@ async function submit() { if (!data.community && !edit) { toast({ - type: ToastType.warning, + type: 'warning', content: 'You need to set a community.', }) return @@ -123,7 +123,7 @@ dispatcher('submit', post.post_view) } } catch (err) { - toast({ content: err as any, type: ToastType.error }) + toast({ content: err as any, type: 'error' }) } } diff --git a/src/lib/components/ui/toasts/Toast.svelte b/src/lib/components/ui/toasts/Toast.svelte index 5f25792a..e71b83f1 100644 --- a/src/lib/components/ui/toasts/Toast.svelte +++ b/src/lib/components/ui/toasts/Toast.svelte @@ -1,9 +1,5 @@