From 6798a06d15afda40d89db3e36e762e7397ef69b2 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 29 Feb 2024 18:41:52 +0800 Subject: [PATCH 1/2] Fix style of the read now success toast --- .../templates/homeFeed/HomeFeedContainer.tsx | 30 ++++------- packages/web/lib/toastHelpers.tsx | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx index f44265e41..10a77911a 100644 --- a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx +++ b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx @@ -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( - () => ( - - Link Saved - - - - ), - { 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 { diff --git a/packages/web/lib/toastHelpers.tsx b/packages/web/lib/toastHelpers.tsx index 867880a41..18c92a75c 100644 --- a/packages/web/lib/toastHelpers.tsx +++ b/packages/web/lib/toastHelpers.tsx @@ -107,6 +107,46 @@ const showToastWithUndo = ( ) } +const showToastWithAction = ( + message: string, + background: string, + actionName: string, + action: () => Promise, + options?: ToastOptions +) => { + return toast( + ({ id }) => ( + + + {message} + + + + + ), + { + 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 +) => { + return showToastWithAction(message, '#55B938', actionName, action, { + position: 'bottom-right', + }) +} From e272463620b4a7a3c1bf326fd43b7bab2be66d57 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 29 Feb 2024 18:42:21 +0800 Subject: [PATCH 2/2] Remove unused imports --- .../web/components/templates/homeFeed/HomeFeedContainer.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx index 10a77911a..ef186a759 100644 --- a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx +++ b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx @@ -2,7 +2,7 @@ import { Action, createAction, useKBar, useRegisterActions } from 'kbar' import debounce from 'lodash/debounce' import { useRouter } from 'next/router' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import toast, { Toaster } from 'react-hot-toast' +import { Toaster } from 'react-hot-toast' import TopBarProgress from 'react-topbar-progress-indicator' import { useFetchMore } from '../../../lib/hooks/useFetchMoreScroll' import { usePersistedState } from '../../../lib/hooks/usePersistedState' @@ -53,8 +53,6 @@ import { saveUrlMutation } from '../../../lib/networking/mutations/saveUrlMutati import { articleQuery } from '../../../lib/networking/queries/useGetArticleQuery' import { PinnedButtons } from './PinnedButtons' import { PinnedSearch } from '../../../pages/settings/pinned-searches' -import { ErrorSlothIcon } from '../../elements/icons/ErrorSlothIcon' -import { DEFAULT_HEADER_HEIGHT } from './HeaderSpacer' import { FetchItemsError } from './FetchItemsError' import { TLDRLayout } from './TLDRLayout'