Skip to content

Commit

Permalink
feat: UI Enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
ghimiresdp committed Mar 25, 2023
1 parent ea5476c commit 661eb0a
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 54 deletions.
10 changes: 8 additions & 2 deletions i18n.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"locales": ["en", "ja"],
"locales": [
"en",
"ja"
],
"defaultLocale": "ja",
"pages": {
"*": ["common"]
"*": [
"common",
"admin"
]
}
}
13 changes: 12 additions & 1 deletion locales/en/admin.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{}
{
"quest": {
"SELECT_SHEET": "Select Sheet",
"SELECT_SHEET_LABEL": "Select Sheet"
},
"tab": {
"SET_QUESTIONS": "Set Quests",
"MANAGE_STUDENTS": "Manage Students",
"STATISTICS": "Statistics",
"SETTINGS": "Settings"
}
}
4 changes: 4 additions & 0 deletions locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"QUESTION": "Question",
"SINGLE_SELECT": "Select single answer",
"SUBMIT": "Submit",
"faucet": {
"ADDRESS_LABEL": "Enter your wallet address",
"ADDRESS_HELP_TEXT": "Your wallet address must be whitelisted to get funds."
},
"nav": {
"ADMIN": "Admin",
"FAUCET": "Faucet",
Expand Down
13 changes: 12 additions & 1 deletion locales/ja/admin.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{}
{
"quests": {
"SELECT_SHEET": "Select Sheet",
"SELECT_SHEET_LABEL": "Select Sheet"
},
"tab": {
"SET_QUESTIONS": "Set Quests",
"MANAGE_STUDENTS": "Manage Students",
"STATISTICS": "Statistics",
"SETTINGS": "Settings"
}
}
32 changes: 20 additions & 12 deletions src/components/Answersheet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Alert, AlertIcon, Box,
Alert, AlertIcon, Badge, Box,
Button, Heading, Progress, Spacer, Stack, Tab, TabList, TabPanel, TabPanels, Tabs,
} from '@chakra-ui/react';
import { ArrowLeftIcon, ArrowRightIcon, CheckCircleIcon, QuestionIcon } from '@chakra-ui/icons';
Expand All @@ -12,6 +12,7 @@ export const AnswerSheet = (props: { quests: Quest[] }) => {
const [tabIndex, setTabIndex] = useState(0);
const { t } = useTranslation('common');
const [ans, setAns] = useState<Quest[]>(props.quests.map((q) => ({ ...q, answer: 0 })));
const answered = ans.filter(a => a.answer !== 0).length;

const handleTabsChange = (index: number) => {
setTabIndex(index);
Expand All @@ -21,36 +22,43 @@ export const AnswerSheet = (props: { quests: Quest[] }) => {
setAns([...ans.slice(0, tabIndex), { ...ans[tabIndex], answer: answer }, ...ans.slice(tabIndex + 1)]);
};
return (
<Box>
<Box py={5}>
<Stack direction={'row'} mb={5}>
<Spacer />
{/*<Button>Answers: {ans.map(a => a.answer?.toString(2).padStart(4, '0'))}</Button>*/}
<Button
leftIcon={<ArrowLeftIcon />}
borderLeftRadius={'full'}
width={'10em'}
colorScheme={'cyan'}
colorScheme={'blue'}
isDisabled={tabIndex == 0}
onClick={() => {
setTabIndex(tabIndex - 1);
}}>{t('PREVIOUS')}</Button>
}}>{t('PREVIOUS')}
</Button>
<Button width={'8em'} borderRadius={0}>{answered} / {ans.length}</Button>
<Button
rightIcon={<ArrowRightIcon />}
borderRightRadius={'full'}
width={'10em'}
colorScheme={'cyan'}
colorScheme={'blue'}
isDisabled={tabIndex === props.quests.length - 1}
onClick={() => {
setTabIndex(tabIndex + 1);
}}>{t('NEXT')}</Button>
<Button colorScheme={'red'}>{t('SUBMIT')}</Button>
}}>{t('NEXT')}
</Button>
<Spacer />

