From b4d0cdaef116f0522ce1a766115c99862f532d7a Mon Sep 17 00:00:00 2001 From: Alina Date: Sat, 13 Apr 2024 23:50:33 +0400 Subject: [PATCH] chore: remove toast usage --- src/__tests__/setupTests.ts | 9 -------- src/popup/app/Popup.tsx | 4 ++-- src/popup/entities/tab/index.ts | 7 +----- .../ui/SelectDictionaryVariant.tsx | 11 ++-------- .../SelectLanguages/ui/SelectLanguages.tsx | 18 ++++++++------- .../features/note/DeleteNote/ui/index.tsx | 6 ++--- src/popup/features/note/EditNote/ui/index.tsx | 22 +++++++++---------- src/popup/widgets/note/NoteList.tsx | 1 - 8 files changed, 28 insertions(+), 50 deletions(-) diff --git a/src/__tests__/setupTests.ts b/src/__tests__/setupTests.ts index 2215572..7cb7941 100644 --- a/src/__tests__/setupTests.ts +++ b/src/__tests__/setupTests.ts @@ -1,12 +1,3 @@ -import { vi } from 'vitest' - -import * as toastModule from '@popup/shared/ui/Toast' -import { getErrorToastMock } from '@popup/shared/ui/Toast/helpers/__mock__/getErrorToast' -import { addToastMock } from '@popup/shared/ui/Toast/model/__mock__/store' - import { chromeMock } from '@shared/shared/browser/__mocks__/chrome' global.chrome = chromeMock - -vi.spyOn(toastModule, 'getErrorToast').mockImplementation(getErrorToastMock) -vi.spyOn(toastModule, 'addToast').mockImplementation(addToastMock) diff --git a/src/popup/app/Popup.tsx b/src/popup/app/Popup.tsx index 66caaa0..c9c79cc 100644 --- a/src/popup/app/Popup.tsx +++ b/src/popup/app/Popup.tsx @@ -1,14 +1,14 @@ import { NoteList } from '@popup/widgets/note/NoteList' import { Settings } from '@popup/widgets/settings' -import { Toasts } from '@popup/shared/ui/Toast' +import { ErrorAlert } from '@popup/entities/error' export const Popup = () => { return (
+ -
) } diff --git a/src/popup/entities/tab/index.ts b/src/popup/entities/tab/index.ts index c7073cb..debb5fb 100644 --- a/src/popup/entities/tab/index.ts +++ b/src/popup/entities/tab/index.ts @@ -1,7 +1,6 @@ import { atom, onMount, task } from 'nanostores' import { browser } from '@popup/shared/browser' -import { addToast, getErrorToast } from '@popup/shared/ui/Toast' import { TTab } from '@shared/shared/browser/tabs' @@ -11,10 +10,6 @@ onMount($activeTab, () => { task(async () => { const getResult = await browser.tabs.getActiveTab() - if (getResult.data) { - $activeTab.set(getResult.data) - } else { - addToast(getErrorToast(getResult.error)) - } + getResult.data && $activeTab.set(getResult.data) }) }) diff --git a/src/popup/features/dictionary/SelectDictionaryVariant/ui/SelectDictionaryVariant.tsx b/src/popup/features/dictionary/SelectDictionaryVariant/ui/SelectDictionaryVariant.tsx index b85dc8e..08cecdb 100644 --- a/src/popup/features/dictionary/SelectDictionaryVariant/ui/SelectDictionaryVariant.tsx +++ b/src/popup/features/dictionary/SelectDictionaryVariant/ui/SelectDictionaryVariant.tsx @@ -2,7 +2,6 @@ import { DictionaryCard } from '@popup/entities/dictionary' import { browser } from '@popup/shared/browser' import { Button } from '@popup/shared/ui/Button' -import { addToast } from '@popup/shared/ui/Toast' import { IDictionaryWithVariants, @@ -18,14 +17,8 @@ interface GroupProps { } export const SelectDictionaryVariant = ({ dictionary, lang }: GroupProps) => { - const onSelectVariant = async (variant: string) => { - const result = await dictionaryStore.selectVariant( - lang, - dictionary.id, - variant, - ) - - result.error && addToast({ title: result.error.type, type: 'error' }) + const onSelectVariant = (variant: string) => { + dictionaryStore.selectVariant(lang, dictionary.id, variant) } return ( diff --git a/src/popup/features/language/SelectLanguages/ui/SelectLanguages.tsx b/src/popup/features/language/SelectLanguages/ui/SelectLanguages.tsx index 6d4b80f..32766e6 100644 --- a/src/popup/features/language/SelectLanguages/ui/SelectLanguages.tsx +++ b/src/popup/features/language/SelectLanguages/ui/SelectLanguages.tsx @@ -1,12 +1,15 @@ import { useStore } from '@nanostores/preact' import { JSXInternal } from 'node_modules/preact/src/jsx' +import { useState } from 'preact/hooks' import { browser } from '@popup/shared/browser' import { Button } from '@popup/shared/ui/Button' -import { addToast, getErrorToast } from '@popup/shared/ui/Toast' +import { Result } from '@popup/shared/ui/Result' import { ILanguage } from '@shared/entities/language' +import { TResult } from '@shared/shared/libs/operationResult' + import { checkIsSelected, localStore, @@ -20,6 +23,7 @@ interface Props { } export const SelectLanguages = ({ languages }: Props) => { + const [result, setResult] = useState(null) useStore(localStore.languageCodes) const onSubmit: JSXInternal.SubmitEventHandler = async ( @@ -27,21 +31,17 @@ export const SelectLanguages = ({ languages }: Props) => { ) => { e.preventDefault() const result = await syncLocalStoreWithLanguageStore() - result.data && - addToast({ - type: 'success', - title: result.data, - }) - result.error && addToast(getErrorToast(result.error)) + setResult(result) } return (
-

+

{browser.i18n.getMessage('SELECT_LANGUAGES_FORM_TITLE')}

@@ -63,6 +63,8 @@ export const SelectLanguages = ({ languages }: Props) => { ))} + +