Skip to content

Commit

Permalink
Added last sync time to the settings page; Updated sync interval;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Jan 4, 2024
1 parent f4c3139 commit eac02b7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
11 changes: 5 additions & 6 deletions packages/mobile/src/hooks/cameraRoll/useSyncFromCameraRoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useAuth from '../auth/useAuth';
import { useKeyValueStorage } from '../auth/useEncryptedStorage';

const ONE_MINUTE = 60000;
const ONE_HOUR = ONE_MINUTE * 60;
const FIVE_MINUTES = ONE_MINUTE * 5;

const targetDrive = PhotoConfig.PhotoDrive;

Expand Down Expand Up @@ -60,7 +60,7 @@ const useSyncFromCameraRoll = () => {
dotYouClient,
targetDrive,
undefined,
fileData.node.image,
fileData.node.image
);
await addDayToLibrary({ date: uploadResult.userDate });
}
Expand All @@ -78,10 +78,10 @@ const useSyncFromCameraRoll = () => {
// Only one to start/run per startup;
if (isFetching.current || isFinished.current) return;

// Only sync when last sync was more than 1 hour ago
// Only sync when last sync was more than 5 minutes ago
if (
lastCameraRollSyncTimeAsInt &&
new Date().getTime() - lastCameraRollSyncTimeAsInt < ONE_HOUR
new Date().getTime() - lastCameraRollSyncTimeAsInt < FIVE_MINUTES
)
return;

Expand All @@ -95,8 +95,7 @@ const useSyncFromCameraRoll = () => {
isFetching.current = false;
isFinished.current = true;

if (!earliestSyncTime)
setEarliestSyncTime(lastCameraRollSyncTimeAsInt.toString());
if (!earliestSyncTime) setEarliestSyncTime(lastCameraRollSyncTimeAsInt.toString());

setLastCameraRollSyncTime(new Date().getTime().toString());
}, 5000);
Expand Down
45 changes: 38 additions & 7 deletions packages/mobile/src/pages/settings-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import InAppBrowser from 'react-native-inappbrowser-reborn';

type SettingsProps = NativeStackScreenProps<SettingsStackParamList, 'Profile'>;

const dateFormat: Intl.DateTimeFormatOptions = {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
};

const SettingsPage = (_props: SettingsProps) => {
const { logout, getIdentity } = useAuth();
const { cleanup } = useDbSync();
Expand All @@ -34,6 +42,7 @@ const SettingsPage = (_props: SettingsProps) => {
setSyncFromCameraRoll,
backupFromCameraRoll,
setBackupFromCameraRoll,
lastCameraRollSyncTime,
} = useKeyValueStorage();

const doLogout = async () => {
Expand Down Expand Up @@ -88,13 +97,35 @@ const SettingsPage = (_props: SettingsProps) => {
}}
>
<Sync size={'lg'} />
<Text
style={{
marginLeft: 16,
}}
>
Sync with your Camera roll
</Text>
<View style={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<Text
style={{
marginLeft: 16,
}}
>
Sync with your Camera roll
</Text>
{syncFromCameraRoll ? (
<Text
style={{
marginLeft: 16,
opacity: 0.5,
}}
>
{lastCameraRollSyncTime ? (
<>
Last sync:{' '}
{new Date(parseInt(lastCameraRollSyncTime)).toLocaleString(
undefined,
dateFormat
)}
</>
) : (
'Last sync: not synced yet'
)}
</Text>
) : null}
</View>
<View style={{ marginLeft: 'auto' }}>
<CheckBox
value={syncFromCameraRoll}
Expand Down

0 comments on commit eac02b7

Please sign in to comment.