Fix style of the read now success toast

This commit is contained in:
Jackson Harper
2024-02-29 18:41:52 +08:00
parent a74377556b
commit 6798a06d15
2 changed files with 59 additions and 21 deletions

View File

@ -42,7 +42,11 @@ import { LibraryHeader, MultiSelectMode } from './LibraryHeader'
import { UploadModal } from '../UploadModal'
import { BulkAction } from '../../../lib/networking/mutations/bulkActionMutation'
import { bulkActionMutation } from '../../../lib/networking/mutations/bulkActionMutation'
import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers'
import {
showErrorToast,
showSuccessToast,
showSuccessToastWithAction,
} from '../../../lib/toastHelpers'
import { SetPageLabelsModalPresenter } from '../article/SetLabelsModalPresenter'
import { NotebookPresenter } from '../article/NotebookPresenter'
import { saveUrlMutation } from '../../../lib/networking/mutations/saveUrlMutation'
@ -797,26 +801,10 @@ export function HomeFeedContainer(): JSX.Element {
) => {
const result = await saveUrlMutation(link, timezone, locale)
if (result) {
toast(
() => (
<Box>
Link Saved
<span style={{ padding: '16px' }} />
<Button
style="ctaDarkYellow"
autoFocus
onClick={() => {
window.location.href = `/article?url=${encodeURIComponent(
link
)}`
}}
>
Read Now
</Button>
</Box>
),
{ position: 'bottom-right' }
)
showSuccessToastWithAction('Link saved', 'Read now', async () => {
window.location.href = `/article?url=${encodeURIComponent(link)}`
return Promise.resolve()
})
const id = result.url?.match(/[^/]+$/)?.[0] ?? ''
performActionOnItem('refresh', undefined as unknown as any)
} else {

View File

@ -107,6 +107,46 @@ const showToastWithUndo = (
)
}
const showToastWithAction = (
message: string,
background: string,
actionName: string,
action: () => Promise<void>,
options?: ToastOptions
) => {
return toast(
({ id }) => (
<FullWidthContainer alignment="center">
<CheckCircle size={24} color="white" />
<MessageContainer>{message}</MessageContainer>
<HStack distribution="end" css={{ marginLeft: 16 }}>
<Button
style="ctaLightGray"
onClick={(event) => {
event.preventDefault()
toast.dismiss(id)
;(async () => {
await action()
})()
}}
>
{actionName}
</Button>
</HStack>
</FullWidthContainer>
),
{
style: {
...toastStyles,
background: background,
},
duration: 3500,
...options,
}
)
}
export const showSuccessToast = (message: string, options?: ToastOptions) => {
return showToast(message, '#55B938', 'success', {
position: 'bottom-right',
@ -129,3 +169,13 @@ export const showSuccessToastWithUndo = (
position: 'bottom-right',
})
}
export const showSuccessToastWithAction = (
message: string,
actionName: string,
action: () => Promise<void>
) => {
return showToastWithAction(message, '#55B938', actionName, action, {
position: 'bottom-right',
})
}