Refactor app passwords to use react-query (#1932)

This commit is contained in:
Paul Frazee 2023-11-16 11:11:56 -08:00 committed by GitHub
parent 310a7eaca7
commit 9f7a162a96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 177 additions and 115 deletions

View file

@ -1,6 +1,7 @@
import RootSiblings from 'react-native-root-siblings'
import React from 'react'
import {Animated, StyleSheet, View} from 'react-native'
import {Props as FontAwesomeProps} from '@fortawesome/react-native-fontawesome'
import {Text} from './text/Text'
import {colors} from 'lib/styles'
import {useTheme} from 'lib/ThemeContext'
@ -9,7 +10,10 @@ import {useAnimatedValue} from 'lib/hooks/useAnimatedValue'
const TIMEOUT = 4e3
export function show(message: string) {
export function show(
message: string,
_icon: FontAwesomeProps['icon'] = 'check',
) {
const item = new RootSiblings(<Toast message={message} />)
setTimeout(() => {
item.destroy()

View file

@ -7,12 +7,14 @@ import {StyleSheet, Text, View} from 'react-native'
import {
FontAwesomeIcon,
FontAwesomeIconStyle,
Props as FontAwesomeProps,
} from '@fortawesome/react-native-fontawesome'
const DURATION = 3500
interface ActiveToast {
text: string
icon: FontAwesomeProps['icon']
}
type GlobalSetActiveToast = (_activeToast: ActiveToast | undefined) => void
@ -36,7 +38,7 @@ export const ToastContainer: React.FC<ToastContainerProps> = ({}) => {
{activeToast && (
<View style={styles.container}>
<FontAwesomeIcon
icon="check"
icon={activeToast.icon}
size={24}
style={styles.icon as FontAwesomeIconStyle}
/>
@ -49,11 +51,12 @@ export const ToastContainer: React.FC<ToastContainerProps> = ({}) => {
// methods
// =
export function show(text: string) {
export function show(text: string, icon: FontAwesomeProps['icon'] = 'check') {
if (toastTimeout) {
clearTimeout(toastTimeout)
}
globalSetActiveToast?.({text})
globalSetActiveToast?.({text, icon})
toastTimeout = setTimeout(() => {
globalSetActiveToast?.(undefined)
}, DURATION)