forked from graasp/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
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 refactor (graasp#491)
fix: some translations
- Loading branch information
Showing
23 changed files
with
333 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,50 @@ | ||
import { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { Alert, Skeleton, Typography } from '@mui/material'; | ||
|
||
import { Context } from '@graasp/sdk'; | ||
import { Main, useMobileView } from '@graasp/ui'; | ||
|
||
import { ROOT_ID_PATH } from '@/config/paths'; | ||
import { hooks } from '@/config/queryClient'; | ||
import { useItemContext } from '@/contexts/ItemContext'; | ||
import { LayoutContextProvider } from '@/contexts/LayoutContext'; | ||
import HeaderNavigation from '@/modules/header/HeaderNavigation'; | ||
import HeaderRightContent from '@/modules/header/HeaderRightContent'; | ||
import { PLAYER } from '@/langs/constants'; | ||
import SideContent from '@/modules/rightPanel/SideContent'; | ||
|
||
import Item from './Item'; | ||
import ItemNavigation from './ItemNavigation'; | ||
|
||
const MainScreen = (): JSX.Element => { | ||
const { isMobile } = useMobileView(); | ||
|
||
const MainScreen = (): JSX.Element | null => { | ||
const rootId = useParams()[ROOT_ID_PATH]; | ||
const { focusedItemId } = useItemContext(); | ||
const mainId = focusedItemId || rootId; | ||
const { data: item, isLoading, isError } = hooks.useItem(mainId); | ||
const { t } = useTranslation(); | ||
const [topItemName, setTopItemName] = useState(''); | ||
const [isFirstItem, setIsFirstItem] = useState(true); | ||
|
||
if (isLoading) { | ||
return <Skeleton variant="rectangular" width="100%" />; | ||
} | ||
|
||
if (!item || isError) { | ||
// todo: add this to translations | ||
return <Alert severity="error">{t('This item does not exist')}</Alert>; | ||
} | ||
|
||
if (isFirstItem) { | ||
setTopItemName(item.name); | ||
setIsFirstItem(false); | ||
} | ||
|
||
const content = !rootId ? ( | ||
const content = rootId ? ( | ||
<Item id={mainId} /> | ||
) : ( | ||
<Typography align="center" variant="h4"> | ||
{t('No item defined.')} | ||
</Typography> | ||
) : ( | ||
<Item id={mainId} /> | ||
); | ||
|
||
return ( | ||
<Main | ||
open={!isMobile && Boolean(rootId)} | ||
context={Context.Player} | ||
sidebar={<ItemNavigation />} | ||
headerLeftContent={ | ||
<HeaderNavigation rootId={rootId} topItemName={topItemName} /> | ||
} | ||
headerRightContent={<HeaderRightContent />} | ||
> | ||
if (item) { | ||
return ( | ||
<LayoutContextProvider> | ||
<SideContent item={item} content={content} /> | ||
</LayoutContextProvider> | ||
</Main> | ||
); | ||
); | ||
} | ||
|
||
if (isLoading) { | ||
return <Skeleton variant="rectangular" width="100%" />; | ||
} | ||
|
||
if (isError) { | ||
// todo: add this to translations | ||
return <Alert severity="error">{t(PLAYER.ERROR_FETCHING_ITEM)}</Alert>; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default MainScreen; |
Oops, something went wrong.