RWKV-Runner/frontend/src/pages/Home.tsx

99 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-05-22 02:52:06 +00:00
import { CompoundButton, Link, Text } from '@fluentui/react-components';
import React, { FC, ReactElement } from 'react';
2023-05-13 12:15:18 +00:00
import banner from '../assets/images/banner.jpg';
2023-05-04 15:55:24 +00:00
import {
Chat20Regular,
DataUsageSettings20Regular,
DocumentSettings20Regular,
Storage20Regular
} from '@fluentui/react-icons';
2023-05-22 02:52:06 +00:00
import { useNavigate } from 'react-router';
import { observer } from 'mobx-react-lite';
import { RunButton } from '../components/RunButton';
2023-05-17 03:39:00 +00:00
import manifest from '../../../manifest.json';
2023-05-22 02:52:06 +00:00
import { BrowserOpenURL } from '../../wailsjs/runtime';
import { useTranslation } from 'react-i18next';
import { ConfigSelector } from '../components/ConfigSelector';
2023-05-19 14:18:38 +00:00
import MarkdownRender from '../components/MarkdownRender';
import commonStore from '../stores/commonStore';
2023-05-04 15:55:24 +00:00
2023-05-20 08:33:32 +00:00
export type IntroductionContent = { [lang: string]: string }
2023-05-04 15:55:24 +00:00
type NavCard = {
label: string;
desc: string;
path: string;
icon: ReactElement;
};
2023-05-16 05:22:57 +00:00
const navCards: NavCard[] = [
2023-05-04 15:55:24 +00:00
{
label: 'Chat',
desc: 'Go to chat page',
path: '/chat',
2023-05-22 02:52:06 +00:00
icon: <Chat20Regular />
2023-05-04 15:55:24 +00:00
},
{
label: 'Configs',
desc: 'Manage your configs',
path: '/configs',
2023-05-22 02:52:06 +00:00
icon: <DocumentSettings20Regular />
2023-05-04 15:55:24 +00:00
},
{
label: 'Models',
desc: 'Manage models',
path: '/models',
2023-05-22 02:52:06 +00:00
icon: <DataUsageSettings20Regular />
2023-05-04 15:55:24 +00:00
},
{
label: 'Train',
desc: '',
path: '/train',
2023-05-22 02:52:06 +00:00
icon: <Storage20Regular />
2023-05-04 15:55:24 +00:00
}
];
2023-05-07 14:48:52 +00:00
export const Home: FC = observer(() => {
2023-05-22 02:52:06 +00:00
const { t } = useTranslation();
2023-05-05 05:41:54 +00:00
const navigate = useNavigate();
2023-05-19 14:18:38 +00:00
const lang: string = commonStore.settings.language;
2023-05-05 05:41:54 +00:00
const onClickNavCard = (path: string) => {
2023-05-22 02:52:06 +00:00
navigate({ pathname: path });
2023-05-05 05:41:54 +00:00
};
2023-05-04 15:55:24 +00:00
return (
<div className="flex flex-col justify-between h-full">
2023-05-22 02:52:06 +00:00
<img className="rounded-xl select-none hidden sm:block" src={banner} />
2023-05-04 15:55:24 +00:00
<div className="flex flex-col gap-2">
2023-05-18 12:48:53 +00:00
<Text size={600} weight="medium">{t('Introduction')}</Text>
2023-05-19 14:18:38 +00:00
<div className="h-40 overflow-y-auto overflow-x-hidden p-1">
<MarkdownRender>
{lang in commonStore.introduction ? commonStore.introduction[lang] : commonStore.introduction['en']}
</MarkdownRender>
2023-05-06 12:17:39 +00:00
</div>
2023-05-04 15:55:24 +00:00
</div>
2023-05-06 12:17:39 +00:00
<div className="grid grid-cols-2 sm:grid-cols-4 gap-5">
2023-05-22 02:52:06 +00:00
{navCards.map(({ label, path, icon, desc }, index) => (
2023-05-18 12:48:53 +00:00
<CompoundButton icon={icon} secondaryContent={t(desc)} key={`${path}-${index}`} value={path}
2023-05-22 02:52:06 +00:00
size="large" onClick={() => onClickNavCard(path)}>
2023-05-18 12:48:53 +00:00
{t(label)}
2023-05-04 15:55:24 +00:00
</CompoundButton>
))}
</div>
2023-05-06 12:17:39 +00:00
<div className="flex flex-col gap-2">
<div className="flex flex-row-reverse sm:fixed bottom-2 right-2">
<div className="flex gap-3">
2023-05-22 02:52:06 +00:00
<ConfigSelector />
<RunButton />
2023-05-06 12:17:39 +00:00
</div>
</div>
2023-05-04 15:55:24 +00:00
<div className="flex gap-4 items-end">
2023-05-18 12:48:53 +00:00
{t('Version')}: {manifest.version}
<Link onClick={() => BrowserOpenURL('https://github.com/josStorer/RWKV-Runner')}>{t('Help')}</Link>
2023-05-04 15:55:24 +00:00
</div>
</div>
</div>
);
2023-05-07 14:48:52 +00:00
});