From 1e178498032a07662dd5a9cd70cb4eca3bca6091 Mon Sep 17 00:00:00 2001 From: Hailey Date: Fri, 12 Jul 2024 17:10:30 -0700 Subject: [PATCH] update js --- .../BackgroundNotificationHandlerProvider.tsx | 33 ++++++++----------- .../src/index.native.ts | 18 ++++------ 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx b/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx index 35cd506062..4898b1cd1a 100644 --- a/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx +++ b/modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider.tsx @@ -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: ( + k: Key, + v: BackgroundNotificationHandlerPreferences[Key], + ) => { + SharedPrefs.setValue(k, v) + setPreferences(prev => ({...prev, [k]: v})) + }, + } return {children} } diff --git a/modules/expo-background-notification-handler/src/index.native.ts b/modules/expo-background-notification-handler/src/index.native.ts index f93b9462ce..435a60ba99 100644 --- a/modules/expo-background-notification-handler/src/index.native.ts +++ b/modules/expo-background-notification-handler/src/index.native.ts @@ -1,25 +1,19 @@ import {requireNativeModule} from 'expo' -import {BackgroundNotificationHandlerPreferences} from './ExpoBackgroundNotificationHandler.types' - const NativeModule = requireNativeModule('ExpoBackgroundNotificationHandler') -export function resetGenericCountAsync(): Promise { - NativeModule.resetGenericCountAsync() +export async function resetGenericCountAsync(): Promise { + await NativeModule.resetGenericCountAsync() } -export function maybeIncrementMessagesCountAsync( +export async function maybeIncrementMessagesCountAsync( convoId: string, ): Promise { - NativeModule.incrementMessagesCountAsync(convoId) + return await NativeModule.maybeIncrementMessagesCountAsync(convoId) } -export function maybeDecrementMessagesCountAsync( +export async function maybeDecrementMessagesCountAsync( convoId: string, ): Promise { - NativeModule.decrementMessagesCountAsync(convoId) -} - -export function getPrefsAsync(): Promise { - return NativeModule.getPrefsAsync() + return await NativeModule.maybeDecrementMessagesCountAsync(convoId) }