Skip to content

Commit

Permalink
feat: add button to adjust last sync date
Browse files Browse the repository at this point in the history
closes #71
  • Loading branch information
linonetwo committed Dec 1, 2024
1 parent f918f15 commit dcc2350
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/i18n/localization/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"ResetDefaultIcon": "Reset Default Icon",
"NoRevert": "Caution! This operation can't be reverted.",
"LastVisitState": "Last page visited",
"SetLastSyncDate": "Adjust last sync date",
"URL": "Wiki URL",
"Port": "Local host server port",
"PathDescription": "Location of your local wiki folder.",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/localization/locales/zh_CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"Path": "Wiki的位置",
"Save": "保存",
"Cancel": "取消",
"SetLastSyncDate": "调整上次同步时间",
"HibernateTitle": "开启休眠",
"DisableAudioTitle": "关闭声音",
"DisableNotificationTitle": "关闭提醒",
Expand Down
31 changes: 31 additions & 0 deletions src/pages/MainMenu/EditItemModel/WikiChangesModelContent.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DateTimePicker, { DateTimePickerEvent } from '@react-native-community/datetimepicker';
import { Picker } from '@react-native-picker/picker';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -30,13 +31,27 @@ export function WikiChangesModelContent({ id, onClose }: ModalProps): JSX.Elemen
})
);
const [serverIDToView, setServerIDToView] = useState<string | undefined>(availableServersToPick[0]?.id);
const [showDatePicker, setShowDatePicker] = useState(false);
const [date, setDate] = useState(new Date());
const updateWiki = useWorkspaceStore(state => state.update);

const [lastSyncToFilterLogs, setLastSyncToFilterLogs] = useState<Date | undefined>();
useEffect(() => {
const lastSync = wiki?.syncedServers?.find(item => item.serverID === serverIDToView)?.lastSync;
setLastSyncToFilterLogs(lastSync === undefined ? new Date(0) : new Date(lastSync));
}, [serverIDToView, wiki?.syncedServers]);

const onLastSyncChange = (event: DateTimePickerEvent, selectedDate?: Date) => {
const currentDate = selectedDate ?? date;
setShowDatePicker(false);
setDate(currentDate);
if (wiki !== undefined && serverIDToView !== undefined) {
updateWiki(wiki.id, {
syncedServers: wiki.syncedServers.map(server => server.serverID === serverIDToView ? { ...server, lastSync: currentDate.getTime() } : server),
});
}
};

if (id === undefined || wiki === undefined) {
return (
<ModalContainer>
Expand All @@ -48,6 +63,22 @@ export function WikiChangesModelContent({ id, onClose }: ModalProps): JSX.Elemen
return (
<ModalContainer>
<CloseButton mode='outlined' onPress={onClose}>{t('Menu.Close')}</CloseButton>
<Button
onPress={() => {
setShowDatePicker(true);
}}
mode='outlined'
>
<Text>{t('EditWorkspace.SetLastSyncDate')}</Text>
</Button>
{showDatePicker && (
<DateTimePicker
value={date}
mode='date'
display='default'
onChange={onLastSyncChange}
/>
)}
<Picker
selectionColor={theme.colors.primary}
style={pickerStyle}
Expand Down

0 comments on commit dcc2350

Please sign in to comment.