From fee0bf4beecbd4bac2f898bd541a8a00ead0ae5d Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Mon, 12 Apr 2021 23:17:00 +0800 Subject: [PATCH] feat: TokenForm for preference and create workspace --- .vscode/settings.json | 1 + src/components/TokenForm/index.tsx | 66 ++++++++++++-------------- src/pages/AddWorkspace/index.tsx | 75 ++++++++++++++++++++++-------- src/pages/Preferences/index.tsx | 17 +------ 4 files changed, 88 insertions(+), 71 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6d55e930..57e7a8fd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "Asyncify", "dugite", "fullscreenable", + "gitee", "maximizable", "minimizable", "submenu", diff --git a/src/components/TokenForm/index.tsx b/src/components/TokenForm/index.tsx index 6c648a32..6a4cd0e4 100644 --- a/src/components/TokenForm/index.tsx +++ b/src/components/TokenForm/index.tsx @@ -1,53 +1,47 @@ import React, { useState, useEffect } from 'react'; import styled from 'styled-components'; -import { Paper, Typography, Tabs, Tab, TabPanel } from '@material-ui/core'; -import SearchRepo from '@/components/github/SearchRepo'; +import { Tab, ListItemText } from '@material-ui/core'; +import { TabPanel, TabContext, TabList } from '@material-ui/lab'; import { SupportedStorageServices } from '@services/types'; +import { useTranslation } from 'react-i18next'; -const Container = styled(Paper)` - margin-top: 5px; +const Container = styled.div` + width: 100%; + display: flex; + flex-direction: column; `; -const GithubRepoLink = styled(Typography)` - cursor: pointer; - opacity: 50%; - &:hover { - opacity: 100%; - } +const TabsContainer = styled.div` + display: flex; + flex-direction: row; `; -const a11yProps = ( - index: SupportedStorageServices, -): { - id: string; - 'aria-controls': string; -} => ({ - id: index, - 'aria-controls': `simple-tabpanel-${index}`, -}); - /** * Create storage provider's token. * @returns */ export function TokenForm(): JSX.Element { + const { t } = useTranslation(); const [currentTab, currentTabSetter] = useState(SupportedStorageServices.github); return ( - - currentTabSetter(newValue)} - aria-label="Vertical tabs example"> - - - - - Item One - - - Item Two - + + + + + currentTabSetter(newValue as SupportedStorageServices)} + orientation="vertical" + variant="scrollable" + value={currentTab} + aria-label="Vertical tabs example"> + + + + + Item One + Item Two + Item Two + + ); } diff --git a/src/pages/AddWorkspace/index.tsx b/src/pages/AddWorkspace/index.tsx index 74ff78a1..5db2cde6 100644 --- a/src/pages/AddWorkspace/index.tsx +++ b/src/pages/AddWorkspace/index.tsx @@ -1,12 +1,15 @@ import React, { useState } from 'react'; import styled from 'styled-components'; import { GraphQLClient, ClientContext } from 'graphql-hooks'; +import { useTranslation } from 'react-i18next'; +import { AppBar, Paper, Tab } from '@material-ui/core'; +import { TabPanel as TabPanelRaw, TabContext, TabList } from '@material-ui/lab'; import { GITHUB_GRAPHQL_API } from '../../constants/auth'; import { TokenForm } from '@/components/TokenForm'; -import { Description } from './Description'; +import { MainSubWikiDescription, SyncedWikiDescription } from './Description'; import { NewWikiForm } from './NewWikiForm'; import { NewWikiDoneButton } from './NewWikiDoneButton'; @@ -15,8 +18,13 @@ import { ExistedWikiDoneButton } from './ExistedWikiDoneButton'; import { CloneWikiForm } from './CloneWikiForm'; import { CloneWikiDoneButton } from './CloneWikiDoneButton'; -import { TabBar, CreateWorkspaceTabs } from './TabBar'; -import { useIsCreateMainWorkspace, useWikiWorkspaceForm } from './useForm'; +import { useIsCreateMainWorkspace, useIsCreateSyncedWorkspace, useWikiWorkspaceForm } from './useForm'; + +enum CreateWorkspaceTabs { + CloneOnlineWiki = 'CloneOnlineWiki', + CreateNewWiki = 'CreateNewWiki', + OpenLocalWiki = 'OpenLocalWiki', +} const graphqlClient = new GraphQLClient({ url: GITHUB_GRAPHQL_API, @@ -30,38 +38,65 @@ const Container = styled.main` width: 0; } `; +const TokenFormContainer = styled(Paper)` + margin-top: 10px; + padding: 5px 10px; +`; +TokenFormContainer.defaultProps = { + square: true, + elevation: 2, +}; +const TabPanel = styled(TabPanelRaw)` + margin-top: 10px; + padding: 0 !important; +`; export default function AddWorkspace(): JSX.Element { + const { t } = useTranslation(); const [currentTab, currentTabSetter] = useState(CreateWorkspaceTabs.CreateNewWiki); + const [isCreateSyncedWorkspace, isCreateSyncedWorkspaceSetter] = useIsCreateSyncedWorkspace(); const [isCreateMainWorkspace, isCreateMainWorkspaceSetter] = useIsCreateMainWorkspace(); const form = useWikiWorkspaceForm(); return ( - - + + + + currentTabSetter(newValue as CreateWorkspaceTabs)} + variant="scrollable" + value={currentTab} + aria-label={t('AddWorkspace.SwitchCreateNewOrOpenExisted')}> + + + + + + - + + + + - {currentTab === 'CreateNewWiki' && ( - - - - - )} - {currentTab === 'OpenLocalWiki' && ( - + + + + + + + + - - )} - {currentTab === 'CloneOnlineWiki' && ( - + + - - )} + + ); } diff --git a/src/pages/Preferences/index.tsx b/src/pages/Preferences/index.tsx index 46693546..e3ed95e8 100644 --- a/src/pages/Preferences/index.tsx +++ b/src/pages/Preferences/index.tsx @@ -31,7 +31,7 @@ import { hunspellLanguagesMap } from '../../constants/hunspell-languages'; import webcatalogLogo from '@/images/webcatalog-logo.svg'; import translatiumLogo from '@/images/translatium-logo.svg'; -import { GithubTokenForm } from '../../components/github/git-token-form'; +import { TokenForm } from '../../components/TokenForm'; import { IPossibleWindowMeta, WindowMeta, WindowNames } from '@services/windows/WindowProperties'; import { IPreferences, PreferenceSections } from '@services/preferences/interface'; import { usePreferenceSections } from './useSections'; @@ -90,16 +90,6 @@ const Paper = styled(PaperRaw)<{ dark?: 0 | 1 }>` border: ${({ dark }) => (dark === 1 ? 'none' : '1px solid rgba(0, 0, 0, 0.12)')}; `; -const TokenContainer = styled.div` - margin-top: 10px; - margin-bottom: 10px; - display: flex; - justify-content: space-around; - flex-direction: column; - width: 200px; - min-width: 200px; -`; - const TimePickerContainer = styled.div` margin-top: 10px; margin-bottom: 10px; @@ -257,10 +247,7 @@ export default function Preferences(): JSX.Element { - - - - +