Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update main component and cleanup
Browse files Browse the repository at this point in the history
spaenleh committed Jan 23, 2024
1 parent 175f173 commit 1b04445
Showing 7 changed files with 36 additions and 59 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"@graasp/query-client": "2.3.0",
"@graasp/sdk": "3.4.1",
"@graasp/translations": "1.22.1",
"@graasp/ui": "4.3.1",
"@graasp/ui": "github:graasp/graasp-ui#636-update-main-comp",
"@mui/icons-material": "5.14.19",
"@mui/lab": "5.0.0-alpha.151",
"@mui/material": "5.14.19",
17 changes: 3 additions & 14 deletions src/components/item/ItemMain.tsx
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { Box, Divider, Typography, styled } from '@mui/material';
import { DiscriminatedItem } from '@graasp/sdk';
import { DrawerHeader } from '@graasp/ui';

import { DRAWER_WIDTH, RIGHT_MENU_WIDTH } from '../../config/constants';
import { RIGHT_MENU_WIDTH } from '../../config/constants';
import { useBuilderTranslation } from '../../config/i18n';
import { ITEM_MAIN_CLASS } from '../../config/selectors';
import { BUILDER } from '../../langs/constants';
@@ -13,10 +13,6 @@ import ItemMetadataContent from './ItemMetadataContent';
import ItemPanel from './ItemPanel';
import ItemHeader from './header/ItemHeader';

const Container = styled(Box)<{ open: boolean }>(({ open }) => ({
width: open ? `calc(100vw - ${DRAWER_WIDTH})` : '100vw',
}));

