-
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.
Daily implemented and Outfit of Day updated
- Loading branch information
1 parent
46fe22a
commit 2fa45d3
Showing
2 changed files
with
53 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import Button from 'react-bootstrap/Button'; | ||
import './styles/Daily.css'; | ||
|
||
const Daily = ({ day, handleSubmmit }) => { | ||
const apiUrl = process.env.REACT_APP_API_URL; | ||
const [outfits, setOutfits] = useState([]); | ||
const [selectedOutfitIndex, setSelectedOutfitIndex] = useState(0); | ||
|
||
useEffect(() => { | ||
const fetchOutfitsForDay = async () => { | ||
try { | ||
const response = await axios.get(`${apiUrl}day/${day}`); | ||
setOutfits(response.data.outfits); | ||
} catch (error) { | ||
console.error('Error fetching outfits for the day:', error); | ||
} | ||
}; | ||
|
||
fetchOutfitsForDay(); | ||
}, [apiUrl, day]); | ||
|
||
const handleSave = () => { | ||
if (outfits.length > 0) { | ||
handleSubmmit(outfits[selectedOutfitIndex]); | ||
} | ||
}; | ||
|
||
const handleSelectOutfit = (index) => { | ||
setSelectedOutfitIndex(index); | ||
}; | ||
|
||
return ( | ||
<div className='daily-container'> | ||
<h3>Outfits for {day}</h3> | ||
<div className='outfit-list'> | ||
{outfits.map((outfit, index) => ( | ||
<div | ||
key={index} | ||
className={`outfit-item ${index === selectedOutfitIndex ? 'selected' : ''}`} | ||
onClick={() => handleSelectOutfit(index)} | ||
> | ||
<img src={`data:image/jpeg;base64,${outfit.image}`} alt={`Outfit ${index + 1}`} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Daily; |
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