Remove legacy Toast wrapper
Deletes src/view/com/util/Toast and its LegacyToastType union. The two
remaining callers (UserAddRemoveLists and PostFeedErrorMessage) and the
Storybook deprecated-API demo are migrated to the canonical
`#/components/Toast` API.
Also picks up two prettier fixes in Toast/index.{tsx,web.tsx} from the
previous commit.
This commit is contained in:
@@ -107,7 +107,8 @@ export function promise<T>(
|
||||
{
|
||||
...options,
|
||||
id,
|
||||
duration: type === 'pending' ? Infinity : (options?.duration ?? DURATION),
|
||||
duration:
|
||||
type === 'pending' ? Infinity : (options?.duration ?? DURATION),
|
||||
dismissible: type === 'pending' ? false : options?.dismissible,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -108,7 +108,8 @@ export function promise<T>(
|
||||
...options,
|
||||
unstyled: true, // required on web
|
||||
id,
|
||||
duration: type === 'pending' ? Infinity : (options?.duration ?? DURATION),
|
||||
duration:
|
||||
type === 'pending' ? Infinity : (options?.duration ?? DURATION),
|
||||
dismissible: type === 'pending' ? false : options?.dismissible,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -24,11 +24,11 @@ import {
|
||||
useListMembershipRemoveMutation,
|
||||
} from '#/state/queries/list-memberships'
|
||||
import {useSession} from '#/state/session'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {IS_ANDROID, IS_WEB, IS_WEB_MOBILE} from '#/env'
|
||||
import {MyLists} from '../lists/MyLists'
|
||||
import {Button} from '../util/forms/Button'
|
||||
import {Text} from '../util/text/Text'
|
||||
import * as Toast from '../util/Toast'
|
||||
import {UserAvatar} from '../util/UserAvatar'
|
||||
|
||||
export const snapPoints = ['fullscreen']
|
||||
@@ -172,7 +172,7 @@ function ListItem({
|
||||
onRemove?.(list.uri)
|
||||
}
|
||||
} catch (e) {
|
||||
Toast.show(cleanError(e), 'xmark')
|
||||
Toast.show(cleanError(e), {type: 'error'})
|
||||
} finally {
|
||||
setIsProcessing(false)
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ import {type FeedDescriptor} from '#/state/queries/post-feed'
|
||||
import {useRemoveFeedMutation} from '#/state/queries/preferences'
|
||||
import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning'
|
||||
import * as Prompt from '#/components/Prompt'
|
||||
import * as Toast from '#/components/Toast'
|
||||
import {EmptyState} from '../util/EmptyState'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import {Button} from '../util/forms/Button'
|
||||
import {Text} from '../util/text/Text'
|
||||
import * as Toast from '../util/Toast'
|
||||
|
||||
export enum KnownError {
|
||||
Block = 'Block',
|
||||
@@ -152,7 +152,7 @@ function FeedgenErrorMessage({
|
||||
_l(
|
||||
msgLingui`There was an issue removing this feed. Please check your internet connection and try again.`,
|
||||
),
|
||||
'exclamation-circle',
|
||||
{type: 'warning'},
|
||||
)
|
||||
logger.error('Failed to remove feed', {message: err})
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import * as toast from '#/components/Toast'
|
||||
import {type ToastType} from '#/components/Toast/types'
|
||||
|
||||
/**
|
||||
* @deprecated use {@link ToastType} and {@link toast} instead
|
||||
*/
|
||||
export type LegacyToastType =
|
||||
| 'xmark'
|
||||
| 'exclamation-circle'
|
||||
| 'check'
|
||||
| 'clipboard-check'
|
||||
| 'circle-exclamation'
|
||||
|
||||
export const convertLegacyToastType = (
|
||||
type: ToastType | LegacyToastType,
|
||||
): ToastType => {
|
||||
switch (type) {
|
||||
// these ones are fine
|
||||
case 'default':
|
||||
case 'success':
|
||||
case 'error':
|
||||
case 'warning':
|
||||
case 'info':
|
||||
case 'pending':
|
||||
return type
|
||||
// legacy ones need conversion
|
||||
case 'xmark':
|
||||
return 'error'
|
||||
case 'exclamation-circle':
|
||||
return 'warning'
|
||||
case 'check':
|
||||
return 'success'
|
||||
case 'clipboard-check':
|
||||
return 'success'
|
||||
case 'circle-exclamation':
|
||||
return 'warning'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link toast} instead
|
||||
*/
|
||||
export function show(
|
||||
message: string,
|
||||
type: ToastType | LegacyToastType = 'default',
|
||||
): void {
|
||||
const convertedType = convertLegacyToastType(type)
|
||||
toast.show(message, {type: convertedType})
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import {Pressable, View} from 'react-native'
|
||||
|
||||
import {show as deprecatedShow} from '#/view/com/util/Toast'
|
||||
import {atoms as a} from '#/alf'
|
||||
import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe'
|
||||
import * as Toast from '#/components/Toast'
|
||||
@@ -134,20 +133,6 @@ export function Toasts() {
|
||||
}>
|
||||
<DefaultToast content="This is an error toast :(" type="error" />
|
||||
</Pressable>
|
||||
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
onPress={() =>
|
||||
deprecatedShow(
|
||||
`This is a test of the deprecated API`,
|
||||
'exclamation-circle',
|
||||
)
|
||||
}>
|
||||
<DefaultToast
|
||||
content="This is a test of the deprecated API"
|
||||
type="warning"
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user