-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b67d98b
commit bd699c6
Showing
6 changed files
with
152 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
|
||
const initialState = { | ||
firms: [], | ||
loading: false, | ||
error: false, | ||
} | ||
|
||
const firmSlice = createSlice({ | ||
name: "getfirms", | ||
initialState, | ||
reducers: { | ||
fetchStart: (state) => { | ||
state.loading = true | ||
}, | ||
firmsList: (state, {payload}) => { | ||
state.loading = false | ||
state.firms = payload.data | ||
}, | ||
fetchFail: (state) => { | ||
state.loading = false | ||
state.error = true | ||
}, | ||
} | ||
}); | ||
|
||
export const { fetchFail, firmsList, fetchStart } = firmSlice.actions | ||
|
||
export default firmSlice.reducer |
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,11 +1,91 @@ | ||
import React from 'react' | ||
import React, { useEffect } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import useStockRequest from "../services/useStockRequest"; | ||
import { Box, Container, Typography } from "@mui/material"; | ||
import { styled } from "@mui/material/styles"; | ||
import Card from "@mui/material/Card"; | ||
import CardHeader from "@mui/material/CardHeader"; | ||
import CardMedia from "@mui/material/CardMedia"; | ||
import CardContent from "@mui/material/CardContent"; | ||
import CardActions from "@mui/material/CardActions"; | ||
import Collapse from "@mui/material/Collapse"; | ||
import Avatar from "@mui/material/Avatar"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import { red } from "@mui/material/colors"; | ||
import FavoriteIcon from "@mui/icons-material/Favorite"; | ||
import ShareIcon from "@mui/icons-material/Share"; | ||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; | ||
import MoreVertIcon from "@mui/icons-material/MoreVert"; | ||
|
||
const ExpandMore = styled((props) => { | ||
const { expand, ...other } = props; | ||
return <IconButton {...other} />; | ||
})(({ theme, expand }) => ({ | ||
transform: !expand ? "rotate(0deg)" : "rotate(180deg)", | ||
marginLeft: "auto", | ||
transition: theme.transitions.create("transform", { | ||
duration: theme.transitions.duration.shortest, | ||
}), | ||
})); | ||
|
||
const ListFirms = () => { | ||
const [expanded, setExpanded] = React.useState(false); | ||
const { firms } = useSelector((state) => state.getfirms); | ||
const { getFirms } = useStockRequest(); | ||
// console.log(firms) | ||
|
||
const handleExpandClick = () => { | ||
setExpanded(!expanded); | ||
}; | ||
|
||
useEffect(() => { | ||
getFirms(); | ||
}, []); | ||
return ( | ||
<div> | ||
|
||
</div> | ||
) | ||
} | ||
<Container> | ||
<Typography>FİRMS</Typography> | ||
|
||
<Box> | ||
{firms.map((firm) => ( | ||
<Card key={firm.id} sx={{ maxWidth: 345 }}> | ||
<CardHeader | ||
title={firm.name} | ||
sx={{textAlign:"center"}} | ||
/> | ||
<CardMedia | ||
component="img" | ||
height="194" | ||
image={firm.image} | ||
alt="Paella dish" | ||
sx={{ objectFit: "contain" }} | ||
/> | ||
<CardContent> | ||
<Typography variant="body2" color="text.secondary"> | ||
{firm.address} | ||
</Typography> | ||
</CardContent> | ||
<CardActions disableSpacing> | ||
<IconButton aria-label="add to favorites"> | ||
<FavoriteIcon /> | ||
</IconButton> | ||
<IconButton aria-label="share"> | ||
<ShareIcon /> | ||
</IconButton> | ||
<ExpandMore | ||
expand={expanded} | ||
onClick={handleExpandClick} | ||
aria-expanded={expanded} | ||
aria-label="show more" | ||
> | ||
<ExpandMoreIcon /> | ||
</ExpandMore> | ||
</CardActions> | ||
|
||
</Card> | ||
))} | ||
</Box> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ListFirms | ||
export default ListFirms; |
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,24 @@ | ||
import { useDispatch } from "react-redux" | ||
import useAxios from "./useAxios" | ||
import { fetchFail, fetchStart, firmsList } from "../features/firmSlice" | ||
|
||
const useStockRequest = () => { | ||
const { axiosToken } = useAxios() | ||
const dispatch = useDispatch() | ||
|
||
const getFirms = async () => { | ||
dispatch(fetchStart()) | ||
try { | ||
const { data } =await axiosToken.get("/firms") | ||
console.log(data) | ||
dispatch(firmsList(data)) | ||
} catch (error) { | ||
dispatch(fetchFail()) | ||
console.log(error) | ||
} | ||
} | ||
|
||
return { getFirms } | ||
} | ||
|
||
export default useStockRequest |