const StyledContainer = styled(Box)<{ open: boolean }>(({ theme, open }) => {
const openStyles = open
? {
@@ -29,14 +25,8 @@ const StyledContainer = styled(Box)<{ open: boolean }>(({ theme, open }) => {
: {};

return {
position: 'relative',
padding: theme.spacing(1, 2),
flexGrow: 1,
marginRight: 0,
width: 'unset',
// takes the whole screen height minus the header height approximatively
// this might have to change
minHeight: '85vh',
display: 'flex',
flexDirection: 'column',

@@ -62,11 +52,10 @@ const ItemMain = ({ id, children, item }: Props): JSX.Element => {
setIsItemMetadataMenuOpen,
isChatboxMenuOpen,
setIsChatboxMenuOpen,
isMainMenuOpen,
} = useLayoutContext();

return (
<Container id={id} className={ITEM_MAIN_CLASS} open={isMainMenuOpen}>
<Box id={id} className={ITEM_MAIN_CLASS}>
{isChatboxMenuOpen && (
<ItemPanel open={isChatboxMenuOpen}>
<DrawerHeader
@@ -105,7 +94,7 @@ const ItemMain = ({ id, children, item }: Props): JSX.Element => {

{children}
</StyledContainer>
</Container>
</Box>
);
};

62 changes: 24 additions & 38 deletions src/components/main/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Link } from 'react-router-dom';

import { Grid, Typography, styled } from '@mui/material';
import Box from '@mui/material/Box';
import { Stack, styled } from '@mui/material';

import { Context } from '@graasp/sdk';
import {
GraaspLogo,
Main as GraaspMain,
Platform,
PlatformSwitch,
@@ -15,8 +13,9 @@ import {
} from '@graasp/ui';

import { HOST_MAP } from '@/config/externalPaths';
import { useBuilderTranslation } from '@/config/i18n';
import { BUILDER } from '@/langs/constants';

import { APP_NAME, GRAASP_LOGO_HEADER_HEIGHT } from '../../config/constants';
import { HOME_PATH, ITEM_ID_PARAMS } from '../../config/paths';
import {
APP_NAVIGATION_PLATFORM_SWITCH_BUTTON_IDS,
@@ -35,7 +34,9 @@ const StyledLink = styled(Link)(() => ({
display: 'flex',
alignItems: 'center',
}));
type Props = { children: JSX.Element | (JSX.Element & string) };
const LinkComponent = ({ children }: { children: JSX.Element }) => (
<StyledLink to={HOME_PATH}>{children}</StyledLink>
);

// small converter for HOST_MAP into a usePlatformNavigation mapper
export const platformsHostsMap = defaultHostsMapper({
@@ -44,8 +45,11 @@ export const platformsHostsMap = defaultHostsMapper({
[Platform.Analytics]: HOST_MAP.analytics,
});

type Props = { children: JSX.Element | (JSX.Element & string) };

const Main = ({ children }: Props): JSX.Element => {
const { isMainMenuOpen, setIsMainMenuOpen } = useLayoutContext();
const { isMainMenuOpen } = useLayoutContext();
const { t } = useBuilderTranslation();

const itemId = useShortenURLParams(ITEM_ID_PARAMS);

@@ -69,47 +73,29 @@ const Main = ({ children }: Props): JSX.Element => {
},
};

const leftContent = (
<Box display="flex" ml={2}>
<StyledLink to={HOME_PATH}>
<GraaspLogo height={GRAASP_LOGO_HEADER_HEIGHT} sx={{ fill: 'white' }} />
<Typography variant="h6" color="inherit" mr={2} ml={1}>
{APP_NAME}
</Typography>
</StyledLink>
<PlatformSwitch
id={APP_NAVIGATION_PLATFORM_SWITCH_ID}
selected={Platform.Builder}
platformsProps={platformProps}
/>
</Box>
);

const rightContent = (
<Grid container>
<Grid item>
<NotificationButton />
</Grid>
<Grid item>
<UserSwitchWrapper />
</Grid>
</Grid>
<Stack direction="row" alignItems="center">
<NotificationButton />
<UserSwitchWrapper />
</Stack>
);

return (
<GraaspMain
context={Context.Builder}
handleDrawerOpen={() => {
setIsMainMenuOpen(true);
}}
handleDrawerClose={() => {
setIsMainMenuOpen(false);
}}
headerId={HEADER_APP_BAR_ID}
headerLeftContent={leftContent}
drawerOpenAriaLabel={t(BUILDER.ARIA_OPEN_DRAWER)}
headerRightContent={rightContent}
sidebar={<MainMenu />}
drawerContent={<MainMenu />}
open={isMainMenuOpen}
LinkComponent={LinkComponent}
PlatformComponent={
<PlatformSwitch
id={APP_NAVIGATION_PLATFORM_SWITCH_ID}
selected={Platform.Builder}
platformsProps={platformProps}
/>
}
>
<CookiesBanner />
{children}
1 change: 1 addition & 0 deletions src/langs/constants.ts
Original file line number Diff line number Diff line change
@@ -360,6 +360,7 @@ export const BUILDER = {
EMPTY_FOLDER_CHILDREN_FOR_THIS_ITEM: 'EMPTY_FOLDER_CHILDREN_FOR_THIS_ITEM',
TO_FOLDER: 'TO_FOLDER',
ROOT: 'ROOT',
ARIA_OPEN_DRAWER: 'ARIA_OPEN_DRAWER',
// temporary message
"You can also find the items of this page in ''My Graasp''. This page will be unavailable soon.":
"You can also find the items of this page in ''My Graasp''. This page will be unavailable soon.",
1 change: 1 addition & 0 deletions src/langs/en.json
Original file line number Diff line number Diff line change
@@ -301,6 +301,7 @@
"EMPTY_FOLDER_CHILDREN_FOR_THIS_ITEM": "This item does not contain any folder.",
"TO_FOLDER": "to {{name}}",
"ROOT": "Root",
"ARIA_OPEN_DRAWER": "open drawer",
"ITEM_SELECTION_NAVIGATION_RECENT_ITEMS": "Recent Items",
"ITEM_SELECTION_NAVIGATION_PARENT": "Move above"
}
3 changes: 2 additions & 1 deletion src/langs/fr.json
Original file line number Diff line number Diff line change
@@ -298,5 +298,6 @@
"SHORT_LINK_UNKNOWN_ERROR": "Il y a une erreur inconnue.",
"You can also find the items of this page in ''My Graasp''. This page will be unavailable soon.": "Les éléments de cette page sont aussi disponibles dans ''Mon Graasp''. Cette page ''Eléments Partagés'' sera bientôt indisponible.",
"ITEM_SELECTION_NAVIGATION_RECENT_ITEMS": "Éléments Récents",
"ITEM_SELECTION_NAVIGATION_PARENT": "Déplacer au-dessus"
"ITEM_SELECTION_NAVIGATION_PARENT": "Déplacer au-dessus",
"ARIA_OPEN_DRAWER": "ouvrir la bare latérale"
}
9 changes: 4 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1294,15 +1294,14 @@ __metadata:
languageName: node
linkType: hard

"@graasp/ui@npm:4.3.1":
"@graasp/ui@github:graasp/graasp-ui#636-update-main-comp":
version: 4.3.1
resolution: "@graasp/ui@npm:4.3.1"
resolution: "@graasp/ui@https://github.com/graasp/graasp-ui.git#commit=d693b30feb2c5aa8748dcb5dd569da97c02552ac"
dependencies:
"@graasp/sdk": "npm:3.4.1"
http-status-codes: "npm:2.3.0"
katex: "npm:0.16.9"
lodash.truncate: "npm:4.4.2"
qs: "npm:6.11.2"
quill-emoji: "npm:0.2.0"
react-cookie-consent: "npm:9.0.0"
react-quill: "npm:2.0.0-beta.4"
@@ -1331,7 +1330,7 @@ __metadata:
optional: true
ag-grid-react:
optional: true
checksum: b5cf0290dda520c2bd65c2834c415ac3d376569a2a2765f1b1bd855cb1a8e5d582c94213433383b8b632f598007d96a774cbacf10702f3c14f1def563e677409
checksum: 35be26f24bf4327ba8ae0d1f5eb7ab4c3908897121c0e11df518266430ed780f1dae184ed7edd1450e1a7944c36197b192c984284b14d65ea534da15cd642869
languageName: node
linkType: hard

@@ -6313,7 +6312,7 @@ __metadata:
"@graasp/query-client": "npm:2.3.0"
"@graasp/sdk": "npm:3.4.1"
"@graasp/translations": "npm:1.22.1"
"@graasp/ui": "npm:4.3.1"
"@graasp/ui": "github:graasp/graasp-ui#636-update-main-comp"
"@mui/icons-material": "npm:5.14.19"
"@mui/lab": "npm:5.0.0-alpha.151"
"@mui/material": "npm:5.14.19"

0 comments on commit 1b04445

Please sign in to comment.