Moved later/gitgram-ai/gitgram/ to apps/ritgram/ (fresh history; full history stays in caelum0x/gitgram). AITimeMachine stays separate in later/gitgram-ai per the Rithub master plan. Logs, pid files and env files are ignored; GPL-3.0 mobile/proximity noted in THIRD_PARTY_NOTICES. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
36 lines
833 B
TypeScript
36 lines
833 B
TypeScript
import React from 'react';
|
|
|
|
// Hook for optimistic UI updates
|
|
export function useOptimisticUpdate<T>(
|
|
initialData: T,
|
|
updateFn: (data: T) => Promise<T>
|
|
) {
|
|
const [data, setData] = React.useState<T>(initialData);
|
|
const [isUpdating, setIsUpdating] = React.useState(false);
|
|
|
|
const update = React.useCallback(
|
|
async (optimisticData: T) => {
|
|
// Optimistically update UI
|
|
setData(optimisticData);
|
|
setIsUpdating(true);
|
|
|
|
try {
|
|
// Perform actual update
|
|
const result = await updateFn(optimisticData);
|
|
setData(result);
|
|
return result;
|
|
} catch (error) {
|
|
// Revert on error
|
|
setData(initialData);
|
|
throw error;
|
|
} finally {
|
|
setIsUpdating(false);
|
|
}
|
|
},
|
|
[updateFn, initialData]
|
|
);
|
|
|
|
return { data, update, isUpdating };
|
|
}
|
|
|