<Button colorScheme={'red'} width={'10em'}>{t('SUBMIT')}</Button>
</Stack>
<Progress hasStripe={true} colorScheme='cyan' min={0} max={props.quests.length - 1} size='sm' value={tabIndex}
<Progress hasStripe={true} colorScheme='pink' min={0} max={props.quests.length} size='xs' value={answered}
mb={5} />
<Tabs orientation={'vertical'} index={tabIndex} onChange={handleTabsChange}>
<TabList width={300}>
<TabList width={200} minWidth={200}>
{props.quests.map((_, idx) => (
<Tab key={`q_tab_${idx}`} justifyContent={'flex-start'}>
{(ans[idx].answer ?? 0) > 0 ?
<CheckCircleIcon mx={4} color={(ans[idx].answer ?? 0) > 0 ? 'green.500' : 'transparent'} /> :
<CheckCircleIcon mx={4} color={(ans[idx].answer ?? 0) > 0 ? 'blue.500' : 'transparent'} /> :
<QuestionIcon mx={4} color={'yellow.500'} />}
{t('QUESTION')} {idx + 1}
</Tab>
Expand All @@ -59,11 +67,11 @@ export const AnswerSheet = (props: { quests: Quest[] }) => {
<TabPanels>
{props.quests.map(({ question, selection, options, answer }, questionIndex) => (
<TabPanel key={`t_panel_${questionIndex}`}>
<Alert variant={'left-accent'} status={selection == 'single' ? 'info' : 'warning'} mb={5}>
<Alert variant={'subtle'} status={selection == 'single' ? 'info' : 'warning'} mb={5}>
<AlertIcon />
{selection === 'single' ? t('SINGLE_SELECT') : t('MULTI_SELECT')}
</Alert>
<Heading size={'lg'} mb={3}>{questionIndex + 1}. {question}</Heading>
<Heading size={'md'} mb={3}>{questionIndex + 1}. {question}</Heading>
<Box p={5}>
{selection === 'single' &&
<MultipleChoiceSingleSelect options={options} answer={answer} onAnswer={onAnswer} />}
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const RadioCard = (props: RadioCardProps) => {
<Box
bg={state.isChecked ? 'blue.500' : '#8887'}
borderColor={state.isChecked ? 'blue.500' : '#aaa3'}
borderRadius={props.square ? '6px' : '12px'} mr={3}
borderRadius={props.square ? 'md' : 'full'} mr={3}
w={'20px'} h={'20px'} minW={'20px'}
display={'flex'} alignItems={'center'} justifyContent={'center'}>
<CheckIcon boxSize={3} color={'white'} />
Expand Down
8 changes: 5 additions & 3 deletions src/components/admin/QuestionManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const QuestionManager = () => {
const [sheets, setSheets] = useState<string[]>([]);
const [activeSheet, setActiveSheet] = useState('');
const [questions, setQuestions] = useState<Quest[]>([]);
const { t } = useTranslation('common');
const { t } = useTranslation('admin');
const [sheetsLoading, setSheetsLoading] = useState(false);
const [sheetsError, setSheetsError] = useState(false);

Expand Down Expand Up @@ -47,8 +47,10 @@ export const QuestionManager = () => {
<>
<Stack mb={5} direction={'row'}>
{sheets.length > 0 && <Select
borderRadius={'1rem'} borderWidth={2} variant={'filled'} display={'block'} width={'300px'}
placeholder={'Select Sheet'}
// border={'2px solid'} borderColor={'whiteAlpha.500'}
// variant={'filled'}
width={'300px'} borderWidth={2}
placeholder={t('quest.SELECT_SHEET')}
isDisabled={sheetsLoading}
onChange={(event) => {
setActiveSheet(event.target.value);
Expand Down
3 changes: 0 additions & 3 deletions src/layouts/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Heading,
Box,
Link,
Flex,
Spacer,
useColorMode,
Expand All @@ -23,7 +22,6 @@ import useTranslation from 'next-translate/useTranslation';
import { default as NextLink } from 'next/link';
import { MoonIcon, SunIcon, HamburgerIcon, LockIcon, UnlockIcon, WarningIcon } from '@chakra-ui/icons';
import setLanguage from 'next-translate/setLanguage';
import Footer from '@/components/Footer';
import Head from 'next/head';
import { useAccount, useNetwork } from 'wagmi';
import { NavLink } from '@/components';
Expand Down Expand Up @@ -117,7 +115,6 @@ const Layout = ({ children }: LayoutProps) => {
</Alert>}
{children}
</Box>
<Footer />
</>
);
};
Expand Down
46 changes: 25 additions & 21 deletions src/pages/admin.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
Alert, AlertDescription, AlertIcon, AlertTitle, Box,
Button,
Container,
Grid,
GridItem, Heading,
Progress,
Spacer, Spinner,
Stack,
Heading, Icon,
Tab,
TabList, TabPanel,
TabPanels,
Expand All @@ -16,42 +9,53 @@ import useTranslation from 'next-translate/useTranslation';
import { useAccount, useNetwork } from 'wagmi';
import { QuestionManager } from '@/components/admin';
import { defaultChain } from '@/utils/contract';
import { FaFile, FaUsers, FaChartBar } from 'react-icons/fa';
import { SettingsIcon } from '@chakra-ui/icons';

const Admin = () => {
const { t } = useTranslation('common');
const { t } = useTranslation('admin');
const { address, connector, isConnected } = useAccount();
const { chain } = useNetwork();

const adminComponents = [
{
title: t('SETQUESTIONS'),
title: t('tab.SET_QUESTIONS'),
icon: FaFile,
component: <QuestionManager />,
},
{
title: t('Manage Students'),
title: t('tab.MANAGE_STUDENTS'),
icon: FaUsers,
component: <Heading>Manage Students</Heading>,
},
{
title: t('Statistics'),
title: t('tab.STATISTICS'),
icon: FaChartBar,
component: <Heading>Statistics</Heading>,
},
{
title: t('Settings'),
title: t('tab.SETTINGS'),
icon: SettingsIcon,
component: <Heading>Settings</Heading>,
},
];


return (
<>
{isConnected && chain?.id===defaultChain.id && <Tabs orientation={'vertical'} variant={'soft-rounded'} colorScheme={'blue'}>
<TabList width={300} minWidth={300}>
{adminComponents.map(({ title }, idx) => <Tab key={idx}>{title}</Tab>)}
</TabList>
<TabPanels>
{adminComponents.map(({ component }, idx) => <TabPanel key={idx}>{component}</TabPanel>)}
</TabPanels>
</Tabs>}
{isConnected && chain?.id === defaultChain.id &&
<Tabs orientation={'vertical'} variant={'unstyled'} colorScheme={'blue'}>
<TabList width={300} minWidth={300}>
{adminComponents.map(({ title, icon }, idx) => (
<Tab fontSize={'md'} key={idx} justifyContent={'flex-start'} _selected={{color: 'blue.500', fontWeight: 'bold'}}>
<Icon as={icon} mr={3} boxSize={5}/>
{title}
</Tab>))}
</TabList>
<TabPanels>
{adminComponents.map(({ component }, idx) => <TabPanel key={idx}>{component}</TabPanel>)}
</TabPanels>
</Tabs>}
</>

);
Expand Down
20 changes: 15 additions & 5 deletions src/pages/faucet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { Heading } from '@chakra-ui/react';
import { Container, FormControl, FormHelperText, FormLabel, Heading, Input } from '@chakra-ui/react';
import useTranslation from 'next-translate/useTranslation';

const FaucetPage = () =>{
return(
const FaucetPage = () => {
const { t } = useTranslation('common');
return (
<>
<Heading>Faucet</Heading>
<Container size={'xl'} py={10}>
<FormControl>
<FormLabel>{t('faucet.ADDRESS_LABEL')}</FormLabel>
<Input placeholder={'0x00000000000000000000'} size={'lg'} borderRadius={'full'}/>
<FormHelperText>{t('faucet.ADDRESS_HELP_TEXT')}</FormHelperText>
<FormHelperText>{t('faucet.ADDRESS_HELP_TEXT')}</FormHelperText>
</FormControl>
</Container>
</>
)
}
);
};
export default FaucetPage;
14 changes: 9 additions & 5 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import {
Stack,
} from '@chakra-ui/react';
import { ContractDetail } from '@/components/wallet';
import Footer from '@/components/Footer';

const Home = () => {
return (
<Box p={10}>
<Stack alignItems={"center"}>
<ContractDetail />
</Stack>
</Box>
<>
<Box p={10} minH={'70vh'}>
<Stack alignItems={'center'}>
<ContractDetail />
</Stack>
</Box>
<Footer />
</>
);
};

Expand Down

1 comment on commit 661eb0a

@vercel
Copy link

@vercel vercel bot commented on 661eb0a Mar 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cit-coin-ui – ./

cit-coin-ui-git-dev-pitpa.vercel.app
cit-coin-ui.vercel.app
cit-coin-ui-pitpa.vercel.app

Please sign in to comment.