Add toasts
This commit is contained in:
@@ -9,6 +9,7 @@ import {type Shadow} from '#/state/cache/post-shadow'
|
|||||||
import {useBookmarkMutation} from '#/state/queries/bookmarks/useBookmarkMutation'
|
import {useBookmarkMutation} from '#/state/queries/bookmarks/useBookmarkMutation'
|
||||||
import {useTheme} from '#/alf'
|
import {useTheme} from '#/alf'
|
||||||
import {Bookmark, BookmarkFilled} from '#/components/icons/Bookmark'
|
import {Bookmark, BookmarkFilled} from '#/components/icons/Bookmark'
|
||||||
|
import * as toast from '#/components/Toast'
|
||||||
import {PostControlButton, PostControlButtonIcon} from './PostControlButton'
|
import {PostControlButton, PostControlButtonIcon} from './PostControlButton'
|
||||||
|
|
||||||
export const BookmarkButton = memo(function BookmarkButton({
|
export const BookmarkButton = memo(function BookmarkButton({
|
||||||
@@ -33,21 +34,24 @@ export const BookmarkButton = memo(function BookmarkButton({
|
|||||||
action: 'delete',
|
action: 'delete',
|
||||||
uri,
|
uri,
|
||||||
})
|
})
|
||||||
// TODO toast
|
toast.show(_(msg`Removed from saved posts`))
|
||||||
} else {
|
} else {
|
||||||
await bookmark({
|
await bookmark({
|
||||||
action: 'create',
|
action: 'create',
|
||||||
uri,
|
uri,
|
||||||
cid,
|
cid,
|
||||||
})
|
})
|
||||||
// TODO toast
|
toast.show(_(msg`Post saved`), {
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
const {raw, clean} = cleanError(e)
|
const {raw, clean} = cleanError(e)
|
||||||
console.log(clean || raw || e)
|
toast.show(clean || raw || e, {
|
||||||
// TODO toast
|
type: 'error',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [uri, cid, isBookmarked, bookmark, cleanError])
|
}, [_, uri, cid, isBookmarked, bookmark, cleanError])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PostControlButton
|
<PostControlButton
|
||||||
@@ -55,8 +59,8 @@ export const BookmarkButton = memo(function BookmarkButton({
|
|||||||
big={big}
|
big={big}
|
||||||
label={
|
label={
|
||||||
isBookmarked
|
isBookmarked
|
||||||
? _(msg`Remove this post from your bookmarks`)
|
? _(msg`Remove from saved posts`)
|
||||||
: _(msg`Save this post to your bookmarks`)
|
: _(msg`Add to saved posts`)
|
||||||
}
|
}
|
||||||
onPress={onHandlePress}>
|
onPress={onHandlePress}>
|
||||||
<PostControlButtonIcon
|
<PostControlButtonIcon
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import {CircleQuestion_Stroke2_Corner2_Rounded as QuestionIcon} from '#/componen
|
|||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
import {ListFooter} from '#/components/Lists'
|
import {ListFooter} from '#/components/Lists'
|
||||||
import * as Skele from '#/components/Skeleton'
|
import * as Skele from '#/components/Skeleton'
|
||||||
|
import * as toast from '#/components/Toast'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
type Props = NativeStackScreenProps<CommonNavigatorParams, 'Bookmarks'>
|
type Props = NativeStackScreenProps<CommonNavigatorParams, 'Bookmarks'>
|
||||||
@@ -114,7 +115,6 @@ function BookmarksInner() {
|
|||||||
const onEndReached = useCallback(async () => {
|
const onEndReached = useCallback(async () => {
|
||||||
if (isFetchingNextPage || !hasNextPage || error) return
|
if (isFetchingNextPage || !hasNextPage || error) return
|
||||||
try {
|
try {
|
||||||
console.log('Fetching more bookmarks...')
|
|
||||||
await fetchNextPage()
|
await fetchNextPage()
|
||||||
} catch {}
|
} catch {}
|
||||||
}, [isFetchingNextPage, hasNextPage, error, fetchNextPage])
|
}, [isFetchingNextPage, hasNextPage, error, fetchNextPage])
|
||||||
@@ -220,10 +220,11 @@ function BookmarkNotFound({
|
|||||||
try {
|
try {
|
||||||
setRemoved(true)
|
setRemoved(true)
|
||||||
await bookmark({action: 'delete', uri: post.uri})
|
await bookmark({action: 'delete', uri: post.uri})
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
const {raw, clean} = cleanError(e)
|
const {raw, clean} = cleanError(e)
|
||||||
console.log(clean || raw || e)
|
toast.show(clean || raw || e, {
|
||||||
// TODO toast
|
type: 'error',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [post.uri, bookmark, cleanError])
|
}, [post.uri, bookmark, cleanError])
|
||||||
|
|
||||||
@@ -260,7 +261,7 @@ function BookmarkNotFound({
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Button
|
<Button
|
||||||
label={_(msg`Remove this post from your bookmarks`)}
|
label={_(msg`Remove from saved posts`)}
|
||||||
size="tiny"
|
size="tiny"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onPress={remove}>
|
onPress={remove}>
|
||||||
|
|||||||
Reference in New Issue
Block a user