Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
onghwan committed Dec 9, 2024
1 parent 70cb365 commit a90416b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
20 changes: 6 additions & 14 deletions packages/core-mobile/app/new/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
import { useRouter } from 'expo-router'
import { View, Button } from '@avalabs/k2-alpine'
import React from 'react'
import { showToast } from 'new/utils/toast'
import { showNotificationAlert, showSnackbar } from 'new/utils/toast'

export default function Index(): JSX.Element {
const { navigate } = useRouter()

const handleSignIn = (): void => {
navigate('/portfolio/')

showToast({
toastType: 'snackbar',
content: {
message: 'Welcome back!'
}
})
showSnackbar('Welcome back!')
}

const handleSignUp = (): void => {
navigate('/signup/')

showToast({
toastType: 'notificationAlert',
content: {
type: 'success',
title: 'Sign up',
message: 'Sign up button pressed'
}
showNotificationAlert({
type: 'success',
title: 'Sign up',
message: 'Sign up button pressed'
})
}

Expand Down
26 changes: 24 additions & 2 deletions packages/core-mobile/app/new/utils/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type NotificationAlertToast = {
content: { type: NotificationAlertType; title: string; message?: string }
}

export function showToast(props: SnackbarToast | NotificationAlertToast): void {
function showToast(props: SnackbarToast | NotificationAlertToast): void {
global.toast?.hideAll()

const _toastId = props.toastId ?? uuid()
Expand All @@ -78,6 +78,28 @@ export function showToast(props: SnackbarToast | NotificationAlertToast): void {
})
}

export function dismissToast(toastId: string): void {
function dismissToast(toastId: string): void {
global?.toast?.hide(toastId)
}

export function showSnackbar(message: string): void {
showToast({
toastType: 'snackbar',
content: { message }
})
}

export function showNotificationAlert({
type,
title,
message
}: {
type: NotificationAlertType
title: string
message?: string
}): void {
showToast({
toastType: 'notificationAlert',
content: { type, title, message }
})
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26640,7 +26640,7 @@ react-native-webview@ava-labs/react-native-webview:
peerDependencies:
react: "*"
react-native: "*"
checksum: 6e268fad7aa8b8e56fd28cc95f94f35a33fdac4cec0085ae71a766d092760e3f9af35218706113ff7ae99a74baabc5112d32005dce9e66bdf4fda676fad9aa4e
checksum: a187edd718e1ea3a6b1e5da167744e6ee324bc3c3e492bcb0a9d028ab68a82907f053f37c23aa4229d6a9091541cee3c73549c3c850056e4cf5eb5b3cb2c9ffc
languageName: node
linkType: hard

Expand Down

0 comments on commit a90416b

Please sign in to comment.