refactor: toast

This commit is contained in:
codytseng
2025-06-19 23:09:07 +08:00
parent 697b8e4663
commit ef2f8b357d
33 changed files with 127 additions and 477 deletions

View File

@@ -5,9 +5,9 @@ import indexedDb from '@/services/indexed-db.service'
import dayjs from 'dayjs'
import { Event } from 'nostr-tools'
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { toast } from 'sonner'
import { z } from 'zod'
import { useNostr } from './NostrProvider'
import { useToast } from '@/hooks'
type TMuteListContext = {
mutePubkeys: string[]
@@ -32,7 +32,6 @@ export const useMuteList = () => {
}
export function MuteListProvider({ children }: { children: React.ReactNode }) {
const { toast } = useToast()
const {
pubkey: accountPubkey,
muteListEvent,
@@ -111,10 +110,7 @@ export function MuteListProvider({ children }: { children: React.ReactNode }) {
}
const newMuteListDraftEvent = createMuteListDraftEvent(tags, content)
const event = await publish(newMuteListDraftEvent)
toast({
title: 'Mute list updated',
description: 'Your mute list has been updated successfully.'
})
toast.success('Successfully updated mute list')
return event
}

View File

@@ -1,6 +1,5 @@
import LoginDialog from '@/components/LoginDialog'
import { ApplicationDataKey, BIG_RELAY_URLS, ExtendedKind } from '@/constants'
import { useToast } from '@/hooks'
import { createSeenNotificationsAtDraftEvent } from '@/lib/draft-event'
import {
getLatestEvent,
@@ -20,11 +19,12 @@ import * as nip19 from 'nostr-tools/nip19'
import * as nip49 from 'nostr-tools/nip49'
import { createContext, useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from 'sonner'
import { BunkerSigner } from './bunker.signer'
import { Nip07Signer } from './nip-07.signer'
import { NostrConnectionSigner } from './nostrConnection.signer'
import { NpubSigner } from './npub.signer'
import { NsecSigner } from './nsec.signer'
import { NostrConnectionSigner } from './nostrConnection.signer'
type TNostrContext = {
isInitialized: boolean
@@ -80,7 +80,6 @@ export const useNostr = () => {
export function NostrProvider({ children }: { children: React.ReactNode }) {
const { t } = useTranslation()
const { toast } = useToast()
const [account, setAccount] = useState<TAccountPointer | null>(null)
const [nsec, setNsec] = useState<string | null>(null)
const [ncryptsec, setNcryptsec] = useState<string | null>(null)
@@ -379,11 +378,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
}
return login(nip07Signer, { pubkey, signerType: 'nip-07' })
} catch (err) {
toast({
title: 'Login failed',
description: (err as Error).message,
variant: 'destructive'
})
toast.error(t('Login failed') + ': ' + (err as Error).message)
throw err
}
}