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