diff --git a/renderer/pages/sync.js b/renderer/pages/sync.js index aaddb4a6f..56ee6aea2 100644 --- a/renderer/pages/sync.js +++ b/renderer/pages/sync.js @@ -1,7 +1,7 @@ -import Sync from '@/modules/projects/Sync'; +import Sync from '@/components/Sync/Sync'; import AuthenticationContextProvider from '@/components/Login/AuthenticationContextProvider'; import AutographaContextProvider from '@/components/context/AutographaContext'; -import SyncContextProvider from '@/components/Sync/SyncContextProvider'; +import SyncContextProvider from '@/components/context/SyncContext'; const projects = () => ( diff --git a/renderer/src/components/Sync/LoadingSpinner.js b/renderer/src/components/LoadingSpinner/LoadingSpinner.js similarity index 100% rename from renderer/src/components/Sync/LoadingSpinner.js rename to renderer/src/components/LoadingSpinner/LoadingSpinner.js diff --git a/renderer/src/components/LoadingSpinner/index.js b/renderer/src/components/LoadingSpinner/index.js new file mode 100644 index 000000000..f4e655db5 --- /dev/null +++ b/renderer/src/components/LoadingSpinner/index.js @@ -0,0 +1 @@ +export { default as LoadingSpinner } from './LoadingSpinner'; diff --git a/renderer/src/components/Sync/ProgressCircle.js b/renderer/src/components/ProgressCircle/ProgressCircle.js similarity index 100% rename from renderer/src/components/Sync/ProgressCircle.js rename to renderer/src/components/ProgressCircle/ProgressCircle.js diff --git a/renderer/src/components/ProgressCircle/index.js b/renderer/src/components/ProgressCircle/index.js new file mode 100644 index 000000000..088e14f11 --- /dev/null +++ b/renderer/src/components/ProgressCircle/index.js @@ -0,0 +1 @@ +export { default as ProgressCircle } from './ProgressCircle'; diff --git a/renderer/src/components/Sync/Ag/SyncToGitea-backup.js b/renderer/src/components/Sync/Ag/SyncToGitea-backup.js deleted file mode 100644 index 7a08dd2b1..000000000 --- a/renderer/src/components/Sync/Ag/SyncToGitea-backup.js +++ /dev/null @@ -1,107 +0,0 @@ -import * as localForage from 'localforage'; -import * as logger from '../../../logger'; -import { - handleCreateRepo, createFiletoServer, updateFiletoServer, getOrPutLastSyncInAgSettings, -} from './SyncToGiteaUtils'; -import packageInfo from '../../../../../package.json'; - -// upload project to gitea main function -export async function uploadToGitea(projectDataAg, auth, setSyncProgress, notifyStatus, addNotification) { - logger.debug('ToGiteaUtils.js', 'in uploadTOGitea'); - const projectData = projectDataAg.projectMeta; - const projectId = Object.keys(projectData.identification.primary[packageInfo.name])[0]; - const projectName = projectData.identification.name.en; - const ingredientsObj = projectData.ingredients; - const projectCreated = projectData.meta.dateCreated.split('T')[0]; - const repoName = `${packageInfo.name}-${projectData.languages[0].tag}-${projectData.type.flavorType.flavor.name}-${projectName.replace(/[\s+ -]/g, '_')}`; - - localForage.getItem('userProfile').then(async (user) => { - const newpath = localStorage.getItem('userPath'); - const fs = window.require('fs'); - const path = require('path'); - const projectsMetaPath = path.join(newpath, packageInfo.name, 'users', user?.username, 'projects', `${projectName}_${projectId}`); - setSyncProgress((prev) => ( - { - ...prev, - totalFiles: Object.keys(ingredientsObj).length, - } - )); - // Create A REPO for the project - try { - const createResult = await handleCreateRepo(repoName.toLowerCase(), auth); - if (createResult.id) { - logger.debug('SyncToGitea.js', 'repo created success : starting sync'); - setSyncProgress((prev) => ({ - ...prev, - syncStarted: true, - })); - // read metadata - const Metadata = await fs.readFileSync(path.join(projectsMetaPath, 'metadata.json')); - await createFiletoServer(JSON.stringify(Metadata), 'metadata.json', `${user?.username}/${projectCreated}.1`, createResult.name, auth); - logger.debug('SyncToGitea.js', 'read and uploaded metaData to repo'); - // Read ingredients - /* eslint-disable no-await-in-loop */ - /* eslint-disable no-restricted-syntax */ - for (const key in ingredientsObj) { - if (Object.prototype.hasOwnProperty.call(ingredientsObj, key)) { - setSyncProgress((prev) => ({ - ...prev, - completedFiles: prev.completedFiles + 1, - })); - // setTotalUploadedAg((prev) => prev + 1); - const Metadata1 = fs.readFileSync(path.join(projectsMetaPath, key), 'utf8'); - await createFiletoServer(Metadata1, key, `${user?.username}/${projectCreated}.1`, createResult.name, auth); - logger.debug('SyncToGitea.js', `Read and uploaded ${key} to repo`); - } - } - // update the scribe-settings - sync - await getOrPutLastSyncInAgSettings('put', projectData, auth?.user?.username); - notifyStatus('success', 'Sync completed successfully !!'); - await addNotification('Sync', 'Project Sync Successfull', 'success'); - logger.debug('SyncToGitea.js', 'sync successfull - first time'); - } else if (createResult.message.includes('409')) { - logger.debug('SyncToGitea.js', 'repo exist update section : 409 error'); - setSyncProgress((prev) => ({ - ...prev, - syncStarted: true, - })); - const metadataContent = fs.readFileSync(path.join(projectsMetaPath, 'metadata.json')); - await updateFiletoServer(JSON.stringify(metadataContent), 'metadata.json', `${user?.username}/${projectCreated}.1`, repoName, auth); - logger.debug('SyncToGitea.js', 'read and updated metaData to repo'); - // Read ingredients and update - for (const key in ingredientsObj) { - if (Object.prototype.hasOwnProperty.call(ingredientsObj, key)) { - setSyncProgress((prev) => ({ - ...prev, - completedFiles: prev.completedFiles + 1, - })); - const metadata1 = await fs.readFileSync(path.join(projectsMetaPath, key), 'utf8'); - // setTotalUploadedAg((prev) => prev + 1); - await updateFiletoServer(metadata1, key, `${user?.username}/${projectCreated}.1`, repoName, auth); - logger.debug('SyncToGitea.js', `Read and updated ${key} to repo`); - } - } - // update the scribe-settings - sync update - await getOrPutLastSyncInAgSettings('put', projectData, auth?.user?.username); - logger.debug('SyncToGitea.js', 'Updated last Sync data'); - notifyStatus('success', 'Sync completed successfully !!'); - await addNotification('Sync', 'Project Sync Successfull', 'success'); - logger.debug('SyncToGitea.js', 'sync successfull - update sync'); - } else { - logger.debug('SyncToGitea.js', 'create/update not success on sync : ', createResult.message); - notifyStatus('failure', 'Something went wrong, sync failed, check internet'); - logger.debug('SyncToGitea.js', 'sync failed - may be due to internet'); - } - } catch (err) { - logger.debug('SyncToGitea.js', `Error on Sync create/update : ${err}`); - notifyStatus('failure', `Sync failed : ${err}`); - await addNotification('Sync', err?.message || err, 'failure'); - } finally { - setSyncProgress({ - syncStarted: false, - totalFiles: 0, - completedFiles: 0, - }); - } - }); -} diff --git a/renderer/src/components/Sync/Gitea/EditorSync/EditorSync.js b/renderer/src/components/Sync/Gitea/EditorSync/EditorSync.js index 3cce09dcf..afe89eff5 100644 --- a/renderer/src/components/Sync/Gitea/EditorSync/EditorSync.js +++ b/renderer/src/components/Sync/Gitea/EditorSync/EditorSync.js @@ -7,17 +7,17 @@ import Link from 'next/link'; import { SnackBar } from '@/components/SnackBar'; import menuStyles from '@/layouts/editor/MenuBar.module.css'; import useAddNotification from '@/components/hooks/useAddNotification'; -import PopUpModal from '@/layouts/Sync/PopUpModal'; import ConfirmationModal from '@/layouts/editor/ConfirmationModal'; import { ReferenceContext } from '@/components/context/ReferenceContext'; +import PopUpModal from '../../PopUpModal'; import * as logger from '../../../../logger'; import CloudUploadIcon from '@/icons/basil/Outline/Files/Cloud-upload.svg'; import CloudCheckIcon from '@/icons/basil/Solid/Files/Cloud-check.svg'; -import ProgressCircle from '../../ProgressCircle'; +import { ProgressCircle } from '../../../ProgressCircle'; import Door43Logo from '@/icons/door43.svg'; import { getGiteaUsersList, handleEditorSync } from './EditorSyncUtils'; import useGetCurrentProjectMeta from '../../hooks/useGetCurrentProjectMeta'; -import { getOrPutLastSyncInAgSettings } from '../../Ag/SyncToGiteaUtils'; +import { getOrPutLastSyncInAgSettings } from '../../Scribe/SyncToGiteaUtils'; function EditorSync({ selectedProject }) { const [usersList, setUsersList] = useState([]); diff --git a/renderer/src/components/Sync/Gitea/EditorSync/EditorSyncUtils.js b/renderer/src/components/Sync/Gitea/EditorSync/EditorSyncUtils.js index dae9345ab..0e32b184e 100644 --- a/renderer/src/components/Sync/Gitea/EditorSync/EditorSyncUtils.js +++ b/renderer/src/components/Sync/Gitea/EditorSync/EditorSyncUtils.js @@ -2,7 +2,7 @@ import * as localForage from 'localforage'; import { environment } from '../../../../../environment'; import * as logger from '../../../../logger'; import packageInfo from '../../../../../../package.json'; -import { uploadToGitea } from '../../Ag/SyncToGitea'; +import { uploadToGitea } from '../../Scribe/SyncToGitea'; export async function getGiteaUsersList() { let usersList = []; diff --git a/renderer/src/components/Sync/Gitea/Gitea.js b/renderer/src/components/Sync/Gitea/Gitea.js index bee23608c..de029713d 100644 --- a/renderer/src/components/Sync/Gitea/Gitea.js +++ b/renderer/src/components/Sync/Gitea/Gitea.js @@ -5,7 +5,7 @@ import { } from 'gitea-react-toolkit'; import GiteaFileBrowser from './GiteaFileBrowser'; import { environment } from '../../../../environment'; -import { createSyncProfile } from '../Ag/SyncToGiteaUtils'; +import { createSyncProfile } from '../Scribe/SyncToGiteaUtils'; const Gitea = ({ setAuth, setRepo }) => { const [authentication, setAuthentication] = useState(); diff --git a/renderer/src/components/Sync/Gitea/GiteaFileBrowser.js b/renderer/src/components/Sync/Gitea/GiteaFileBrowser.js index 33f727d53..00dbe7efd 100644 --- a/renderer/src/components/Sync/Gitea/GiteaFileBrowser.js +++ b/renderer/src/components/Sync/Gitea/GiteaFileBrowser.js @@ -6,15 +6,13 @@ import { } from 'gitea-react-toolkit'; import { ChevronRightIcon } from '@heroicons/react/24/solid'; import CustomMultiComboBox from '@/components/Resources/ResourceUtils/CustomMultiComboBox'; -import { SyncContext } from '../SyncContextProvider'; +import { SyncContext } from '../../context/SyncContext'; import * as logger from '../../../logger'; -import LoadingSpinner from '../LoadingSpinner'; +import { LoadingSpinner } from '../../LoadingSpinner'; import GridRow from '../GridRow'; import ProjectMergePop from './ProjectMerge/ProjectMergePopUp'; import { environment } from '../../../../environment'; -/* eslint-disable no-console */ -// eslint-disable-next-line react/prop-types const GiteaFileBrowser = ({ changeRepo }) => { const { states: { diff --git a/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergePopUp.js b/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergePopUp.js index db5190522..d66cb7716 100644 --- a/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergePopUp.js +++ b/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergePopUp.js @@ -3,12 +3,12 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import ConfirmationModal from '@/layouts/editor/ConfirmationModal'; import PropTypes from 'prop-types'; -import PopUpModal from '@/layouts/Sync/PopUpModal'; import { SnackBar } from '@/components/SnackBar'; import useAddNotification from '@/components/hooks/useAddNotification'; +import PopUpModal from '../../PopUpModal'; import { VerticalLinearStepper } from '../../VerticalStepperProgress'; import { mergeProgressSteps } from './ProjectMergeConst'; -import LoadingSpinner from '../../LoadingSpinner'; +import { LoadingSpinner } from '../../../LoadingSpinner'; import { tryMergeProjects } from './MergeActions'; import burrito from '../../../../lib/BurritoTemplete.json'; import { backupLocalProject, deleteCreatedMergeBranch, undoMergeOrDeleteOldBackup } from './ProjectMergeUtils'; diff --git a/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergeUtils.js b/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergeUtils.js index c37c2bdcc..cb25d7afd 100644 --- a/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergeUtils.js +++ b/renderer/src/components/Sync/Gitea/ProjectMerge/ProjectMergeUtils.js @@ -1,4 +1,4 @@ -import { createFiletoServer } from '../../Ag/SyncToGiteaUtils'; +import { createFiletoServer } from '../../Scribe/SyncToGiteaUtils'; import * as logger from '../../../../logger'; import packageInfo from '../../../../../../package.json'; diff --git a/renderer/src/components/Sync/GridRow.js b/renderer/src/components/Sync/GridRow.js deleted file mode 100644 index f086dc2d9..000000000 --- a/renderer/src/components/Sync/GridRow.js +++ /dev/null @@ -1,47 +0,0 @@ -import React from 'react'; -import { classNames } from '@/util/classNames'; -import moment from 'moment'; -import FolderIcon from '@/icons/folder.svg'; - -function GridRow({ - title, lastSync, selected, isUpload, uploadPercentage = 0, - }) { - return ( - - <> -
- - - {title} - - - - {(lastSync && lastSync !== null) ? moment.utc(lastSync.lastSynced).local().startOf('seconds').fromNow() : '-'} - - -
- {isUpload && ( -
-
-
- )} - - - ); -} - -export default GridRow; diff --git a/renderer/src/components/Sync/GridRow.jsx b/renderer/src/components/Sync/GridRow.jsx new file mode 100644 index 000000000..00dab2300 --- /dev/null +++ b/renderer/src/components/Sync/GridRow.jsx @@ -0,0 +1,56 @@ +import React from 'react'; +import { classNames } from '@/util/classNames'; +import moment from 'moment'; +import FolderIcon from '@/icons/folder.svg'; + +function GridRow({ + title, + lastSync, + selected, + isUpload, + uploadPercentage = 0, +}) { + return ( + <> +
+ + + {title} + + + + {lastSync && lastSync !== null + ? moment + .utc(lastSync.lastSynced) + .local() + .startOf('seconds') + .fromNow() + : '-'} + +
+ {isUpload && ( +
+
+
+ )} + + ); +} + +export default GridRow; diff --git a/renderer/src/layouts/Sync/PopUpModal.js b/renderer/src/components/Sync/PopUpModal.jsx similarity index 100% rename from renderer/src/layouts/Sync/PopUpModal.js rename to renderer/src/components/Sync/PopUpModal.jsx diff --git a/renderer/src/components/Sync/Ag/ProjectFileBrowser.js b/renderer/src/components/Sync/Scribe/ProjectFileBrowser.js similarity index 97% rename from renderer/src/components/Sync/Ag/ProjectFileBrowser.js rename to renderer/src/components/Sync/Scribe/ProjectFileBrowser.js index d123ccf0a..b6976f836 100644 --- a/renderer/src/components/Sync/Ag/ProjectFileBrowser.js +++ b/renderer/src/components/Sync/Scribe/ProjectFileBrowser.js @@ -2,7 +2,7 @@ import { useContext, useEffect, } from 'react'; import GridRow from '../GridRow'; -import { SyncContext } from '../SyncContextProvider'; +import { SyncContext } from '../../context/SyncContext'; export default function ProjectFileBrowser() { const { diff --git a/renderer/src/components/Sync/Ag/SyncToGitea.js b/renderer/src/components/Sync/Scribe/SyncToGitea.js similarity index 100% rename from renderer/src/components/Sync/Ag/SyncToGitea.js rename to renderer/src/components/Sync/Scribe/SyncToGitea.js diff --git a/renderer/src/components/Sync/Ag/SyncToGiteaUtils.js b/renderer/src/components/Sync/Scribe/SyncToGiteaUtils.js similarity index 100% rename from renderer/src/components/Sync/Ag/SyncToGiteaUtils.js rename to renderer/src/components/Sync/Scribe/SyncToGiteaUtils.js diff --git a/renderer/src/modules/projects/Sync.js b/renderer/src/components/Sync/Sync.js similarity index 94% rename from renderer/src/modules/projects/Sync.js rename to renderer/src/components/Sync/Sync.js index 4ab5ba642..302d5cf38 100644 --- a/renderer/src/modules/projects/Sync.js +++ b/renderer/src/components/Sync/Sync.js @@ -1,8 +1,6 @@ import { useState, useContext } from 'react'; import { useTranslation } from 'react-i18next'; - import ProjectsLayout from '@/layouts/projects/Layout'; -// import Gitea from '@/components/Sync/Gitea/Gitea'; import AuthenticationContextProvider from '@/components/Login/AuthenticationContextProvider'; import ProjectContextProvider from '@/components/context/ProjectContext'; import ReferenceContextProvider from '@/components/context/ReferenceContext'; @@ -10,16 +8,16 @@ import { CloudArrowDownIcon, CloudArrowUpIcon, } from '@heroicons/react/24/outline'; -import ProjectFileBrowser from '@/components/Sync/Ag/ProjectFileBrowser'; -import Gitea from '@/components/Sync/Gitea/Gitea'; -import { SyncContext } from '@/components/Sync/SyncContextProvider'; import { SnackBar } from '@/components/SnackBar'; -import { uploadToGitea } from '@/components/Sync/Ag/SyncToGitea'; -import { downloadFromGitea } from '@/components/Sync/Gitea/SyncFromGitea'; import useAddNotification from '@/components/hooks/useAddNotification'; import ConfirmationModal from '@/layouts/editor/ConfirmationModal'; -import { cloneAndSetProject, updateSettingsFiles } from '@/components/Sync/Gitea/SyncFromGiteaUtils'; -import { checkoutJsonFiles, pullProject } from '@/components/Sync/Isomorphic/utils'; +import { SyncContext } from '../context/SyncContext'; +import { uploadToGitea } from './Scribe/SyncToGitea'; +import { downloadFromGitea } from './Gitea/SyncFromGitea'; +import { cloneAndSetProject, updateSettingsFiles } from './Gitea/SyncFromGiteaUtils'; +import { checkoutJsonFiles, pullProject } from './Isomorphic/utils'; +import Gitea from './Gitea/Gitea'; +import ProjectFileBrowser from './Scribe/ProjectFileBrowser'; import Door43Logo from '@/icons/door43.svg'; import * as logger from '../../logger'; @@ -81,7 +79,7 @@ export default function Sync() { // for pull without conflict const checkoutFIles = await checkoutJsonFiles(pullData.fs, pullData.gitprojectDir, pullData.checkoutBranch); const pullStatus = checkoutFIles && await pullProject(pullData.fs, pullData.gitprojectDir, pullData.userBranch, auth.token.sha1, pullData.checkoutBranch); - pullStatus?.status && await updateSettingsFiles( + pullStatus?.status && await updateSettingsFiles( pullData.fs, pullData.sbDataObject, pullData.projectDir, diff --git a/renderer/src/components/Sync/useSync.js b/renderer/src/components/Sync/hooks/useSync.js similarity index 93% rename from renderer/src/components/Sync/useSync.js rename to renderer/src/components/Sync/hooks/useSync.js index 761b6fbaa..5300854c1 100644 --- a/renderer/src/components/Sync/useSync.js +++ b/renderer/src/components/Sync/hooks/useSync.js @@ -1,8 +1,8 @@ import { useState, useEffect } from 'react'; import * as localForage from 'localforage'; -import * as logger from '../../logger'; -import fetchProjectsMeta from '../../core/projects/fetchProjectsMeta'; -import { getOrPutLastSyncInAgSettings } from './Ag/SyncToGiteaUtils'; +import * as logger from '../../../logger'; +import fetchProjectsMeta from '../../../core/projects/fetchProjectsMeta'; +import { getOrPutLastSyncInAgSettings } from '../Scribe/SyncToGiteaUtils'; function useSync() { const projectList = []; diff --git a/renderer/src/components/Sync/supportForExistingSyncUsers.js b/renderer/src/components/Sync/supportForExistingSyncUsers.js deleted file mode 100644 index 6bc108c50..000000000 --- a/renderer/src/components/Sync/supportForExistingSyncUsers.js +++ /dev/null @@ -1,3 +0,0 @@ -export const supportForExistingSyncUsers = async () => { -// cupport codes checka and resolve all -}; diff --git a/renderer/src/components/Sync/SyncContextProvider.js b/renderer/src/components/context/SyncContext.js similarity index 92% rename from renderer/src/components/Sync/SyncContextProvider.js rename to renderer/src/components/context/SyncContext.js index 955e4a583..e370d4ee0 100644 --- a/renderer/src/components/Sync/SyncContextProvider.js +++ b/renderer/src/components/context/SyncContext.js @@ -1,7 +1,7 @@ /* eslint-disable react/jsx-no-constructed-context-values */ import React, { createContext } from 'react'; import PropTypes from 'prop-types'; -import useSync from './useSync'; +import useSync from '../Sync/hooks/useSync'; export const SyncContext = createContext(); diff --git a/renderer/src/layouts/projects/Export/ExportProjectPopUp.js b/renderer/src/layouts/projects/Export/ExportProjectPopUp.js index 316254fbd..46969e530 100644 --- a/renderer/src/layouts/projects/Export/ExportProjectPopUp.js +++ b/renderer/src/layouts/projects/Export/ExportProjectPopUp.js @@ -16,7 +16,7 @@ import { validate } from '../../../util/validate'; import * as logger from '../../../logger'; import burrito from '../../../lib/BurritoTemplete.json'; import ConfirmationModal from '../../editor/ConfirmationModal'; -import ProgressCircle from '../../../components/Sync/ProgressCircle'; +import { ProgressCircle } from '../../../components/ProgressCircle'; import { exportDefaultAudio, exportFullAudio } from './ExportUtils'; import packageInfo from '../../../../../package.json';