This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
generated from graasp/graasp-repo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from graasp/15/home
15/home
- Loading branch information
Showing
9 changed files
with
690 additions
and
598 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Card from '@material-ui/core/Card'; | ||
import { useHistory } from 'react-router'; | ||
import { ItemIcon } from '@graasp/ui'; | ||
import PropTypes from 'prop-types'; | ||
import CardContent from '@material-ui/core/CardContent'; | ||
import truncate from 'lodash.truncate'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import CardActionArea from '@material-ui/core/CardActionArea'; | ||
import { buildMainPath } from '../../config/paths'; | ||
import { ITEM_CARD_MAX_LENGTH } from '../../config/constants'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
bullet: { | ||
display: 'inline-block', | ||
margin: '0 2px', | ||
transform: 'scale(0.8)', | ||
}, | ||
title: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
iconClass: { | ||
marginRight: theme.spacing(1), | ||
}, | ||
})); | ||
|
||
const SimpleCard = ({ item }) => { | ||
const classes = useStyles(); | ||
const { push } = useHistory(); | ||
|
||
const onClick = () => { | ||
push(buildMainPath({ rootId: item.id, id: null })); | ||
}; | ||
return ( | ||
<Card className={classes.root}> | ||
<CardActionArea onClick={onClick}> | ||
<CardContent> | ||
<Typography variant="h5" component="h2" className={classes.title}> | ||
<ItemIcon | ||
type={item.type} | ||
extra={item.extra} | ||
name={item.name} | ||
iconClass={classes.iconClass} | ||
/> | ||
{truncate(item.name, { length: ITEM_CARD_MAX_LENGTH })} | ||
</Typography> | ||
</CardContent> | ||
</CardActionArea> | ||
</Card> | ||
); | ||
}; | ||
|
||
SimpleCard.propTypes = { | ||
item: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
type: PropTypes.string.isRequired, | ||
extra: PropTypes.shape({}).isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default SimpleCard; |
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 |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
Main, | ||
MainMenu as GraaspMainMenu, | ||
DynamicTreeView, | ||
Loader, | ||
} from '@graasp/ui'; | ||
import { Divider, Grid, Container } from '@material-ui/core'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { useHistory } from 'react-router'; | ||
import HeaderRightContent from './HeaderRightContent'; | ||
import { hooks } from '../../config/queryClient'; | ||
import { buildTreeItemClass } from '../../config/selectors'; | ||
import ItemCard from '../common/ItemCard'; | ||
import { buildMainPath } from '../../config/paths'; | ||
|
||
const { useItem, useOwnItems, useChildren, useSharedItems } = hooks; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
divider: { | ||
margin: theme.spacing(2, 0), | ||
}, | ||
})); | ||
|
||
const Home = () => { | ||
const { t } = useTranslation(); | ||
const classes = useStyles(); | ||
const { push } = useHistory(); | ||
|
||
const { data: ownItems, isLoading: isLoadingOwnItems } = useOwnItems(); | ||
const { data: sharedItems, isLoading: isLoadingSharedItems } = | ||
useSharedItems(); | ||
|
||
const renderSharedItems = () => { | ||
if (isLoadingSharedItems) { | ||
return <Loader />; | ||
} | ||
|
||
if (!sharedItems?.size) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<Divider className={classes.divider} /> | ||
<Typography variant="h4">{t('Shared Items')}</Typography> | ||
<Grid container spacing={3} justify="center"> | ||
{sharedItems.map((i) => ( | ||
<Grid item lg={3} md={4} sm={6}> | ||
<ItemCard item={i} /> | ||
</Grid> | ||
))} | ||
</Grid> | ||
</> | ||
); | ||
}; | ||
|
||
const renderOwnItems = () => { | ||
if (isLoadingOwnItems) { | ||
return <Loader />; | ||
} | ||
|
||
if (!ownItems?.size) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<Typography variant="h4">{t('My Items')}</Typography> | ||
<Grid container spacing={3} justify="center"> | ||
{ownItems.map((i) => ( | ||
<Grid item lg={3} md={4} sm={6}> | ||
<ItemCard item={i} /> | ||
</Grid> | ||
))} | ||
</Grid> | ||
</> | ||
); | ||
}; | ||
|
||
const renderContent = () => ( | ||
<Container> | ||
{renderOwnItems()} | ||
{renderSharedItems()} | ||
</Container> | ||
); | ||
|
||
const renderOwnItemsMenu = () => { | ||
const rootOwnId = 'own'; | ||
|
||
if (isLoadingOwnItems) { | ||
return <Loader />; | ||
} | ||
|
||
if (!ownItems?.size) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<GraaspMainMenu> | ||
<DynamicTreeView | ||
rootLabel={t('My Items')} | ||
rootId={rootOwnId} | ||
useItem={useItem} | ||
buildTreeItemClass={(nodeId) => buildTreeItemClass(nodeId)} | ||
initialExpendedItems={[]} | ||
showCheckbox={false} | ||
showItemFilter={() => true} | ||
onTreeItemSelect={(payload) => { | ||
if (payload !== rootOwnId) { | ||
push(buildMainPath({ rootId: payload, id: null })); | ||
} | ||
}} | ||
useChildren={useChildren} | ||
shouldFetchChildrenForItem={() => false} | ||
isTreeItemDisabled={() => false} | ||
items={ownItems} | ||
/> | ||
</GraaspMainMenu> | ||
); | ||
}; | ||
|
||
const renderSharedItemsMenu = () => { | ||
const rootSharedId = 'shared'; | ||
|
||
if (isLoadingSharedItems) { | ||
return <Loader />; | ||
} | ||
|
||
if (!sharedItems?.size) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<GraaspMainMenu> | ||
<DynamicTreeView | ||
rootLabel={t('Shared Items')} | ||
rootId={rootSharedId} | ||
useItem={useItem} | ||
buildTreeItemClass={(nodeId) => buildTreeItemClass(nodeId)} | ||
initialExpendedItems={[]} | ||
showCheckbox={false} | ||
showItemFilter={() => true} | ||
onTreeItemSelect={(payload) => { | ||
if (payload !== rootSharedId) { | ||
push(buildMainPath({ rootId: payload, id: null })); | ||
} | ||
}} | ||
useChildren={useChildren} | ||
shouldFetchChildrenForItem={() => false} | ||
isTreeItemDisabled={() => false} | ||
items={sharedItems} | ||
/> | ||
</GraaspMainMenu> | ||
); | ||
}; | ||
|
||
const sidebar = ( | ||
<> | ||
{renderOwnItemsMenu()} | ||
{renderSharedItemsMenu()} | ||
</> | ||
); | ||
|
||
return ( | ||
<Main | ||
open | ||
sidebar={sidebar} | ||
headerLeftContent={t('Graasp Perform')} | ||
headerRightContent={<HeaderRightContent />} | ||
> | ||
{renderContent()} | ||
</Main> | ||
); | ||
}; | ||
|
||
export default Home; |
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,3 +1,8 @@ | ||
{ | ||
"translations": {} | ||
"translations": { | ||
"Graasp Perform": "Graasp Perform", | ||
"My Items": "My Items", | ||
"Shared Items": "Shared Items", | ||
"You are not signed in.": "You are not signed in." | ||
} | ||
} |
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,3 +1,8 @@ | ||
{ | ||
"translations": {} | ||
"translations": { | ||
"Graasp Perform": "Graasp Perform", | ||
"My Items": "Mes Eléments", | ||
"Shared Items": "Eléments Partagés", | ||
"You are not signed in.": "Vous n'êtes pas connecté." | ||
} | ||
} |
Oops, something went wrong.