11import React from 'react' ;
22import { useStaticQuery , graphql } from 'gatsby' ;
3- import { Box , Text , chakra , SimpleGrid } from '@chakra-ui/react' ;
3+ import {
4+ Box ,
5+ Text ,
6+ chakra ,
7+ Grid ,
8+ useColorModeValue ,
9+ Tooltip ,
10+ Img ,
11+ } from '@chakra-ui/react' ;
412import { StaticImage , GatsbyImage , getImage } from 'gatsby-plugin-image' ;
513import Link from '@/components/gatsby-link' ;
6- import letterboxd from 'letterboxd' ;
7- import { move } from 'formik' ;
814
915const MovieCard = ( ) => {
10- let FilmData ;
11-
12- // letterboxd('desktopofsamuel')
13- // .then((items) =>
14- // items.forEach((item) => {
15- // console.log(item);
16- // }),
17- // )
18- // .catch((error) => console.log(error));
19-
20- // ;
21-
22- function Striper ( data ) {
23- const imageURL = data . match ( / < p > / ) ;
24- return imageURL ;
25- }
26-
27- function getTestDiv ( htmlString ) {
28- let textVal = null ;
16+ function rssParser ( htmlString ) {
17+ let imgLink = null ;
2918 const searchTerm = `\"/></p>` ;
30- const imgclose = htmlString . indexOf ( searchTerm ) ;
31- const elements = htmlString . slice ( 14 , imgclose ) ;
32- textVal = elements ;
33-
34- // console.log(textVal);
35- return textVal ;
19+ const imgTagPosition = htmlString . indexOf ( searchTerm ) ;
20+ const elements = htmlString . slice ( 14 , imgTagPosition ) ;
21+ imgLink = elements ;
22+ // console.log(imgLink);
23+ return imgLink ;
3624 }
3725
3826 // .getElementsByTagName('p')[0]
3927
4028 const data = useStaticQuery ( graphql `
4129 query MovieCardPage {
42- allFeedLetterboxd(limit: 3 ) {
30+ allFeedLetterboxd(limit: 5 ) {
4331 edges {
4432 node {
4533 id
@@ -56,43 +44,39 @@ const MovieCard = () => {
5644 }
5745 ` ) ;
5846
59- function htmlDecode ( input ) {
60- var e = document . createElement ( 'div' ) ;
61- e . innerHTML = input ;
62- return e . childNodes . length === 0 ? '' : e . childNodes [ 0 ] . nodeValue ;
63- }
64-
6547 // const image = getImage(getTestDiv(movie.node.content));
6648
6749 return (
6850 < >
6951 { data . allFeedLetterboxd . edges && (
7052 < Box
71- backgroundColor = " gray.100"
53+ backgroundColor = { useColorModeValue ( ' gray.100' , 'gray.700' ) }
7254 p = "4"
7355 borderRadius = "16"
7456 gridColumn = "span 2"
7557 >
76- < Text m = "0" > I'm watching to</ Text >
77- < SimpleGrid columns = { 3 } spacing = { 10 } >
78- { data . allFeedLetterboxd . edges . map ( ( movie ) => (
79- < Box key = { movie . node . id } >
58+ < Text m = "0" > 最近在看</ Text >
59+ < Grid gridTemplateColumns = "repeat(auto-fit, 120px)" >
60+ { data . allFeedLetterboxd . edges . map ( ( movie , index ) => (
61+ < Box
62+ key = { movie . node . id }
63+ mr = "-30px"
64+ zIndex = { index }
65+ _hover = { { zIndex : '100' } }
66+ boxShadow = "2px 0 7px grey;"
67+ >
8068 < Link to = { movie . node . link } target = "_blank" >
81- { /* {console.log(getTestDiv(movie.node.content))} */ }
82- { /* <Box
83- dangerouslySetInnerHTML={{
84- __html: getTestDiv(movie.node.content),
85- }}
86- /> */ }
87- < img
88- src = { getTestDiv ( movie . node . content ) }
89- alt = { movie . node . title }
90- />
91- < Text > { movie . node . title } </ Text >
69+ < Tooltip label = { movie . node . title } fontSize = "md" >
70+ < Img
71+ src = { rssParser ( movie . node . content ) }
72+ alt = { movie . node . title }
73+ />
74+ { /* <Text>{movie.node.title}</Text> */ }
75+ </ Tooltip >
9276 </ Link >
9377 </ Box >
9478 ) ) }
95- </ SimpleGrid >
79+ </ Grid >
9680 </ Box >
9781 ) }
9882 </ >
0 commit comments