diff --git a/apps/mobile/app/components/sheets/force-sync/index.tsx b/apps/mobile/app/components/sheets/force-sync/index.tsx new file mode 100644 index 000000000..e78437148 --- /dev/null +++ b/apps/mobile/app/components/sheets/force-sync/index.tsx @@ -0,0 +1,221 @@ +/* +This file is part of the Notesnook project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +import { strings } from "@notesnook/intl"; +import { useThemeColors } from "@notesnook/theme"; +import React, { useState } from "react"; +import { View } from "react-native"; +import { Radius, Spacing } from "../../../common/design/spacing"; +import { Button } from "../../ui/button"; +import AppIcon from "../../ui/AppIcon"; +import { Pressable } from "../../ui/pressable"; +import Heading from "../../ui/typography/heading"; +import Paragraph from "../../ui/typography/paragraph"; +import { AppFontSize } from "../../../utils/size"; +import { presentSheet, eSendEvent } from "../../../services/event-manager"; +import { eCloseSheet } from "../../../utils/events"; +import { sleep } from "../../../utils/time"; +import { Progress } from "../progress"; +import Sync from "../../../services/sync"; + +type ForceSyncMode = "fetch" | "send"; + +type ForceSyncProps = { + mode: ForceSyncMode; + close?: (ctx?: string) => void; +}; + +function ForceSync({ mode, close }: ForceSyncProps) { + const { colors } = useThemeColors(); + const [acknowledged, setAcknowledged] = useState(true); + + const onForceSyncPress = async () => { + if (!acknowledged) return; + + close?.(); + await sleep(300); + Progress.present(); + Sync.run("global", true, mode, () => { + eSendEvent(eCloseSheet); + }); + }; + + const title = + mode === "fetch" ? strings.forcePullChanges() : strings.forcePushChanges(); + const description = + mode === "fetch" + ? strings.forceSyncPullSheetDesc() + : strings.forceSyncPushSheetDesc(); + const actionText = + mode === "fetch" ? strings.forcePullAction() : strings.forcePushAction(); + + return ( + + + + + + + + + {title} + + {description} + + + + + + + + {strings.forceSyncWarningShort()} + + + + {strings.forceSyncNeedHelpContact()} + + + support@streetwriters.co + + + + + setAcknowledged((value) => !value)} + > + + + {strings.forceSyncRiskAcknowledgement()} + + + + +