body.tsx 2.25 KB
Newer Older
백승민's avatar
백승민 committed
1
import React, { useEffect, MouseEvent } from "react";
백승민's avatar
백승민 committed
2
import { Outlet, useSearchParams } from "react-router-dom";
백승민's avatar
theme1    
백승민 committed
3
import Theme from "./theme";
백승민's avatar
백승민 committed
4
import Citylist from "./citylist";
백승민's avatar
백승민 committed
5
import {getPicure} from "./pic";
백승민's avatar
백승민 committed
6
7

const initSearchParams = { "theme": "", "city": "" }
백승민's avatar
theme1    
백승민 committed
8
9

export default function Body() {
백승민's avatar
백승민 committed
10

백승민's avatar
theme1    
백승민 committed
11
    const [searchParams, setSearchParams] = useSearchParams(initSearchParams)
백승민's avatar
백승민 committed
12
    let getPics = getPicure();
백승민's avatar
theme1    
백승민 committed
13
14
15

    useEffect(() => {
        console.log(searchParams.get('theme'), searchParams.get('city'))
백승민's avatar
백승민 committed
16
        // setSearchParams(searchParams)
백승민's avatar
theme1    
백승민 committed
17
18
    }, [])

백승민's avatar
백승민 committed
19
    const themeHandleClick = (event: MouseEvent<HTMLButtonElement>) => {
백승민's avatar
theme1    
백승민 committed
20
        console.log(`theme id= ${event.currentTarget.id}`)
백승민's avatar
백승민 committed
21
22
23
24
        setSearchParams({
            ...Object.fromEntries(searchParams),
            theme: event.currentTarget.id,
        })
백승민's avatar
theme1    
백승민 committed
25
26
    }

백승민's avatar
백승민 committed
27
28
29
30
31
32
33
    const cityHandleClick = (event: MouseEvent<HTMLButtonElement>) => {
        console.log(`city id= ${event.currentTarget.id}`)
        setSearchParams({
            ...Object.fromEntries(searchParams),
            city: event.currentTarget.id
        })
    }
백승민's avatar
theme1    
백승민 committed
34

백승민's avatar
백승민 committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    const Idpics = getPics.filter(p => {

       return (p.themeid == searchParams.get('theme') && p.cityid == searchParams.get('city'))||(p.themeid == searchParams.get('theme') && searchParams.get('city') == "")
       ||(searchParams.get('theme') == "" && p.cityid == searchParams.get('city'))||(searchParams.get('theme') == "" && searchParams.get('city') == "")
    })


    return (
        <div className="flex flex-col px-1 py-1">
            <Theme handleClick={themeHandleClick} />
            <div className="flex flex-col md:flex-row py-10 ">
                <Citylist handleClick={cityHandleClick} />
                <div className="flex md:mr-10 md:basis-4/5 grid grid-rows-3 grid-cols-5">
                    {Idpics.map((pic, index: number) => (
백승민's avatar
백승민 committed
49
                        <div className="m-1 shrink-0 bg-gray-200 rounded overflow-hidden shadow-md" key={index}>
백승민's avatar
백승민 committed
50
                            <img src={pic.url} className="w-full h-10 md:h-20 object-cover" />
백승민's avatar
백승민 committed
51
52
                            <p className="text-center text-xs">{pic.name}</p>
                        </div>
백승민's avatar
백승민 committed
53
                    ))}
백승민's avatar
백승민 committed
54
                </div>
백승민's avatar
theme1    
백승민 committed
55
            </div>
백승민's avatar
백승민 committed
56
57
58
59
60
            <Outlet />
        </div>
        // Body Page
    );
};