Skip to content

Commit

Permalink
update uikit and refactor (#1330)
Browse files Browse the repository at this point in the history
* update uikit and refactor

* update ui kit

* add a translation key
  • Loading branch information
Thykof authored Mar 5, 2024
1 parent 531d35e commit c1649c9
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 47 deletions.
6 changes: 5 additions & 1 deletion web/massastation/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
extends: ['@massalabs', 'plugin:@tanstack/eslint-plugin-query/recommended'],
extends: [
'@massalabs',
'plugin:@tanstack/eslint-plugin-query/recommended',
'plugin:react-hooks/recommended',
],
plugins: ['html', '@tanstack/query'],
};
6 changes: 3 additions & 3 deletions web/massastation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions web/massastation/src/const/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const PLUGIN_STOP = 'stop';
export const PLUGIN_UPDATE = 'update';

export const isZipFile = /^(http)[^\s]*\.zip$/i;

export const THEME_STORAGE_KEY = 'massa-station-theme';
3 changes: 2 additions & 1 deletion web/massastation/src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"fe-error": "Please enter a valid url",
"be-error": "Failed to install plugin",
"button": "Install"
}
},
"beta": "beta"
},
"unexpected-error": {
"title": "Oops!",
Expand Down
10 changes: 7 additions & 3 deletions web/massastation/src/layouts/LayoutStation/LayoutStation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@massalabs/react-ui-kit';
import { useNavigate } from 'react-router-dom';
import Intl from '@/i18n/i18n';
import { THEME_STORAGE_KEY } from '@/const';

interface LayoutStationProps {
children?: ReactNode;
Expand Down Expand Up @@ -70,7 +71,7 @@ export function LayoutStation(props: LayoutStationProps) {
if (network.availableNetworks)
setAvailableNetworks(network.availableNetworks);
}
}, [isSuccessNetwork]);
}, [isSuccessNetwork, network, setCurrentNetwork, setAvailableNetworks]);

const selectedNetworkKey: number = parseInt(
Object.keys(availableNetworks).find(
Expand All @@ -94,7 +95,7 @@ export function LayoutStation(props: LayoutStationProps) {
if (isSuccessUpdateNetwork) {
navigate(0);
}
}, [isSuccessUpdateNetwork]);
}, [isSuccessUpdateNetwork, navigate]);

