update js

This commit is contained in:
Hailey
2024-07-12 17:10:30 -07:00
parent f5d231f2f0
commit 1e17849803
2 changed files with 19 additions and 32 deletions
@@ -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)
}