Skip to content

Commit

Permalink
update basic style
Browse files Browse the repository at this point in the history
  • Loading branch information
raibove authored May 2, 2024
1 parent 9631ee3 commit ee68965
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 57 deletions.
16 changes: 16 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { useEffect } from 'react';
import './App.css'
import Header from './component/header'
import InputModal from './component/input-modal'

const prefetchImage = async (imageName: string) => {
var img=new Image();
img.src=`/${imageName}`;
};

function App() {
useEffect(() => {
const prefetchImages = async () => {
const promises = [];
for (let i = 0; i <= 11; i++) {
promises.push(prefetchImage(`image${i}.png`));
}
await Promise.all(promises);
};
prefetchImages();
}, []);

return (
<div className='app'>
Expand Down
70 changes: 41 additions & 29 deletions src/component/input-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ const InputModal: React.FC = () => {

const selectNextDisabled = loading || selectedClothIndex === -1;


const handleReset = () => {
setStep('upload');
setClothesInImg([])
setSelectedClothIndex(-1)
setComplementOutfit([])
}

return (
<div className="app-container">
{loading && <div className="loading style-2"><div className="loading-wheel"></div></div>}
Expand All @@ -55,25 +63,36 @@ const InputModal: React.FC = () => {
{
step === 'select' && (
<>
<img src={image} alt="uplaoded outfit" style={{ height: '300px' }} />
<div style={{ display: 'flex', flexDirection: 'column' }}>
{clothesInImg.map((cloth, index) => (
<div key={index} style={{ cursor: 'pointer' }}>
<label style={{ color: 'black', cursor: 'pointer' }}>
<input
type='radio'
value={index}
checked={selectedClothIndex === index}
onChange={() => {
setSelectedClothIndex(index);
}}
/>
{cloth.item}
</label>
</div>)
)}
</div>
<button className="next-button" onClick={handleNext} disabled={selectNextDisabled} style={{ cursor: selectNextDisabled ? 'no-drop' : 'pointer' }}>Next</button>
{clothesInImg.length === 0 ?
<>
<label className="upload-label">No outfit found, please try with different image</label>
<div style={{ margin: '20px 80px 80px 80px' }}>
<button className="start-again-button" onClick={handleReset}>Try Again</button>
</div>
</>
:
<>
<img src={image} alt="uplaoded outfit" style={{ height: '300px' }} />
<div style={{ display: 'flex', flexDirection: 'column' }}>
{clothesInImg.map((cloth, index) => (
<div key={index} style={{ cursor: 'pointer' }}>
<label style={{ color: 'black', cursor: 'pointer' }}>
<input
type='radio'
value={index}
checked={selectedClothIndex === index}
onChange={() => {
setSelectedClothIndex(index);
}}
/>
{cloth.item}
</label>
</div>)
)}
</div>
<button className="next-button" onClick={handleNext} disabled={selectNextDisabled} style={{ cursor: selectNextDisabled ? 'no-drop' : 'pointer' }}>Next</button>
</>
}
</>
)
}
Expand All @@ -84,19 +103,12 @@ const InputModal: React.FC = () => {
<div className='card-container'>
{
complementOutfit.map((outfit) => (
<Card outfit={outfit} selectedItem={clothesInImg[selectedClothIndex]} />
<Card key={outfit.color + outfit.item} outfit={outfit} selectedItem={clothesInImg[selectedClothIndex]} />
))
}
</div>
<div style={{ margin: '20px 80px 80px 80px' }}
onClick={()=>{
setStep('upload');
setClothesInImg([])
setSelectedClothIndex(-1)
setComplementOutfit([])
}}
>
<button className="start-again-button">Start Again</button>
<div style={{ margin: '20px 80px 80px 80px' }}>
<button className="start-again-button" onClick={handleReset}>Start Again</button>
</div>
</div>
)
Expand Down
15 changes: 1 addition & 14 deletions src/component/input-modal/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
.upload-label {
font-size: 34px;
color: black;
text-align: center;
}

.next-button {
Expand All @@ -35,20 +36,6 @@
background-color: #2980b9;
}

.file-input-container {
display: inline-block;
background-color: #3498db;
color: #000;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

.file-input {
display: none;
}

.loading {
width: 100%;
height: 100%;
Expand Down
33 changes: 20 additions & 13 deletions src/component/upload/style.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
.file-input-container {
display: inline-block;
background-color: #3498db;
color: #fff;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

.file-input {
display: none;
}

display: inline-block;
background-color: black;
color: #fff;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
border: 1px solid transparent;
}

.file-input-container:hover {
background-color: #ccc;
color: #000;
border: 1px solid black;
display: block;
}

.file-input {
display: none;
}
11 changes: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ const loadImageAsBuffer = async (imageUrl: string): Promise<string> => {
}
};

function trimTextUntilImage(text: string) {
const indexOfImage = text.indexOf("Image:");
if (indexOfImage !== -1) {
return text.substring(0, indexOfImage);
} else {
return text;
}
}

export async function run(input: string) {

const genAI = new GoogleGenerativeAI(import.meta.env.VITE_API_KEY);
Expand Down Expand Up @@ -203,7 +212,7 @@ export async function run(input: string) {
});

const response = result.response;
return response.text();
return trimTextUntilImage(response.text());
}


Expand Down

0 comments on commit ee68965

Please sign in to comment.