const availableNetworksItems = availableNetworks.map((network) => ({
item: network,
Expand Down Expand Up @@ -129,7 +130,10 @@ export function LayoutStation(props: LayoutStationProps) {
select={selectedNetworkKey}
/>
</div>
<ThemeMode onSetTheme={handleSetTheme} />
<ThemeMode
onSetTheme={handleSetTheme}
storageKey={THEME_STORAGE_KEY}
/>
</div>
</div>
{children}
Expand Down
2 changes: 2 additions & 0 deletions web/massastation/src/mirage/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { routesForAccounts } from './account';
import { routesForNetwork } from './network';
import { routesForPlugins } from './plugin';
import { routesForStore } from './store';
import { routesForVersion } from './version';

const handlers = {
accounts: routesForAccounts,
network: routesForNetwork,
plugins: routesForPlugins,
store: routesForStore,
version: routesForVersion,
};

export { handlers };
7 changes: 7 additions & 0 deletions web/massastation/src/mirage/handlers/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Server } from 'miragejs';

export function routesForVersion(server: Server) {
server.get('/version', () => {
return 'dev';
});
}
16 changes: 7 additions & 9 deletions web/massastation/src/pages/Base/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FiCodepen, FiGlobe, FiHome, FiSun, FiMoon } from 'react-icons/fi';
import { LayoutStation } from '@/layouts/LayoutStation/LayoutStation';

import { PAGES } from '@/const/pages/pages';
import { THEME_STORAGE_KEY } from '@/const';

type ThemeSettings = {
[key: string]: {
Expand Down Expand Up @@ -47,26 +48,23 @@ const navigatorSteps: INavigatorSteps = {
};

export function Base() {
// Hooks
const [theme, setThemeStorage] = useLocalStorage<Theme>(
'massa-station-theme',
THEME_STORAGE_KEY,
'theme-dark',
);

const { pathname } = useLocation();
const navigate = useNavigate();

useEffect(() => {
setActivePage(currentPage);
}, [pathname]);

// State
const currentPage = pathname.split('/').pop() || 'index';
const [activePage, setActivePage] = useState(currentPage);

// Store
const setThemeStore = useConfigStore((s) => s.setTheme);

useEffect(() => {
setActivePage(currentPage);
}, [setActivePage, pathname, currentPage]);

const navigator = (
<Navigator
items={[
Expand Down Expand Up @@ -121,7 +119,7 @@ export function Base() {
storedTheme={theme}
>
<Outlet />
<Toast />
<Toast storageKey={THEME_STORAGE_KEY} />
</LayoutStation>
</div>
);
Expand Down
59 changes: 59 additions & 0 deletions web/massastation/src/pages/Index/DashboardStation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Theme } from '@massalabs/react-ui-kit';

import { ReactNode, useEffect, useState } from 'react';

export interface IDashboardStationProps {
imagesDark: ReactNode[];
imagesLight: ReactNode[];
components: ReactNode[];
theme?: Theme | undefined;
}

export function DashboardStation(props: IDashboardStationProps) {
let { imagesDark, imagesLight, components, theme } = props;

const [images, setImages] = useState<ReactNode[]>([]);
const sizeClass = 'h-full w-full';

useEffect(() => {
let imageList: ReactNode[] = [...components];

const diff = imagesDark.length - components.length;
for (let i = 0; i < diff; i++) {
const imageToAdd =
theme === 'theme-dark' ? imagesDark[i] : imagesLight[i];
imageList.push(imageToAdd);
}

setImages(imageList);
}, [theme, components, imagesDark, imagesLight]);

return (
<div
className="grid lg:grid-cols-6 grid-cols-3 grid-rows-2 gap-8"
data-testid="dashboard-station"
>
<div className="col-span-2 row-span-2">
<div className={`${sizeClass}`}>{images[0]}</div>
</div>
<div className="col-start-3">
<div className={`${sizeClass}`}>{images[1]}</div>
</div>
<div className="col-start-3 row-start-2">
<div className={`${sizeClass}`}>{images[2]}</div>
</div>
<div className="row-start-3 lg:col-span-2 lg:row-span-2 lg:col-start-4 lg:row-start-1">
<div className={`${sizeClass}`}>{images[3]}</div>
</div>
<div className="col-start-1 row-start-4 lg:col-start-6 lg:row-start-1">
<div className={`${sizeClass}`}>{images[4]}</div>
</div>
<div
className="col-span-2 row-span-2 col-start-2 row-start-3
lg:col-span-1 lg:row-span-1 lg:col-start-6 lg:row-start-2"
>
<div className={`${sizeClass}`}>{images[5]}</div>
</div>
</div>
);
}
22 changes: 5 additions & 17 deletions web/massastation/src/pages/Index/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { ReactComponent as Image2Light } from '../../assets/subduedImages/light/
import { ReactComponent as Image3Light } from '../../assets/subduedImages/light/3.svg';
import { ReactComponent as Image4Light } from '../../assets/subduedImages/light/4.svg';
import { ReactComponent as Image5Light } from '../../assets/subduedImages/light/5.svg';
import {
Button,
DashboardStation,
PluginWallet,
Theme,
} from '@massalabs/react-ui-kit';
import { Button, PluginWallet } from '@massalabs/react-ui-kit';
import { FiCodepen, FiGlobe } from 'react-icons/fi';
import { useNavigate } from 'react-router-dom';
import { useEffect, useState } from 'react';
Expand All @@ -26,6 +21,7 @@ import { useConfigStore } from '@/store/store';
import { usePost, useResource } from '../../custom/api';
import { UseQueryResult } from '@tanstack/react-query';
import { MASSA_WALLET } from '@/const';
import { DashboardStation } from './DashboardStation';

export function Index() {
const plugins = useResource<MassaPluginModel[]>('plugin-manager');
Expand All @@ -50,14 +46,11 @@ function NestedIndex({
const navigate = useNavigate();
const [pluginWalletIsInstalled, setPluginWalletIsInstalled] = useState(false);
const [urlPlugin, setUrlPlugin] = useState<string | undefined>(undefined);
const [refreshPlugins, setRefreshPlugins] = useState(0);
const theme = useConfigStore((s) => s.theme);

const { data: massaPlugins } = plugins;

const { data: availablePlugins } =
useResource<MassaStoreModel[]>('plugin-store');

const availablePlugins = store.data;
const {
mutate: installPlugin,
isSuccess: installSuccess,
Expand All @@ -77,7 +70,7 @@ function NestedIndex({
);
setUrlPlugin(storeWalletPlugin?.file.url);
}
}, [plugins, store]);
}, [plugins, availablePlugins, massaPlugins]);

useEffect(() => {
// we should check that installed plugin is actually the wallet
Expand All @@ -89,10 +82,6 @@ function NestedIndex({
}
}, [installSuccess, installError]);

useEffect(() => {
setRefreshPlugins(refreshPlugins + 1);
}, [pluginWalletIsInstalled, isLoading]);

function handleInstallPlugin(url: string) {
const params = { source: url };
installPlugin({ params });
Expand Down Expand Up @@ -126,8 +115,7 @@ function NestedIndex({
</Button>
</div>
<DashboardStation
key={refreshPlugins}
theme={theme as Theme}
theme={theme}
imagesDark={[
<Image1Dark />,
<Image2Dark />,
Expand Down
2 changes: 1 addition & 1 deletion web/massastation/src/pages/Store/Install.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Install({
if (isSuccess) {
refetchPlugins();
}
}, [isSuccess]);
}, [isSuccess, refetchPlugins]);

return (
<SidePanel customClass="border-l border-c-default">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export function StationPlugin({
if (isExecuteSuccess) {
refetch();
}
}, [isExecuteSuccess]);
}, [isExecuteSuccess, refetch]);

useEffect(() => {
if (deleteSuccess) {
refetch();
}
}, [deleteSuccess]);
}, [deleteSuccess, refetch]);

function updatePluginState(e: SyntheticEvent, command: string) {
e.preventDefault();
Expand All @@ -83,7 +83,7 @@ export function StationPlugin({
subtitle: author,
tag:
pluginList.includes(name) && name === NODE_MANAGER ? (
<Tag type="warning" content="beta" />
<Tag type="warning">{Intl.t('store.beta')}</Tag>
) : null,
subtitleIcon: massalabsNomination.includes(author) ? <Certificate /> : null,
version: version,
Expand Down Expand Up @@ -127,9 +127,10 @@ export function StationPlugin({
content: [
<Tooltip
className="mas-tooltip"
content={Intl.t('store.crashed-module')}
icon={<FiAlertCircle className="text-s-error" />}
/>,
body={Intl.t('store.crashed-module')}
>
<FiAlertCircle className="text-s-error" />
</Tooltip>,
<Button variant="icon" disabled>
<FiArrowUpRight />
</Button>,
Expand Down
9 changes: 4 additions & 5 deletions web/massastation/src/pages/Store/StoreSection/StorePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ function StorePlugin(props: StorePluginProps) {
if (isInstallSuccess) {
refetch();
}
}, [isInstallSuccess]);
}, [isInstallSuccess, refetch]);

const incompatibleActions = [
<div className="relative whitespace-nowrap">
<Tooltip
content={warningMessage}
icon={<FiAlertTriangle className="text-s-warning" size={24} />}
/>
<Tooltip body={warningMessage}>
<FiAlertTriangle className="text-s-warning" size={24} />
</Tooltip>
</div>,
<FiDownload className="w-6 h-10 text-tertiary" />,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function StoreSection({
if (error) {
navigate(routeFor('error'));
}
}, [error]);
}, [error, navigate]);

return (
<>
Expand Down

0 comments on commit c1649c9

Please sign in to comment.