import React, { ReactElement, useEffect } from "react"; import Preview from "../Preview/Preview"; import { API } from "aws-amplify"; import { useState } from "react"; import styles from "./Vod.module.css"; import { useParams } from "react-router-dom"; const Vod = () => { const [playlist, setPlaylist] = useState([]); const { keyword } = useParams(); useEffect(() => { const apiName = "GetVideoList"; const apiPath = "/vod"; const testEvent = { message: "Hello, this is the test event from the amplify", }; const list: ReactElement[] = []; // temporary array and set to remove duplicate let tempArray: string[] = []; const tempSet: Set = new Set(); API.get(apiName, apiPath, testEvent) .then((response) => { for (const item of response) { if (!keyword) tempSet.add(item.url); else { if (keyword === item.celebName) { console.log(`${keyword} provided`); tempSet.add(item.url); } } } tempArray = [...tempSet]; for (const elem of tempArray) { list.push(
  • ); } setPlaylist(list); }) .catch((error) => { // console.log(error.response); }); }, [keyword]); return (
    {/*  Shorts */}
      {playlist}
    ); }; export default Vod;