body.tsx 2.11 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
5
6
7
import Citylist from "./citylist";
import getpic from "./pic";

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 = getpic();
백승민'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
49
50
51
52
    const Idpics = getpics.filter(p =>
            p.themeid == searchParams.get('theme')&&            
            p.cityid == 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="overflow-y-auto flex mr:10 md:basis-4/5 grid grid-rows-3 grid-cols-5">
                        {Idpics.map((pic, index:number) => (
                        <div className="m-1 shrink-0 bg-gray-200 rounded overflow-hidden shadow-md" key={index}>
                            <img src={pic.url} className="w-full h-10 md:h-20 object-cover"/>
                            <p className="text-center text-xs">{pic.name}</p>
                        </div>
                     ))}
                    </div>
백승민's avatar
백승민 committed
53
                </div>
백승민's avatar
백승민 committed
54
                <Outlet />
백승민's avatar
theme1    
백승민 committed
55
            </div>
백승민's avatar
백승민 committed
56
57
58
            // Body Page
        );
    };