@@ -301,10 +301,46 @@ const shuffleArray = (array) => {
301
301
return shuffled ;
302
302
} ;
303
303
304
+ const VoteButton = styled . button `
305
+ position: absolute;
306
+ bottom: 10px;
307
+ right: 10px;
308
+ display: flex;
309
+ flex-direction: column;
310
+ align-items: center;
311
+ justify-content: center;
312
+ width: 40px;
313
+ height: 40px;
314
+ background-color: ${ ( props ) => ( props . voted ? '#00a6fb' : 'rgb(13, 25, 53)' ) } ;
315
+ color: ${ ( props ) => ( props . voted ? 'white' : '#00a6fb' ) } ;
316
+ border: 2px solid #00a6fb;
317
+ border-radius: 8px;
318
+ cursor: pointer;
319
+ transition:
320
+ background-color 0.3s,
321
+ color 0.3s;
322
+
323
+ &:hover {
324
+ background-color: rgb(13, 25, 53);
325
+ color: white;
326
+ border: 2px solid #00a6fb;
327
+ }
328
+
329
+ .icon {
330
+ font-size: 16px;
331
+ }
332
+
333
+ .count {
334
+ font-size: 12px;
335
+ margin-top: 2px;
336
+ }
337
+ ` ;
338
+
304
339
const PortfolioIdeas = ( ) => {
305
340
const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
306
341
const [ portfolios , setPortfolios ] = useState ( [ ] ) ;
307
342
const [ searchTerm , setSearchTerm ] = useState ( '' ) ;
343
+ const [ votes , setVotes ] = useState ( { } ) ;
308
344
const [ newPortfolio , setNewPortfolio ] = useState ( {
309
345
author : '' ,
310
346
screenshot : '' ,
@@ -316,8 +352,18 @@ const PortfolioIdeas = () => {
316
352
useEffect ( ( ) => {
317
353
const shuffledPortfolios = shuffleArray ( portfoliosData ) ; // Shuffle portfolios
318
354
setPortfolios ( shuffledPortfolios ) ; // Load shuffled portfolios from JSON file
355
+
356
+ // Load votes from local storage
357
+ const storedVotes = JSON . parse ( localStorage . getItem ( 'portfolioVotes' ) ) || { } ;
358
+ setVotes ( storedVotes ) ;
319
359
} , [ ] ) ;
320
360
361
+ const handleVote = ( index ) => {
362
+ const newVotes = { ...votes , [ index ] : ( votes [ index ] || 0 ) + 1 } ;
363
+ setVotes ( newVotes ) ;
364
+ localStorage . setItem ( 'portfolioVotes' , JSON . stringify ( newVotes ) ) ;
365
+ } ;
366
+
321
367
const handleSubmit = ( e ) => {
322
368
e . preventDefault ( ) ;
323
369
setPortfolios ( [ ...portfolios , newPortfolio ] ) ;
@@ -645,6 +691,10 @@ const PortfolioIdeas = () => {
645
691
alt = { `${ portfolio . author } 's portfolio` }
646
692
className = "h-full w-full rounded-lg object-cover"
647
693
/>
694
+ < VoteButton voted = { votes [ index ] > 0 } onClick = { ( ) => handleVote ( index ) } >
695
+ < div className = "icon" > ▲</ div >
696
+ < div className = "count" > { votes [ index ] || 0 } </ div >
697
+ </ VoteButton >
648
698
</ div >
649
699
< h3 className = "mb-2 flex items-center justify-between text-lg font-semibold text-white" >
650
700
{ portfolio . author }
0 commit comments