update js
This commit is contained in:
+13
-20
@@ -1,7 +1,6 @@
|
||||
import React from 'react'
|
||||
|
||||
import {SharedPrefs} from '../../expo-bluesky-swiss-army'
|
||||
import {BackgroundNotifications} from '../index'
|
||||
import {BackgroundNotificationHandlerPreferences} from './types'
|
||||
|
||||
interface BackgroundNotificationPreferencesContext {
|
||||
@@ -30,31 +29,25 @@ export function BackgroundNotificationPreferencesProvider({
|
||||
|
||||
React.useEffect(() => {
|
||||
;(async () => {
|
||||
const prefs = await BackgroundNotifications.getPrefsAsync()
|
||||
const prefs: BackgroundNotificationHandlerPreferences = {
|
||||
playSoundChat: SharedPrefs.getBool('playSoundChat') ?? true,
|
||||
}
|
||||
if (prefs) {
|
||||
setPreferences(prefs)
|
||||
}
|
||||
})()
|
||||
}, [])
|
||||
|
||||
const value = React.useMemo(
|
||||
() => ({
|
||||
preferences,
|
||||
setPref: async <
|
||||
Key extends keyof BackgroundNotificationHandlerPreferences,
|
||||
>(
|
||||
k: Key,
|
||||
v: BackgroundNotificationHandlerPreferences[Key],
|
||||
) => {
|
||||
SharedPrefs.setValue(k, v)
|
||||
setPreferences(prev => ({
|
||||
...prev,
|
||||
[k]: v,
|
||||
}))
|
||||
},
|
||||
}),
|
||||
[preferences],
|
||||
)
|
||||
const value = {
|
||||
preferences,
|
||||
setPref: <Key extends keyof BackgroundNotificationHandlerPreferences>(
|
||||
k: Key,
|
||||
v: BackgroundNotificationHandlerPreferences[Key],
|
||||
) => {
|
||||
SharedPrefs.setValue(k, v)
|
||||
setPreferences(prev => ({...prev, [k]: v}))
|
||||
},
|
||||
}
|
||||
|
||||
return <Context.Provider value={value}>{children}</Context.Provider>
|
||||
}
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
import {requireNativeModule} from 'expo'
|
||||
|
||||
import {BackgroundNotificationHandlerPreferences} from './ExpoBackgroundNotificationHandler.types'
|
||||
|
||||
const NativeModule = requireNativeModule('ExpoBackgroundNotificationHandler')
|
||||
|
||||
export function resetGenericCountAsync(): Promise<void> {
|
||||
NativeModule.resetGenericCountAsync()
|
||||
export async function resetGenericCountAsync(): Promise<void> {
|
||||
await NativeModule.resetGenericCountAsync()
|
||||
}
|
||||
|
||||
export function maybeIncrementMessagesCountAsync(
|
||||
export async function maybeIncrementMessagesCountAsync(
|
||||
convoId: string,
|
||||
): Promise<boolean> {
|
||||
NativeModule.incrementMessagesCountAsync(convoId)
|
||||
return await NativeModule.maybeIncrementMessagesCountAsync(convoId)
|
||||
}
|
||||
|
||||
export function maybeDecrementMessagesCountAsync(
|
||||
export async function maybeDecrementMessagesCountAsync(
|
||||
convoId: string,
|
||||
): Promise<boolean> {
|
||||
NativeModule.decrementMessagesCountAsync(convoId)
|
||||
}
|
||||
|
||||
export function getPrefsAsync(): Promise<BackgroundNotificationHandlerPreferences> {
|
||||
return NativeModule.getPrefsAsync()
|
||||
return await NativeModule.maybeDecrementMessagesCountAsync(convoId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user