refactor: make "clone wiki" the first tab

This commit is contained in:
tiddlygit-test 2020-08-15 18:32:54 +08:00
parent 5396df24af
commit d8cd3cfcac
3 changed files with 28 additions and 13 deletions

View file

@ -59,7 +59,7 @@ const previousToken = getGithubToken();
previousToken && setHeaderToGraphqlClient(previousToken); previousToken && setHeaderToGraphqlClient(previousToken);
export default function AddWorkspace() { export default function AddWorkspace() {
const [currentTab, currentTabSetter] = useState(0); const [currentTab, currentTabSetter] = useState('CloneOnlineWiki');
const [isCreateMainWorkspace, isCreateMainWorkspaceSetter] = useState(countWorkspace() === 0); const [isCreateMainWorkspace, isCreateMainWorkspaceSetter] = useState(countWorkspace() === 0);
const [parentFolderLocation, parentFolderLocationSetter] = useState(getDesktopPath()); const [parentFolderLocation, parentFolderLocationSetter] = useState(getDesktopPath());
const [existedFolderLocation, existedFolderLocationSetter] = useState(getDesktopPath()); const [existedFolderLocation, existedFolderLocationSetter] = useState(getDesktopPath());
@ -138,6 +138,7 @@ export default function AddWorkspace() {
accessToken={accessToken} accessToken={accessToken}
githubWikiUrlSetter={githubWikiUrlSetter} githubWikiUrlSetter={githubWikiUrlSetter}
userInfo={userInfo} userInfo={userInfo}
wikiFolderNameSetter={wikiFolderNameSetter}
isCreateMainWorkspace={isCreateMainWorkspace} isCreateMainWorkspace={isCreateMainWorkspace}
/> />
</SyncContainer> </SyncContainer>
@ -152,7 +153,7 @@ export default function AddWorkspace() {
/> />
{syncContainer} {syncContainer}
{currentTab === 0 && ( {currentTab === 'CreateNewWiki' && (
<Container> <Container>
<NewWikiPathForm <NewWikiPathForm
parentFolderLocation={parentFolderLocation} parentFolderLocation={parentFolderLocation}
@ -177,7 +178,7 @@ export default function AddWorkspace() {
/> />
</Container> </Container>
)} )}
{currentTab === 1 && ( {currentTab === 'OpenLocalWiki' && (
<Container> <Container>
<ExistedWikiPathForm <ExistedWikiPathForm
existedFolderLocationSetter={existedFolderLocationSetter} existedFolderLocationSetter={existedFolderLocationSetter}
@ -201,7 +202,7 @@ export default function AddWorkspace() {
/> />
</Container> </Container>
)} )}
{currentTab === 2 && ( {currentTab === 'CloneOnlineWiki' && (
<Container> <Container>
<NewWikiPathForm <NewWikiPathForm
parentFolderLocation={parentFolderLocation} parentFolderLocation={parentFolderLocation}

View file

@ -65,6 +65,7 @@ type Props = {|
accessToken?: string, accessToken?: string,
githubWikiUrl: string, githubWikiUrl: string,
githubWikiUrlSetter: string => void, githubWikiUrlSetter: string => void,
wikiFolderNameSetter: string => void,
userInfo?: IUserInfo, userInfo?: IUserInfo,
isCreateMainWorkspace: boolean, isCreateMainWorkspace: boolean,
|}; |};
@ -72,6 +73,7 @@ export default function SearchRepo({
accessToken, accessToken,
githubWikiUrl, githubWikiUrl,
githubWikiUrlSetter, githubWikiUrlSetter,
wikiFolderNameSetter,
userInfo, userInfo,
isCreateMainWorkspace, isCreateMainWorkspace,
}: Props) { }: Props) {
@ -148,7 +150,10 @@ export default function SearchRepo({
<ListItem <ListItem
button button
key={url} key={url}
onClick={() => githubWikiUrlSetter(url)} onClick={() => {
githubWikiUrlSetter(url);
wikiFolderNameSetter(name);
}}
selected={trim(githubWikiUrl) === trim(url)} selected={trim(githubWikiUrl) === trim(url)}
> >
<ListItemIcon> <ListItemIcon>

View file

@ -1,5 +1,6 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { invert } from 'lodash';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import Paper from '@material-ui/core/Paper'; import Paper from '@material-ui/core/Paper';
@ -9,28 +10,36 @@ import Tab from '@material-ui/core/Tab';
function a11yProps(index) { function a11yProps(index) {
return { return {
id: `simple-tab-${index}`, id: index,
'aria-controls': `simple-tabpanel-${index}`, 'aria-controls': `simple-tabpanel-${index}`,
}; };
} }
const tabIndexMap = {
CloneOnlineWiki: 0,
CreateNewWiki: 1,
OpenLocalWiki: 2,
};
export interface IProps { export interface IProps {
currentTab: number; currentTab: string;
currentTabSetter: number => void; currentTabSetter: string => void;
} }
export default function TabBar({ currentTab, currentTabSetter }: IProps) { export default function TabBar({ currentTab, currentTabSetter }: IProps) {
const { t } = useTranslation(); const { t } = useTranslation();
// DEBUG: console
console.log(`currentTab`, currentTab);
return ( return (
<AppBar position="static"> <AppBar position="static">
<Paper square> <Paper square>
<Tabs <Tabs
value={currentTab} value={tabIndexMap[currentTab]}
onChange={(event, newValue) => currentTabSetter(newValue)} onChange={(event, newValue) => currentTabSetter(invert(tabIndexMap)[newValue])}
aria-label={t('AddWorkspace.SwitchCreateNewOrOpenExisted')} aria-label={t('AddWorkspace.SwitchCreateNewOrOpenExisted')}
> >
<Tab label={t('AddWorkspace.CreateNewWiki')} {...a11yProps(0)} /> <Tab label={t('AddWorkspace.CloneOnlineWiki')} {...a11yProps('CloneOnlineWiki')} />
<Tab label={t('AddWorkspace.OpenLocalWiki')} {...a11yProps(1)} /> <Tab label={t('AddWorkspace.CreateNewWiki')} {...a11yProps('CreateNewWiki')} />
<Tab label={t('AddWorkspace.CloneOnlineWiki')} {...a11yProps(2)} /> <Tab label={t('AddWorkspace.OpenLocalWiki')} {...a11yProps('OpenLocalWiki')} />
</Tabs> </Tabs>
</Paper> </Paper>
</AppBar> </AppBar>