From dcc235044049f9f81eb08b3ed0d8657992397f1a Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Sun, 1 Dec 2024 16:30:09 +0800 Subject: [PATCH] feat: add button to adjust last sync date closes #71 --- .../localization/locales/en/translation.json | 1 + .../locales/zh_CN/translation.json | 1 + .../EditItemModel/WikiChangesModelContent.tsx | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/i18n/localization/locales/en/translation.json b/src/i18n/localization/locales/en/translation.json index 191f8d3..907b78e 100644 --- a/src/i18n/localization/locales/en/translation.json +++ b/src/i18n/localization/locales/en/translation.json @@ -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.", diff --git a/src/i18n/localization/locales/zh_CN/translation.json b/src/i18n/localization/locales/zh_CN/translation.json index 686a6a7..a21d17d 100644 --- a/src/i18n/localization/locales/zh_CN/translation.json +++ b/src/i18n/localization/locales/zh_CN/translation.json @@ -190,6 +190,7 @@ "Path": "Wiki的位置", "Save": "保存", "Cancel": "取消", + "SetLastSyncDate": "调整上次同步时间", "HibernateTitle": "开启休眠", "DisableAudioTitle": "关闭声音", "DisableNotificationTitle": "关闭提醒", diff --git a/src/pages/MainMenu/EditItemModel/WikiChangesModelContent.tsx b/src/pages/MainMenu/EditItemModel/WikiChangesModelContent.tsx index 3cad865..884798a 100644 --- a/src/pages/MainMenu/EditItemModel/WikiChangesModelContent.tsx +++ b/src/pages/MainMenu/EditItemModel/WikiChangesModelContent.tsx @@ -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'; @@ -30,6 +31,9 @@ export function WikiChangesModelContent({ id, onClose }: ModalProps): JSX.Elemen }) ); const [serverIDToView, setServerIDToView] = useState(availableServersToPick[0]?.id); + const [showDatePicker, setShowDatePicker] = useState(false); + const [date, setDate] = useState(new Date()); + const updateWiki = useWorkspaceStore(state => state.update); const [lastSyncToFilterLogs, setLastSyncToFilterLogs] = useState(); useEffect(() => { @@ -37,6 +41,17 @@ export function WikiChangesModelContent({ id, onClose }: ModalProps): JSX.Elemen 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 ( @@ -48,6 +63,22 @@ export function WikiChangesModelContent({ id, onClose }: ModalProps): JSX.Elemen return ( {t('Menu.Close')} + + {showDatePicker && ( + + )}