body.tsx 2.6 KB
Newer Older
백승민's avatar
백승민 committed
1
import React, { useEffect, MouseEvent,useState } 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
import Pagination from "./picpagination"
import { LibManifestPlugin } from "webpack";
백승민's avatar
백승민 committed
8
9

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

export default function Body() {
백승민's avatar
백승민 committed
12
13
14
15
16
    let limit = 15;
    const [searchParams, setSearchParams] = useSearchParams(initSearchParams);
    const [page, setPage] = useState(1);
    const offset = (page-1) *limit;

백승민's avatar
백승민 committed
17

백승민's avatar
백승민 committed
18
    let getPics = getPicure();
백승민's avatar
theme1    
백승민 committed
19
20
21

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

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

백승민's avatar
백승민 committed
33
34
35
36
37
38
39
    const cityHandleClick = (event: MouseEvent<HTMLButtonElement>) => {
        console.log(`city id= ${event.currentTarget.id}`)
        setSearchParams({
            ...Object.fromEntries(searchParams),
            city: event.currentTarget.id
        })
    }
백승민's avatar
백승민 committed
40
41
42
    
    let themechange = searchParams.get('theme');
    let citylistchange = searchParams.get('city');
백승민's avatar
theme1    
백승민 committed
43

백승민's avatar
백승민 committed
44
45
    const Idpics = getPics.filter(p => {

백승민's avatar
백승민 committed
46
47
48
49
       return (p.themeid == themechange && p.cityid == citylistchange)||
       (p.themeid == themechange && citylistchange == "")||
       (themechange == "" && p.cityid == citylistchange)||
       (themechange == "" && citylistchange == "")
백승민's avatar
백승민 committed
50
51
52
53
54
55
56
57
    })


    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} />
백승민's avatar
백승민 committed
58
59
                <div className="flex-row md:mr-10 md:basis-4/5 grid grid-rows-3 grid-cols-5">
                    {Idpics.slice(offset, offset + limit).map((pic, index: number) => (
백승민's avatar
백승민 committed
60
                        <div className="m-1 shrink-0 bg-gray-200 rounded overflow-hidden shadow-md" key={index}>
백승민's avatar
백승민 committed
61
                            <img src={pic.url} className="w-full h-10 md:h-20 object-center" />
백승민's avatar
백승민 committed
62
63
                            <p className="text-center text-xs">{pic.name}</p>
                        </div>
백승민's avatar
백승민 committed
64
                    ))}
백승민's avatar
백승민 committed
65
                    <Pagination total={Idpics.length} page = {page} setPage ={setPage}/>
백승민's avatar
백승민 committed
66
                </div>
백승민's avatar
백승민 committed
67
                     
백승민's avatar
theme1    
백승민 committed
68
            </div>
백승민's avatar
백승민 committed
69
70
71
72
73
            <Outlet />
        </div>
        // Body Page
    );
};