|
| 1 | +import { useEffect, useRef } from 'react'; |
| 2 | +import styled from 'styled-components'; |
| 3 | +import { ReactComponent as Check } from '../../../assets/svg/Check.svg'; |
| 4 | +import { ReactComponent as Plus } from '../../../assets/svg/Plus.svg'; |
| 5 | +import youtubeSearch from '../../../interface/youtubeSearch.interface'; |
| 6 | +import { getThumbnail } from '../../../api/main'; |
| 7 | + |
| 8 | +export default function SearchListItem({ |
| 9 | + item, |
| 10 | + isInPlaylist, |
| 11 | +}: { |
| 12 | + item: youtubeSearch; |
| 13 | + isInPlaylist: (_item: youtubeSearch) => boolean; |
| 14 | +}) { |
| 15 | + const isAdded = isInPlaylist(item); |
| 16 | + const imgRef = useRef(null); |
| 17 | + useEffect(() => { |
| 18 | + getThumbnail(item.id.videoId) |
| 19 | + .then((res) => { |
| 20 | + console.log(res); |
| 21 | + if (imgRef.current) { |
| 22 | + imgRef.current.src = res; |
| 23 | + } |
| 24 | + }) |
| 25 | + .catch((err) => console.log(err)); |
| 26 | + }, []); |
| 27 | + |
| 28 | + return ( |
| 29 | + <VideoComponent isAdded={isAdded} key={item.id.videoId}> |
| 30 | + <InnerComponent isAdded={isAdded} id={!isAdded ? 'addVideoButton' : ''}> |
| 31 | + <SvgComponent isAdded={isAdded}> |
| 32 | + {isAdded ? <Check /> : <Plus />} |
| 33 | + </SvgComponent> |
| 34 | + </InnerComponent> |
| 35 | + <Image ref={imgRef} /> |
| 36 | + </VideoComponent> |
| 37 | + ); |
| 38 | +} |
| 39 | + |
| 40 | +const VideoComponent = styled.div<{ isAdded: boolean }>` |
| 41 | + width: 100%; |
| 42 | + height: 14rem; |
| 43 | + /* background-color: ${({ isAdded }) => |
| 44 | + isAdded ? 'rgba(55, 65, 81, 1)' : 'rgba(55, 65, 81, 0.5)'}; */ |
| 45 | + &:hover { |
| 46 | + #addVideoButton { |
| 47 | + display: grid; |
| 48 | + } |
| 49 | + } |
| 50 | + #addVideoButton { |
| 51 | + cursor: pointer; |
| 52 | + } |
| 53 | +`; |
| 54 | + |
| 55 | +const InnerComponent = styled.div<{ isAdded: boolean }>` |
| 56 | + width: 100%; |
| 57 | + height: 100%; |
| 58 | + display: ${({ isAdded }) => (isAdded ? 'flex' : 'none')}; |
| 59 | + align-items: center; |
| 60 | + justify-content: center; |
| 61 | + background-color: rgba(0, 0, 0, 0.5); |
| 62 | + transition: all 0.3s ease-in-out; |
| 63 | +`; |
| 64 | + |
| 65 | +const SvgComponent = styled.div<{ isAdded: boolean }>` |
| 66 | + width: 5rem; |
| 67 | + height: 5rem; |
| 68 | + display: flex; |
| 69 | + justify-content: center; |
| 70 | + align-items: center; |
| 71 | + background-color: ${({ isAdded }) => (isAdded ? '#00c113' : '#3C3C3C')}; |
| 72 | + border-radius: 50%; |
| 73 | + svg { |
| 74 | + width: 60%; |
| 75 | + height: 60%; |
| 76 | + } |
| 77 | +`; |
| 78 | + |
| 79 | +const Image = styled.image` |
| 80 | + width: 100%; |
| 81 | + height: 100%; |
| 82 | +`; |
0 commit comments