Skip to content

Commit

Permalink
Merge pull request #3775 from tloncorp/lb/misc-fixes
Browse files Browse the repository at this point in the history
native: a few ChatList fixes
  • Loading branch information
latter-bolden authored Jul 19, 2024
2 parents 4c28622 + c346d06 commit 38a12b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apps/tlon-mobile/src/components/AuthenticatedApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ZStack } from '@tloncorp/ui';
import { useEffect } from 'react';

import { useShip } from '../contexts/ship';
import useAppForegrounded from '../hooks/useAppForegrounded';
import { useCurrentUserId } from '../hooks/useCurrentUser';
import { useDeepLinkListener } from '../hooks/useDeepLinkListener';
import useNotificationListener, {
Expand Down Expand Up @@ -44,6 +45,10 @@ function AuthenticatedApp({
sync.syncStart();
}, [currentUserId, ship, shipUrl]);

useAppForegrounded(() => {
sync.syncUnreads(sync.SyncPriority.High);
});

return (
<ZStack flex={1}>
<RootStack />
Expand Down
30 changes: 30 additions & 0 deletions apps/tlon-mobile/src/hooks/useAppForegrounded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useCallback, useEffect, useState } from 'react';
import { AppState, AppStateStatus } from 'react-native';

const useAppForegrounded = (callback: (() => void) | (() => Promise<void>)) => {
const [appState, setAppState] = useState(AppState.currentState);

const handleAppStateChange = useCallback(
(nextAppState: AppStateStatus) => {
if (appState.match(/inactive|background/) && nextAppState === 'active') {
// App has come to the foreground
callback();
}
setAppState(nextAppState);
},
[appState, callback]
);

useEffect(() => {
const subscription = AppState.addEventListener(
'change',
handleAppStateChange
);

return () => {
subscription.remove();
};
}, [callback, handleAppStateChange]);
};

export default useAppForegrounded;
1 change: 0 additions & 1 deletion apps/tlon-mobile/src/screens/ChatListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default function ChatListScreen(

useFocusEffect(
useCallback(() => {
store.syncUnreads(store.SyncPriority.High);
store.syncPinnedItems(store.SyncPriority.High);
}, [])
);
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export function ChatList({
{
gap: '$s',
paddingHorizontal: '$l',
paddingBottom: 100, // bottom nav height + some cushion
},
{ resolveValues: 'value' }
) as StyleProp<ViewStyle>;
Expand Down

0 comments on commit 38a12b5

Please sign in to comment.