Skip to content
Snippets Groups Projects
Commit 60a8d27b authored by Raul Almeida's avatar Raul Almeida
Browse files

WIP Item Store: finish item card carousel

It's a circular linked list
parent 13807c12
No related branches found
No related tags found
1 merge request!21Gamification
...@@ -22,6 +22,9 @@ import Card from '@material-ui/core/Card'; ...@@ -22,6 +22,9 @@ import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions'; import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent'; import CardContent from '@material-ui/core/CardContent';
import ItemCard from './ItemCard.js'; import ItemCard from './ItemCard.js';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import ArrowForwardIcon from '@material-ui/icons/ArrowForward';
import IconButton from '@material-ui/core/IconButton';
//url/user_items/index?q={"item_type": umdaqueles, "op": "none", "unlock_rule": "purchase"} //url/user_items/index?q={"item_type": umdaqueles, "op": "none", "unlock_rule": "purchase"}
export default function ItemCarousel (props) { export default function ItemCarousel (props) {
...@@ -29,13 +32,13 @@ export default function ItemCarousel (props) { ...@@ -29,13 +32,13 @@ export default function ItemCarousel (props) {
const [right, setRight] = useState(5); const [right, setRight] = useState(5);
const goLeft = () => { const goLeft = () => {
setLeft(left-1); setRight(right == 0 ? props.items.length-1 : right-1);
setRight(right-1); setLeft(left == 0 ? props.items.length-1 : left-1);
} }
const goRight = () => { const goRight = () => {
setRight(right+1); setRight(right == props.items.length-1 ? 0 : right+1);
setLeft(left+1); setLeft(left == props.items.length-1 ? 0 : left+1);
} }
return ( return (
...@@ -47,15 +50,22 @@ export default function ItemCarousel (props) { ...@@ -47,15 +50,22 @@ export default function ItemCarousel (props) {
xs={12} xs={12}
spacing={3} spacing={3}
> >
<p onClick={goLeft}>ESQUERDA</p> <IconButton onClick={goLeft}>
<p onClick={goRight}>DIREITA</p> <ArrowBackIcon/>
{props.items.slice(left, right).map((i) => { </IconButton>
{(left > right ?
props.items.slice(left, props.items.length).concat(props.items.slice(0, right))
: props.items.slice(left, right)
).map((i) => {
return <ItemCard return <ItemCard
src={i.src} src={i.src}
action={i.action} action={i.action}
name={i.name} name={i.name}
description={i.description}/> description={i.description}/>
})} })}
<IconButton onClick={goRight}>
<ArrowForwardIcon/>
</IconButton>
</Grid> </Grid>
) )
} }
...@@ -28,9 +28,14 @@ import StoreGuide from '../Components/StoreGuide.js'; ...@@ -28,9 +28,14 @@ import StoreGuide from '../Components/StoreGuide.js';
import ItemCarousel from '../Components/ItemCarousel.js'; import ItemCarousel from '../Components/ItemCarousel.js';
import {apiUrl} from '../env'; import {apiUrl} from '../env';
const StoreSection = styled.h2` const SectionTitle = styled.h3`
font-weight: 100; font-weight: 100;
` `
const StoreSection = styled.div`
font-size: 1.5em;
margin-top: 20px;
margin-bottom: 20px;
`
export default function ItemStoreContainer (props) { export default function ItemStoreContainer (props) {
const [avatar_frames, setAvatarFrames] = useState([]); const [avatar_frames, setAvatarFrames] = useState([]);
...@@ -59,8 +64,8 @@ export default function ItemStoreContainer (props) { ...@@ -59,8 +64,8 @@ export default function ItemStoreContainer (props) {
description: "Descrição | Descrição" description: "Descrição | Descrição"
} }
]; ];
for (let i = 0; i < 6; i++) for (let i = 0; i < 10; i++)
items = items.concat(items); items = items.concat(items[0]);
return ( return (
<Container style={{paddingTop : "2em", backgroundColor : "#f4f4f4"}}> <Container style={{paddingTop : "2em", backgroundColor : "#f4f4f4"}}>
...@@ -77,19 +82,19 @@ export default function ItemStoreContainer (props) { ...@@ -77,19 +82,19 @@ export default function ItemStoreContainer (props) {
<StoreGuide/> <StoreGuide/>
</Grid> </Grid>
<StoreSection> <StoreSection>
Bordas de avatar <SectionTitle>Bordas de avatar</SectionTitle>
<ItemCarousel items={items}/> <ItemCarousel items={items}/>
</StoreSection> </StoreSection>
<StoreSection> <StoreSection>
Insígnias <SectionTitle>Insígnias</SectionTitle>
<ItemCarousel items={items}/> <ItemCarousel items={items}/>
</StoreSection> </StoreSection>
<StoreSection> <StoreSection>
Bordas de card <SectionTitle>Bordas de card</SectionTitle>
<ItemCarousel items={items}/> <ItemCarousel items={items}/>
</StoreSection> </StoreSection>
<StoreSection> <StoreSection>
Bordas de capa de perfil <SectionTitle>Bordas de capa de perfil</SectionTitle>
<ItemCarousel items={items}/> <ItemCarousel items={items}/>
</StoreSection> </StoreSection>
</Container> </Container>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment