body.tsx 4.99 KB
Newer Older
백승민's avatar
백승민 committed
1
import React, { useEffect, MouseEvent, useState, useRef } from "react";
2
3
4
5
import { Outlet, useSearchParams } from "react-router-dom";
import Theme from "./theme";
import Citylist from "../Pages/citylist";
import { getPicure } from "../Pages/pic";
백승민's avatar
백승민 committed
6
import { MySlide } from "../Pages/myslide";
7
8
9
10
11
12

const initSearchParams = { theme: "", city: "" };

export default function Body() {
  let limit = 15;
  const [searchParams, setSearchParams] = useSearchParams(initSearchParams);
백승민's avatar
백승민 committed
13

14
  const [page, setPage] = useState(1);
백승민's avatar
백승민 committed
15
  const [style, setStyle] = useState("");
백승민's avatar
백승민 committed
16

백승민's avatar
백승민 committed
17
18
19
  const offset1 = (page - 1) * limit;
  const offset2 = page * limit;
  const offset3 = (page + 1) * limit;
20

백승민's avatar
백승민 committed
21
  let getPics = getPicure();
백승민's avatar
백승민 committed
22

23
24
  useEffect(() => {
    console.log(searchParams.get("theme"), searchParams.get("city"));
백승민's avatar
백승민 committed
25
    setSearchParams(searchParams)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  }, []);

  const themeHandleClick = (event: MouseEvent<HTMLButtonElement>) => {
    console.log(`theme id= ${event.currentTarget.id}`);
    setSearchParams({
      ...Object.fromEntries(searchParams),
      theme: event.currentTarget.id,
    });
  };

  const cityHandleClick = (event: MouseEvent<HTMLButtonElement>) => {
    console.log(`city id= ${event.currentTarget.id}`);
    setSearchParams({
      ...Object.fromEntries(searchParams),
      city: event.currentTarget.id,
    });
  };
백승민's avatar
백승민 committed
43
44

  //picture insert 
45
46
  let themechange = searchParams.get("theme");
  let citylistchange = searchParams.get("city");
백승민's avatar
백승민 committed
47

48
49
50
51
52
53
  const Idpics = getPics.filter((p) => {
    return (
      (p.themeid == themechange && p.cityid == citylistchange) ||
      (p.themeid == themechange && citylistchange == "") ||
      (themechange == "" && p.cityid == citylistchange) ||
      (themechange == "" && citylistchange == "")
백승민's avatar
백승민 committed
54
55
    );
  });
56

백승민's avatar
백승민 committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  const numPages = Math.ceil(Idpics.length / 15);
console.log(page)
  // const slides = []
  // for (let i = 0; i < numPages + 1; i++) {
  //   const k =[ 
  //   <div key={Math.random()} className="min-w-full">
  //     <div className={`inline-grid grid-cols-5 ${style}`}>
  //       {Idpics.slice(i * limit, i * limit + limit).map((pic, index: number) => (
  //         <div
  //           className={`m-1 shrink-0 bg-gray-200 rounded shadow-md `}
  //           key={index}>
  //           <img
  //             src={pic.url}
  //             className="w-full h-10 md:h-20 object-center"
  //           />
  //           <p className="text-center text-xs">{pic.name}</p>
  //         </div>
  //       ))}
  //     </div>
  //   </div>]
  //   slides.push(k);
  // }

  return (
81
82
83
    <div className="flex flex-col px-1 py-1">
      <Theme handleClick={themeHandleClick} />
      <div className="flex flex-col md:flex-row py-10 ">
백승민's avatar
백승민 committed
84
85
86
        <div className="w-50">
          <Citylist handleClick={cityHandleClick} />
        </div>
백승민's avatar
백승민 committed
87
        <div className="flex flex-col  overflow-hidden">
백승민's avatar
백승민 committed
88
89
          <MySlide total={Idpics.length} page={page} setPage={setPage} style={style} setStyle={setStyle}/>
          <div className={`md:mr-10 md:basis-4/5 flex flex-row relative w-full `}>
백승민's avatar
백승민 committed
90
91
            <div key={Math.random()} className="min-w-full">
              <div  className={`inline-grid grid-cols-5 ${style}`}>
백승민's avatar
백승민 committed
92
93
                {Idpics.slice(offset1, offset1 + limit).map((pic, index: number) => (
                  <div
백승민's avatar
백승민 committed
94
                    className={`m-1 shrink-0 bg-gray-200 rounded shadow-md `}
백승민's avatar
백승민 committed
95
96
97
98
99
100
101
                    key={index}>
                    <img
                      src={pic.url}
                      className="w-full h-10 md:h-20 object-center"
                    />
                    <p className="text-center text-xs">{pic.name}</p>
                  </div>
백승민's avatar
백승민 committed
102
103
104
                ))}
              </div>
            </div>
백승민's avatar
백승민 committed
105
106
            <div key={Math.random()} className="min-w-full">
              <div className={`inline-grid grid-cols-5 ${style}`}>
백승민's avatar
백승민 committed
107
108
109
                {Idpics.slice(offset2, offset2 + limit).map((pic, index: number) => (

                  <div
백승민's avatar
백승민 committed
110
                    className={`m-1 shrink-0 bg-gray-200 rounded shadow-md `}
백승민's avatar
백승민 committed
111
112
113
114
115
116
117
118
                    key={index}
                  >
                    <img
                      src={pic.url}
                      className="w-full h-10 md:h-20 object-center"
                    />
                    <p className="text-center text-xs">{pic.name}</p>
                  </div>
백승민's avatar
백승민 committed
119
120
121
                ))}
              </div>
            </div>
백승민's avatar
백승민 committed
122
123
            <div key={Math.random()} className="min-w-full">
              <div className={`inline-grid grid-cols-5 ${style}`}>
백승민's avatar
백승민 committed
124
125
126
                {Idpics.slice(offset3, offset3 + limit).map((pic, index: number) => (

                  <div
백승민's avatar
백승민 committed
127
                    className={`m-1 shrink-0 bg-gray-200 rounded shadow-md `}
백승민's avatar
백승민 committed
128
129
130
131
132
133
134
135
                    key={index}
                  >
                    <img
                      src={pic.url}
                      className="w-full h-10 md:h-20 object-center"
                    />
                    <p className="text-center text-xs">{pic.name}</p>
                  </div>
백승민's avatar
백승민 committed
136
                ))}
백승민's avatar
백승민 committed
137
              </div>
138
            </div>
백승민's avatar
백승민 committed
139
          </div>
140
141
        </div>
      </div>
백승민's avatar
백승민 committed
142

143
144
145
146
147
      <Outlet />
    </div>
    // Body Page
  );
}
백승민's avatar
백승민 committed
148