From d183f6ff63c9dd4190b0bddffab2ff6c07f1c71e Mon Sep 17 00:00:00 2001 From: Mike Mhlv Date: Tue, 4 Nov 2025 17:01:09 +0000 Subject: [PATCH] JS-7418: settings auto download --- src/img/icon/settings/download.svg | 3 ++ src/img/icon/settings/drive.svg | 2 +- src/img/icon/settings/location.svg | 2 +- src/img/theme/dark/icon/settings/download.svg | 3 ++ src/json/text.json | 4 ++ src/scss/page/main/settings.scss | 2 +- src/scss/theme/dark/page.scss | 2 +- .../page/main/settings/data/index.tsx | 40 +++++++++++++++++-- src/ts/lib/api/command.ts | 10 ++++- 9 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 src/img/icon/settings/download.svg create mode 100644 src/img/theme/dark/icon/settings/download.svg diff --git a/src/img/icon/settings/download.svg b/src/img/icon/settings/download.svg new file mode 100644 index 0000000000..32e3e91655 --- /dev/null +++ b/src/img/icon/settings/download.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/img/icon/settings/drive.svg b/src/img/icon/settings/drive.svg index 12adede85b..f8db3d5b0f 100644 --- a/src/img/icon/settings/drive.svg +++ b/src/img/icon/settings/drive.svg @@ -1,3 +1,3 @@ - + diff --git a/src/img/icon/settings/location.svg b/src/img/icon/settings/location.svg index a75f8921a4..e6f3003d59 100644 --- a/src/img/icon/settings/location.svg +++ b/src/img/icon/settings/location.svg @@ -1,3 +1,3 @@ - + diff --git a/src/img/theme/dark/icon/settings/download.svg b/src/img/theme/dark/icon/settings/download.svg new file mode 100644 index 0000000000..546d09836a --- /dev/null +++ b/src/img/theme/dark/icon/settings/download.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/json/text.json b/src/json/text.json index 5545f457b2..b7a881f7fe 100644 --- a/src/json/text.json +++ b/src/json/text.json @@ -1070,6 +1070,10 @@ "popupSettingsDataLocalFiles": "Local files", "popupSettingsDataOffloadWarningText": "All media files stored in Anytype will be deleted from your current device. They can be downloaded again from a backup node or another device.", "popupSettingsDataOffloadWarningTextLocalOnly": "Be careful: your client is in local-only mode, and data is not backing up to external nodes. Ensure that your files are synced to your other devices before removing them.", + + "popupSettingsDataOfflineAccess": "Offline Access", + "popupSettingsDataOfflineAccessDescription": "Auto sync files up to 20 MB for offline access", + "popupSettingsDataFilesOffloaded": "Files offloaded", "popupSettingsDataKeepFiles": "Keep files", "popupSettingsDataRemoveFiles": "Remove files", diff --git a/src/scss/page/main/settings.scss b/src/scss/page/main/settings.scss index 1855ba1fee..8946b83f2e 100644 --- a/src/scss/page/main/settings.scss +++ b/src/scss/page/main/settings.scss @@ -356,8 +356,8 @@ background-position: 50% 50%; background-repeat: no-repeat; background-size: 24px; background-color: var(--color-shape-highlight-medium); } .icon.drive { background-image: url('~img/icon/settings/drive.svg'); } - .icon.sites { background-image: url('~img/icon/settings/sites.svg'); } .icon.location { background-image: url('~img/icon/settings/location.svg'); } + .icon.download { background-image: url('~img/icon/settings/download.svg'); } .actionItems { .title { @include text-common; font-weight: 400; margin-bottom: 0; } diff --git a/src/scss/theme/dark/page.scss b/src/scss/theme/dark/page.scss index 8ae344bc34..5efb4541ce 100644 --- a/src/scss/theme/dark/page.scss +++ b/src/scss/theme/dark/page.scss @@ -184,8 +184,8 @@ .pageSettingsDataIndex { .icon.drive { background-image: url('#{$themePath}/icon/settings/drive.svg'); } - .icon.sites { background-image: url('#{$themePath}/icon/settings/sites.svg'); } .icon.location { background-image: url('#{$themePath}/icon/settings/location.svg'); } + .icon.download { background-image: url('#{$themePath}/icon/settings/download.svg'); } } .pageSettingsSpaceShare { diff --git a/src/ts/component/page/main/settings/data/index.tsx b/src/ts/component/page/main/settings/data/index.tsx index 5895a27eaa..65f2c7f37b 100644 --- a/src/ts/component/page/main/settings/data/index.tsx +++ b/src/ts/component/page/main/settings/data/index.tsx @@ -1,10 +1,11 @@ -import React, { forwardRef } from 'react'; -import { Title, Label, Button, Icon } from 'Component'; +import React, { forwardRef, useState, useEffect } from 'react'; +import { Title, Label, Button, Icon, Switch } from 'Component'; import { I, C, S, U, translate, analytics, Action } from 'Lib'; import { observer } from 'mobx-react'; const PageMainSettingsDataIndex = observer(forwardRef((props, ref) => { + const [ autodownload, setAutodownload ] = useState(true); const { dataPath, spaceStorage } = S.Common; const { localUsage } = spaceStorage; const isLocalNetwork = U.Data.isLocalNetwork(); @@ -47,6 +48,22 @@ const PageMainSettingsDataIndex = observer(forwardRef { + // TODO: finish when MW is ready + }; + + const onAutoDownloadSwitch = (e: any, v: boolean) => { + C.FileSetAutoDownload(v, (message) => { + if (!message.error) { + setAutodownload(v); + }; + }); + }; + + useEffect(() => { + getAutodownloadStatus(); + }, []); + return ( <> @@ -81,10 +98,27 @@ const PageMainSettingsDataIndex = observer(forwardRef<I.PageRef, I.PageSettingsC <Button color="blank" className="c28" text={translate(`commonOpen`)} onClick={onOpenDataLocation} /> </div> </div> + + <div className="item"> + <div className="side left"> + <Icon className="download" /> + + <div className="txt"> + <div className="name">{translate('popupSettingsDataOfflineAccess')}</div> + <div className="type">{translate(`popupSettingsDataOfflineAccessDescription`)}</div> + </div> + </div> + <div className="side right"> + <Switch + value={autodownload} + onChange={onAutoDownloadSwitch} + /> + </div> + </div> </div> </> ); })); -export default PageMainSettingsDataIndex; \ No newline at end of file +export default PageMainSettingsDataIndex; diff --git a/src/ts/lib/api/command.ts b/src/ts/lib/api/command.ts index 3a73122ee6..4d4ed4b88e 100644 --- a/src/ts/lib/api/command.ts +++ b/src/ts/lib/api/command.ts @@ -369,6 +369,14 @@ export const FileDiscardPreload = (fileId: string, callBack?: (message: any) => dispatcher.request(FileDiscardPreload.name, request, callBack); }; +export const FileSetAutoDownload = (enabled: boolean, callBack?: (message: any) => void) => { + const request = new Rpc.File.SetAutoDownload.Request(); + + request.setEnabled(enabled); + + dispatcher.request(FileSetAutoDownload.name, request, callBack); +}; + // ---------------------- NAVIGATION ---------------------- // export const NavigationGetObjectInfoWithLinks = (pageId: string, callBack?: (message: any) => void) => { @@ -2535,4 +2543,4 @@ export const PushNotificationAddAllIds = (spaceId: string, ids: string[], callBa request.setChatidsList(ids); dispatcher.request(PushNotificationAddAllIds.name, request, callBack); -}; \ No newline at end of file +};