From 0236c4a67d544a701a9f5967988984df4d7c6e21 Mon Sep 17 00:00:00 2001 From: samueljd Date: Tue, 5 Sep 2023 18:55:59 +0530 Subject: [PATCH] Porject list refactor --- app/newproject/page.js | 2 +- app/projects/page.jsx | 4 +- jsconfig.json | 7 +- renderer/pages/newproject.js | 2 +- renderer/pages/projects.js | 8 +- renderer/src/Home.js | 2 +- renderer/src/WebHome.js | 2 +- renderer/src/components/Login/Signin.js | 2 + .../src/components/Projects/CustomList.js | 73 +++ .../components/Projects/EnhancedTableHead.js | 187 ++++++ .../src/components/Projects/ImportPopUp.js | 337 +++++++++++ .../Projects/ImportPopUp.module.css | 7 + .../Projects}/NewProject.js | 2 +- .../Projects}/NewWebProject.js | 0 .../src/components/Projects/ProjectList.js | 106 ++++ .../src/components/Projects/ProjectRow.js | 210 +++++++ .../Projects}/SearchTags.js | 12 +- .../Projects/hooks/useEditProject.js | 63 +++ .../Projects/hooks/useSelectProject.js | 36 ++ .../Projects/utils/SortingHelper.js | 64 +++ .../CreateProject/AdvancedSettingsDropdown.js | 2 +- renderer/src/components/Signup/WebSignup.js | 4 - .../src/components/context/ProjectContext.js | 2 +- .../hooks/projects/useProjectsSort.js | 411 ++++---------- renderer/src/modules/projects/ProjectList.js | 496 ---------------- renderer/src/modules/projects/ProjectsNav.js | 29 - .../src/modules/projects/WebProjectList.js | 533 ------------------ .../modules/projects/hooks/useEditProject.js | 62 ++ .../projects/hooks/useSelectProject.js | 36 ++ supabase.js | 50 +- 30 files changed, 1340 insertions(+), 1411 deletions(-) create mode 100644 renderer/src/components/Projects/CustomList.js create mode 100644 renderer/src/components/Projects/EnhancedTableHead.js create mode 100644 renderer/src/components/Projects/ImportPopUp.js create mode 100644 renderer/src/components/Projects/ImportPopUp.module.css rename renderer/src/{modules/projects => components/Projects}/NewProject.js (99%) rename renderer/src/{modules/projects => components/Projects}/NewWebProject.js (100%) create mode 100644 renderer/src/components/Projects/ProjectList.js create mode 100644 renderer/src/components/Projects/ProjectRow.js rename renderer/src/{modules/projects => components/Projects}/SearchTags.js (91%) create mode 100644 renderer/src/components/Projects/hooks/useEditProject.js create mode 100644 renderer/src/components/Projects/hooks/useSelectProject.js create mode 100644 renderer/src/components/Projects/utils/SortingHelper.js delete mode 100644 renderer/src/modules/projects/ProjectList.js delete mode 100644 renderer/src/modules/projects/ProjectsNav.js delete mode 100644 renderer/src/modules/projects/WebProjectList.js create mode 100644 renderer/src/modules/projects/hooks/useEditProject.js create mode 100644 renderer/src/modules/projects/hooks/useSelectProject.js diff --git a/app/newproject/page.js b/app/newproject/page.js index 617bebfc2..aea0cfe49 100644 --- a/app/newproject/page.js +++ b/app/newproject/page.js @@ -1,5 +1,5 @@ import ProtectedRoute from '@/components/Protected'; -import NewWebProject from '@/modules/projects/NewWebProject'; +import NewWebProject from '@/components/Projects/NewWebProject'; const newproject = () => ( diff --git a/app/projects/page.jsx b/app/projects/page.jsx index c938d1b54..3f93376ee 100644 --- a/app/projects/page.jsx +++ b/app/projects/page.jsx @@ -1,4 +1,6 @@ -import ProjectList from '@/modules/projects/WebProjectList'; +'use client'; + +import ProjectList from '@/components/Projects/ProjectList'; import ProtectedRoute from '@/components/Protected'; const projects = () => ( diff --git a/jsconfig.json b/jsconfig.json index a19b392f1..f94e0cddc 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,8 +1,6 @@ { "compilerOptions": { "baseUrl": ".", - "resolveJsonModule": true, - "esModuleInterop": true, "paths": { "@/icons/*": [ "public/icons/*" @@ -25,6 +23,9 @@ "@/util/*": [ "renderer/src/util/*" ], + "@/app/*": [ + "app/*" + ], } } -} +} \ No newline at end of file diff --git a/renderer/pages/newproject.js b/renderer/pages/newproject.js index f4a44725d..7aba5fb9a 100644 --- a/renderer/pages/newproject.js +++ b/renderer/pages/newproject.js @@ -1,4 +1,4 @@ -import NewProject from '@/modules/projects/NewProject'; +import NewProject from '@/components/Projects/NewProject'; import AuthenticationContextProvider from '@/components/Login/AuthenticationContextProvider'; import ProjectContextProvider from '@/components/context/ProjectContext'; import AutographaContextProvider from '@/components/context/AutographaContext'; diff --git a/renderer/pages/projects.js b/renderer/pages/projects.js index 2dcd20e2b..f880b0da9 100644 --- a/renderer/pages/projects.js +++ b/renderer/pages/projects.js @@ -1,9 +1,9 @@ -import ProjectList from '@/modules/projects/ProjectList'; +import ProjectList from '@/components/Projects/ProjectList'; import AuthenticationContextProvider from '@/components/Login/AuthenticationContextProvider'; import AutographaContextProvider from '@/components/context/AutographaContext'; import ProjectContextProvider from '@/components/context/ProjectContext'; -const projects = () => ( +const Projects = () => ( @@ -11,6 +11,6 @@ const projects = () => ( -); + ); -export default projects; +export default Projects; diff --git a/renderer/src/Home.js b/renderer/src/Home.js index b51891b6f..d5e337410 100644 --- a/renderer/src/Home.js +++ b/renderer/src/Home.js @@ -2,13 +2,13 @@ /* eslint-disable react/jsx-no-useless-fragment */ import { useContext, useState, useEffect } from 'react'; +import ProjectList from '@/components/Projects/ProjectList'; import Login from './components/Login/Login'; import AuthenticationContextProvider, { AuthenticationContext } from './components/Login/AuthenticationContextProvider'; import { loadUsers } from './core/Login/handleJson'; import ProjectContextProvider from './components/context/ProjectContext'; import ReferenceContextProvider from './components/context/ReferenceContext'; import * as logger from './logger'; -import ProjectList from './modules/projects/ProjectList'; import AutographaContextProvider from './components/context/AutographaContext'; import { getorPutAppLangage } from './core/projects/handleProfile'; import i18n from './translations/i18n'; diff --git a/renderer/src/WebHome.js b/renderer/src/WebHome.js index 3cf91c8f5..2b769078f 100644 --- a/renderer/src/WebHome.js +++ b/renderer/src/WebHome.js @@ -14,7 +14,7 @@ const WebHome = () => { useEffect(() => { const checkSession = async () => { const data = await getSupabaseSession(); - if (data.session) { + if (data.session.user) { setSession(data.session); const appLangCode = await getorPutAppLangage('get', data.session.user.email); if (i18n.language !== appLangCode) { diff --git a/renderer/src/components/Login/Signin.js b/renderer/src/components/Login/Signin.js index 65be379cc..a9b7db2f3 100644 --- a/renderer/src/components/Login/Signin.js +++ b/renderer/src/components/Login/Signin.js @@ -21,6 +21,8 @@ const SignIn = () => { if (data.session) { console.log('sign in success', data); await localforage.setItem('userProfile', data); + const userData = await localforage.getItem('userProfile'); + console.log({ userData }); router.push('/projects'); setLoading(false); } else { diff --git a/renderer/src/components/Projects/CustomList.js b/renderer/src/components/Projects/CustomList.js new file mode 100644 index 000000000..a08a9c798 --- /dev/null +++ b/renderer/src/components/Projects/CustomList.js @@ -0,0 +1,73 @@ +import React, { Fragment } from 'react'; +import PropTypes from 'prop-types'; +import { Listbox, Transition } from '@headlessui/react'; +import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/24/solid'; +import { classNames } from '../../util/classNames'; + +export default function CustomList({ + selected, setSelected, options, show, width, +}) { + const dropdownWidth = width ?? 40; + return ( + +
+ + {selected?.title} + + + + + + {options.map((option) => ( + `${active ? 'text-amber-900 bg-amber-100' : 'text-gray-900'} + cursor-default select-none relative py-2 pl-10 pr-4 hover:bg-gray-200`} + value={option} + > + {({ selected, active }) => ( + <> + + {option.title} + + {selected ? ( + + + ) : null} + + )} + + ))} + + +
+
+ ); +} + +CustomList.propTypes = { + selected: PropTypes.object, + setSelected: PropTypes.func, + options: PropTypes.array, + show: PropTypes.bool, + width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), +}; diff --git a/renderer/src/components/Projects/EnhancedTableHead.js b/renderer/src/components/Projects/EnhancedTableHead.js new file mode 100644 index 000000000..4f028d42d --- /dev/null +++ b/renderer/src/components/Projects/EnhancedTableHead.js @@ -0,0 +1,187 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { + TableSortLabel, + TableCell, +} from '@material-ui/core'; +import { + StarIcon, +} from '@heroicons/react/24/outline'; +import i18n from '../../translations/i18n'; + +// import { Menu, Transition } from '@headlessui/react'; + +const headCells = [ + { + // id: 'name', numeric: false, disablePadding: true, label: 'Project Name', + id: 'name', numeric: false, disablePadding: true, label: i18n.t('label-project-name'), + }, + { + id: 'language', numeric: false, disablePadding: true, label: i18n.t('label-language'), + }, + { + // id: 'type', numeric: false, disablePadding: true, label: 'Flavor', + id: 'type', numeric: false, disablePadding: true, label: i18n.t('label-flavour'), + }, + { + id: 'date', numeric: true, disablePadding: false, label: i18n.t('label-created-date'), + }, + { + id: 'view', numeric: true, disablePadding: false, label: i18n.t('label-last-viewed'), + }, + // { + // id: 'editors', numeric: false, disablePadding: false, label: 'Editors', + // }, + // { + // id: 'more', numeric: false, disablePadding: false, label: '', + // }, +]; + +function EnhancedTableHead(props) { + const { + order, orderBy, onRequestSort, + } = props; + const createSortHandler = (property) => (event) => { + onRequestSort(event, property); + }; + + return ( + + + +