Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32179114
D15309.1765071620.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D15309.1765071620.diff
View Options
diff --git a/lib/shared/farcaster/farcaster-hooks.js b/lib/shared/farcaster/farcaster-hooks.js
--- a/lib/shared/farcaster/farcaster-hooks.js
+++ b/lib/shared/farcaster/farcaster-hooks.js
@@ -142,6 +142,7 @@
batchSize: number,
processor: (item: T, batchedUpdates: BatchedUpdates) => Promise<R>,
dispatch: Dispatch,
+ onProgress?: (completed: number, total: number) => void,
): Promise<Array<R>> {
const results: Array<R> = [];
for (let i = 0; i < items.length; i += batchSize) {
@@ -179,6 +180,9 @@
});
}
+ const completedItems = Math.min(i + batchSize, items.length);
+ onProgress?.(completedItems, items.length);
+
// This should help with the app responsiveness
await sleep(0);
}
@@ -362,7 +366,14 @@
);
}
-function useFarcasterConversationsSync(): (limit: number) => Promise<void> {
+function useFarcasterConversationsSync(): (
+ limit: number,
+ onProgress?: (
+ completed: number,
+ total: number,
+ phase: 'conversations' | 'messages',
+ ) => void,
+) => Promise<void> {
const fetchFarcasterInbox = useFetchFarcasterInbox();
const dispatch = useDispatch();
const fetchConversation = useFetchConversationWithBatching();
@@ -444,7 +455,14 @@
);
return React.useCallback(
- async (limit: number) => {
+ async (
+ limit: number,
+ onProgress?: (
+ completed: number,
+ total: number,
+ phase: 'conversations' | 'messages',
+ ) => void,
+ ) => {
try {
const conversations = await fetchInboxes(null);
@@ -457,17 +475,20 @@
const farcasterConversations: Array<FarcasterConversation> = [];
+ onProgress?.(0, conversations.length, 'conversations');
const conversationResults = await processInBatchesWithReduxBatching(
conversations,
FARCASTER_DATA_BATCH_SIZE,
(conversationID, batchedUpdates) =>
fetchConversation(conversationID, batchedUpdates),
dispatch,
+ (completed, total) => onProgress?.(completed, total, 'conversations'),
);
const successfulConversations = conversationResults.filter(Boolean);
farcasterConversations.push(...successfulConversations);
+ onProgress?.(0, conversations.length, 'messages');
await processInBatchesWithReduxBatching(
farcasterConversations,
FARCASTER_DATA_BATCH_SIZE,
@@ -478,6 +499,7 @@
batchedUpdates,
),
dispatch,
+ (completed, total) => onProgress?.(completed, total, 'messages'),
);
setFarcasterDCsLoaded(true);
@@ -547,7 +569,14 @@
);
}
-function useFarcasterSync(onComplete?: () => void): { +inProgress: boolean } {
+function useFarcasterSync(onComplete?: () => void): {
+ +inProgress: boolean,
+ +progress: ?{
+ completed: number,
+ total: number,
+ phase: 'conversations' | 'messages',
+ },
+} {
const syncFarcasterConversations = useFarcasterConversationsSync();
const currentUserSupportsDCs = useCurrentUserSupportsDCs();
const farcasterDCsLoaded = useFarcasterDCsLoaded();
@@ -555,6 +584,21 @@
const userDataReady = useIsUserDataReady();
const fullyLoggedIn = isUserLoggedIn && userDataReady;
const [inProgress, setInProgress] = React.useState(false);
+ const [progress, setProgress] = React.useState<?{
+ completed: number,
+ total: number,
+ phase: 'conversations' | 'messages',
+ }>(null);
+
+ const handleProgress = React.useCallback(
+ (completed: number, total: number, phase: 'conversations' | 'messages') =>
+ setProgress({
+ completed,
+ total,
+ phase,
+ }),
+ [],
+ );
React.useEffect(() => {
if (
@@ -566,11 +610,16 @@
return;
}
setInProgress(true);
+ setProgress(null);
void (async () => {
try {
- await syncFarcasterConversations(Number.POSITIVE_INFINITY);
+ await syncFarcasterConversations(
+ Number.POSITIVE_INFINITY,
+ handleProgress,
+ );
} finally {
setInProgress(false);
+ setProgress(null);
onComplete?.();
}
})();
@@ -580,10 +629,11 @@
fullyLoggedIn,
inProgress,
onComplete,
+ handleProgress,
syncFarcasterConversations,
]);
- return { inProgress };
+ return { inProgress, progress };
}
export {
diff --git a/native/farcaster/farcaster-sync-loading-screen.react.js b/native/farcaster/farcaster-sync-loading-screen.react.js
--- a/native/farcaster/farcaster-sync-loading-screen.react.js
+++ b/native/farcaster/farcaster-sync-loading-screen.react.js
@@ -24,7 +24,22 @@
props.navigation.goBack();
}, [props.navigation]);
- useFarcasterSync(handleComplete);
+ const { progress } = useFarcasterSync(handleComplete);
+
+ const progressValue = progress
+ ? progress.completed / progress.total
+ : undefined;
+
+ const phase = React.useMemo(() => {
+ if (!progress?.phase) {
+ return null;
+ }
+ const phaseText =
+ progress.phase === 'conversations'
+ ? 'Loading conversations...'
+ : 'Loading messages...';
+ return <Text style={styles.section}>{phaseText}</Text>;
+ }, [progress?.phase, styles.section]);
return (
<SafeAreaView edges={safeAreaEdges} style={styles.container}>
@@ -35,13 +50,24 @@
<Text style={styles.section}>
This could take a while depending on how many conversations you have.
</Text>
+ {phase}
<View style={styles.progressContainer}>
- <Progress.CircleSnail
- indeterminate
- color={colors.panelForegroundIcon}
- size={100}
- strokeCap="round"
- />
+ {progress ? (
+ <Progress.Circle
+ progress={progressValue}
+ size={100}
+ color={colors.panelForegroundIcon}
+ strokeCap="round"
+ showsText
+ />
+ ) : (
+ <Progress.CircleSnail
+ indeterminate
+ color={colors.panelForegroundIcon}
+ size={100}
+ strokeCap="round"
+ />
+ )}
</View>
</SafeAreaView>
);
diff --git a/web/farcaster/farcaster-sync-loading-screen.react.js b/web/farcaster/farcaster-sync-loading-screen.react.js
--- a/web/farcaster/farcaster-sync-loading-screen.react.js
+++ b/web/farcaster/farcaster-sync-loading-screen.react.js
@@ -8,7 +8,29 @@
import LoadingIndicator from '../loading-indicator.react.js';
function FarcasterSyncLoadingScreen(): React.Node {
- useFarcasterSync();
+ const { progress } = useFarcasterSync();
+
+ const progressComponent = React.useMemo(() => {
+ if (!progress) {
+ return null;
+ }
+ return (
+ <>
+ <p className={css.description}>
+ {progress.phase === 'conversations'
+ ? 'Loading conversations...'
+ : 'Loading messages...'}
+ </p>
+ <p className={css.description}>
+ {progress.completed} of {progress.total} (
+ {progress.total
+ ? Math.round((progress.completed / progress.total) * 100)
+ : 0}
+ %)
+ </p>
+ </>
+ );
+ }, [progress]);
return (
<div className={css.loadingContainer}>
@@ -24,6 +46,7 @@
This could take a while depending on how many conversations you
have.
</p>
+ {progressComponent}
</div>
<div className={css.spinner}>
<LoadingIndicator status="loading" size="x-large" />
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 1:40 AM (8 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5841997
Default Alt Text
D15309.1765071620.diff (7 KB)
Attached To
Mode
D15309: [lib] Improve Farcaster sync loading state
Attached
Detach File
Event Timeline
Log In to Comment