feat: switch to a string instead of enum
This commit is contained in:
1 parent
aeb727ae3b
commit
87612d6507
23 files changed
+92
-128
No files matched your search
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
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 { DEFAULT_INSTANCE_URL, getClient, instance } from '$lib/lemmy.js'
|
||||||
import type { MyUserInfo } from 'lemmy-js-client'
|
import type { MyUserInfo } from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
@@ -87,7 +87,7 @@ export async function setUser(jwt: string, inst: string, username: string) {
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Failed to fetch your user. Is your instance down?',
|
content: 'Failed to fetch your user. Is your instance down?',
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
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'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let node: CommentNodeI
|
export let node: CommentNodeI
|
||||||
@@ -52,13 +52,13 @@
|
|||||||
toast({
|
toast({
|
||||||
content:
|
content:
|
||||||
'Successfully edited comment. You may need to refresh to see changes.',
|
'Successfully edited comment. You may need to refresh to see changes.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
// @ts-ignore i hate this
|
// @ts-ignore i hate this
|
||||||
content: err,
|
content: err,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { getClient, getInstance } from '$lib/lemmy.js'
|
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 Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: error as any,
|
content: error as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,9 @@
|
|||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
navigator.clipboard.writeText(
|
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({
|
toast({
|
||||||
content: 'The comment was deleted.',
|
content: 'The comment was deleted.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Failed to delete comment',
|
content: 'Failed to delete comment',
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
import type { CommentResponse } from 'lemmy-js-client'
|
import type { CommentResponse } from 'lemmy-js-client'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
|
||||||
export let postId: number
|
export let postId: number
|
||||||
export let parentId: number | undefined = undefined
|
export let parentId: number | undefined = undefined
|
||||||
@@ -40,18 +40,16 @@
|
|||||||
dispatch('comment', response)
|
dispatch('comment', response)
|
||||||
|
|
||||||
value = ''
|
value = ''
|
||||||
addToast(
|
toast({
|
||||||
'Success',
|
content: 'Your comment was added. You may need to refresh to see it.',
|
||||||
'Your comment was added. You may need to refresh to see it.',
|
type: 'success',
|
||||||
ToastType.success
|
})
|
||||||
)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
addToast(
|
toast({
|
||||||
'Error',
|
content: err as any,
|
||||||
'Failed to comment. (Sometimes this error appears even when successful.)',
|
type: 'error',
|
||||||
ToastType.error
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommentView, Post } from 'lemmy-js-client'
|
import type { CommentView, Post } from 'lemmy-js-client'
|
||||||
import { fly } from 'svelte/transition'
|
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'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
export let nodes: CommentNodeI[]
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
loadingChildren = false
|
loadingChildren = false
|
||||||
toast({
|
toast({
|
||||||
content: 'The API returned no comments.',
|
content: 'The API returned no comments.',
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
toast({
|
toast({
|
||||||
content: `Failed to fetch comments. ${error as any}`,
|
content: `Failed to fetch comments. ${error as any}`,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import StickyCard from '$lib/components/ui/StickyCard.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 FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
follow: !subscribed,
|
follow: !subscribed,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addToast('Error', error as any, ToastType.error)
|
toast({ content: error as any, type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
||||||
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
block: !blocked,
|
block: !blocked,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addToast('Error', error as any, ToastType.error)
|
toast({ content: error as any, type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
||||||
community_view.blocked = !blocked
|
community_view.blocked = !blocked
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
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 TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
if (date.toLocaleString('en') == 'Invalid Date') {
|
if (date.toLocaleString('en') == 'Invalid Date') {
|
||||||
toast({
|
toast({
|
||||||
content: 'Invalid date. It must be an absolute date.',
|
content: 'Invalid date. It must be an absolute date.',
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
if (date.getTime() < Date.now()) {
|
if (date.getTime() < Date.now()) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Invalid date. It is before the current time.',
|
content: 'Invalid date. It is before the current time.',
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
@@ -75,14 +75,14 @@
|
|||||||
content: `Successfully ${
|
content: `Successfully ${
|
||||||
banned ? 'unbanned' : 'banned'
|
banned ? 'unbanned' : 'banned'
|
||||||
} that user. You may need to refresh to see changes.`,
|
} that user. You may need to refresh to see changes.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
item.banned = !banned
|
item.banned = !banned
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import { isComment, isPost } from '$lib/lemmy/item.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'
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
export let item: PostView | CommentView
|
export let item: PostView | CommentView
|
||||||
@@ -42,12 +42,12 @@
|
|||||||
content: `Successfully ${
|
content: `Successfully ${
|
||||||
lock ? 'locked' : 'unlocked'
|
lock ? 'locked' : 'unlocked'
|
||||||
} that post. You must refresh to see changes.`,
|
} that post. You must refresh to see changes.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,12 +73,12 @@
|
|||||||
content: `Successfully ${
|
content: `Successfully ${
|
||||||
pinned ? 'pinned' : 'unpinned'
|
pinned ? 'pinned' : 'unpinned'
|
||||||
} that post. You must refresh to see changes.`,
|
} that post. You must refresh to see changes.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.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 { getClient } from '$lib/lemmy.js'
|
||||||
import { isComment, isPost } from '$lib/lemmy/item.js'
|
import { isComment, isPost } from '$lib/lemmy/item.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
@@ -54,12 +54,12 @@
|
|||||||
content: `Successfully ${
|
content: `Successfully ${
|
||||||
removed ? 'restored' : 'removed'
|
removed ? 'restored' : 'removed'
|
||||||
} that submission.`,
|
} that submission.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.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 { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
@@ -42,10 +42,10 @@
|
|||||||
open = false
|
open = false
|
||||||
toast({
|
toast({
|
||||||
content: 'That submission has been reported.',
|
content: 'That submission has been reported.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({ content: err as any, type: ToastType.error })
|
toast({ content: err as any, type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
||||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.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'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
|
|
||||||
export let post: PostView
|
export let post: PostView
|
||||||
@@ -125,7 +125,7 @@
|
|||||||
post.post.url = e.detail.post.url
|
post.post.url = e.detail.post.url
|
||||||
toast({
|
toast({
|
||||||
content: 'The post was edited successfully.',
|
content: 'The post was edited successfully.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
import { page } from '$app/stores'
|
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 { createEventDispatcher } from 'svelte'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
||||||
@@ -44,12 +44,12 @@
|
|||||||
post.post.deleted = !deleted
|
post.post.deleted = !deleted
|
||||||
toast({
|
toast({
|
||||||
content: `That post was ${deleted ? 'restored' : 'deleted'}.`,
|
content: `That post was ${deleted ? 'restored' : 'deleted'}.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: error as any,
|
content: error as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
import FileInput from '$lib/components/input/FileInput.svelte'
|
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||||
import Button from '$lib/components/input/Button.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 SearchInput from '$lib/components/input/SearchInput.svelte'
|
||||||
import { Check, Icon } from 'svelte-hero-icons'
|
import { Check, Icon } from 'svelte-hero-icons'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
async function submit() {
|
async function submit() {
|
||||||
if (!data.community && !edit) {
|
if (!data.community && !edit) {
|
||||||
toast({
|
toast({
|
||||||
type: ToastType.warning,
|
type: 'warning',
|
||||||
content: 'You need to set a community.',
|
content: 'You need to set a community.',
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
dispatcher('submit', post.post_view)
|
dispatcher('submit', post.post_view)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({ content: err as any, type: ToastType.error })
|
toast({ content: err as any, type: 'error' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { type Toast, toasts } from '$lib/components/ui/toasts/toasts'
|
||||||
ToastType,
|
|
||||||
type Toast,
|
|
||||||
toasts,
|
|
||||||
} from '$lib/components/ui/toasts/toasts'
|
|
||||||
import {
|
import {
|
||||||
InformationCircle,
|
InformationCircle,
|
||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
@@ -29,13 +25,13 @@
|
|||||||
size="20"
|
size="20"
|
||||||
solid
|
solid
|
||||||
class="relative m-2 ml-4 flex-shrink-0"
|
class="relative m-2 ml-4 flex-shrink-0"
|
||||||
src={toast.type == ToastType.info
|
src={toast.type == 'info'
|
||||||
? InformationCircle
|
? InformationCircle
|
||||||
: toast.type == ToastType.success
|
: toast.type == 'success'
|
||||||
? CheckCircle
|
? CheckCircle
|
||||||
: toast.type == ToastType.warning
|
: toast.type == 'warning'
|
||||||
? ExclamationTriangle
|
? ExclamationTriangle
|
||||||
: toast.type == ToastType.error
|
: toast.type == 'error'
|
||||||
? ExclamationCircle
|
? ExclamationCircle
|
||||||
: ExclamationCircle}
|
: ExclamationCircle}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
export enum ToastType {
|
type ToastType = keyof typeof toastColors
|
||||||
'error' = 'bg-red-500 text-white border border-red-600',
|
|
||||||
'warning' = 'bg-yellow-400 text-black border border-yellow-500',
|
const toastColors = {
|
||||||
'success' = 'bg-green-400 text-black border border-green-500',
|
error: 'bg-red-500 text-white border border-red-600',
|
||||||
'info' = 'dark:bg-zinc-900 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
|
warning: 'bg-yellow-400 text-black border border-yellow-500',
|
||||||
|
success: 'bg-green-400 text-black border border-green-500',
|
||||||
|
info: 'dark:bg-zinc-900 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Toast {
|
export interface Toast {
|
||||||
@@ -19,7 +21,7 @@ export const toasts = writable<Toast[]>([])
|
|||||||
export function toast({
|
export function toast({
|
||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
type = ToastType.info,
|
type = 'info',
|
||||||
duration = 5000,
|
duration = 5000,
|
||||||
}: {
|
}: {
|
||||||
title?: string
|
title?: string
|
||||||
@@ -47,32 +49,3 @@ export function toast({
|
|||||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||||
}, duration)
|
}, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use @function toast
|
|
||||||
*/
|
|
||||||
export function addToast(
|
|
||||||
title: string | undefined,
|
|
||||||
content: string,
|
|
||||||
type: ToastType
|
|
||||||
) {
|
|
||||||
let id = 0
|
|
||||||
|
|
||||||
toasts.update((toasts) => {
|
|
||||||
id = Math.floor(Math.random() * 10000)
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: id,
|
|
||||||
content: content,
|
|
||||||
title: title,
|
|
||||||
type: type,
|
|
||||||
},
|
|
||||||
...toasts,
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
|
||||||
}, 5000)
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
import EditableList from '$lib/components/ui/list/EditableList.svelte'
|
import EditableList from '$lib/components/ui/list/EditableList.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import {
|
import {
|
||||||
LINKED_INSTANCE_URL,
|
LINKED_INSTANCE_URL,
|
||||||
instance,
|
instance,
|
||||||
@@ -32,12 +32,12 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: 'Changed guest instance.',
|
content: 'Changed guest instance.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Failed to contact that instance URL. Is it down?',
|
content: 'Failed to contact that instance URL. Is it down?',
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommunityView } from 'lemmy-js-client'
|
import type { CommunityView } from 'lemmy-js-client'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
|
||||||
export let community: CommunityView
|
export let community: CommunityView
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
subscribing = false
|
subscribing = false
|
||||||
return res
|
return res
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addToast('Error', 'Failed to subscribe to community', ToastType.error)
|
toast({ content: 'Failed to subscribe to community', type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribing = false
|
subscribing = false
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
@@ -16,6 +15,7 @@
|
|||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
|
import { ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
|
||||||
export let item: CommentReplyView | PersonMentionView | PrivateMessageView
|
export let item: CommentReplyView | PersonMentionView | PrivateMessageView
|
||||||
export let read: boolean
|
export let read: boolean
|
||||||
@@ -44,11 +44,10 @@
|
|||||||
recipient_id: message.creator.id,
|
recipient_id: message.creator.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
addToast(
|
toast({
|
||||||
'Success',
|
content: 'Successfully replied to that message.',
|
||||||
'Successfully replied to that message.',
|
type: 'success',
|
||||||
ToastType.success
|
})
|
||||||
)
|
|
||||||
|
|
||||||
replying = false
|
replying = false
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@
|
|||||||
replaceState: true,
|
replaceState: true,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addToast('Error', error as any, ToastType.error)
|
toast({ content: error as any, type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { profileData, setUser } from '$lib/auth.js'
|
import { setUser } from '$lib/auth.js'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import {
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
ToastType,
|
|
||||||
addToast,
|
|
||||||
toast,
|
|
||||||
} from '$lib/components/ui/toasts/toasts.js'
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_INSTANCE_URL,
|
DEFAULT_INSTANCE_URL,
|
||||||
LINKED_INSTANCE_URL,
|
LINKED_INSTANCE_URL,
|
||||||
@@ -42,7 +38,7 @@
|
|||||||
if (response?.jwt) {
|
if (response?.jwt) {
|
||||||
await setUser(response.jwt, data.instance, data.username)
|
await setUser(response.jwt, data.instance, data.username)
|
||||||
|
|
||||||
toast({ content: 'Successfully logged in.', type: ToastType.success })
|
toast({ content: 'Successfully logged in.', type: 'success' })
|
||||||
goto('/')
|
goto('/')
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid credentials')
|
throw new Error('Invalid credentials')
|
||||||
@@ -50,7 +46,7 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
content: error as any,
|
content: error as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
data.loading = false
|
data.loading = false
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.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 { getClient } from '$lib/lemmy.js'
|
||||||
import { isCommentReport, isPostReport } from '$lib/lemmy/item.js'
|
import { isCommentReport, isPostReport } from '$lib/lemmy/item.js'
|
||||||
import type {
|
import type {
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
} else if (isPostReport(item)) {
|
} else if (isPostReport(item)) {
|
||||||
await getClient().resolvePostReport({
|
await getClient().resolvePostReport({
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
resolved = !resolved
|
resolved = !resolved
|
||||||
toast({
|
toast({
|
||||||
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
import PostLink from '$lib/components/lemmy/post/PostLink.svelte'
|
||||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.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 type { CommentSortType } from 'lemmy-js-client'
|
import type { CommentSortType } from 'lemmy-js-client'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
@@ -145,7 +145,7 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: 'The post was edited successfully.',
|
content: 'The post was edited successfully.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
} from '$lib/lemmy.js'
|
} from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
import Button from '$lib/components/input/Button.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 Setting from './Setting.svelte'
|
import Setting from './Setting.svelte'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import { isBlocked } from '$lib/lemmy/user.js'
|
import { isBlocked } from '$lib/lemmy/user.js'
|
||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: `Successfully ${blocked ? 'unblocked' : 'blocked'} that user.`,
|
content: `Successfully ${blocked ? 'unblocked' : 'blocked'} that user.`,
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
goto($page.url, {
|
goto($page.url, {
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
blocking = false
|
blocking = false
|
||||||
@@ -87,14 +87,14 @@
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
content: 'Successfully sent that person a message.',
|
content: 'Successfully sent that person a message.',
|
||||||
type: ToastType.success,
|
type: 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
messaging = false
|
messaging = false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
content: err as any,
|
content: err as any,
|
||||||
type: ToastType.error,
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user