body.tsx 3.87 KB
Newer Older
1
2
3
4
5
import React, { useEffect, MouseEvent, useState } from "react";
import { Outlet, useSearchParams } from "react-router-dom";
import Theme from "./theme";
import Citylist from "../Pages/citylist";
import { getPicure } from "../Pages/pic";
Kim, MinGyu's avatar
Kim, MinGyu committed
6
import { PaginationLeft, PaginationRight } from "../Pages/picpagination";
7
8
9
10
11
12
13
14

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

export default function Body() {
  let limit = 15;
  const [searchParams, setSearchParams] = useSearchParams(initSearchParams);
  const [page, setPage] = useState(1);
  const offset = (page - 1) * limit;
백승민's avatar
백승민 committed
15
  const [selected, setSelected] = useState(1);
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  let getPics = getPicure();

  useEffect(() => {
    console.log(searchParams.get("theme"), searchParams.get("city"));
    // setSearchParams(searchParams)
  }, []);

  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,
    });
  };

  let themechange = searchParams.get("theme");
  let citylistchange = searchParams.get("city");

  const Idpics = getPics.filter((p) => {
    return (
      (p.themeid == themechange && p.cityid == citylistchange) ||
      (p.themeid == themechange && citylistchange == "") ||
      (themechange == "" && p.cityid == citylistchange) ||
      (themechange == "" && citylistchange == "")
    );
  });

Kim, MinGyu's avatar
Kim, MinGyu committed
51
52
53
  const pre = () => {
    setSelected(selected - 1);
  };
백승민's avatar
백승민 committed
54

Kim, MinGyu's avatar
Kim, MinGyu committed
55
56
57
  const next = () => {
    setSelected(selected + 1);
  };
백승민's avatar
백승민 committed
58

59
  return (
Kim, MinGyu's avatar
Kim, MinGyu committed
60
    <div className="flex flex-col">
61
      <Theme handleClick={themeHandleClick} />
Kim, MinGyu's avatar
Kim, MinGyu committed
62
      <div className="flex flex-col md:flex-row py-5 ">
백승민's avatar
백승민 committed
63
64
65
66
67
        <div className="w-50">
          <Citylist handleClick={cityHandleClick} />
        </div>
        <div className="flex flex-col">
          <div>
Kim, MinGyu's avatar
Kim, MinGyu committed
68
69
70
71
72
73
            <button onClick={pre} disabled={selected === 1}>
              &lt;{selected}
            </button>
            <button onClick={next} disabled={selected === 3}>
              &gt;
            </button>
백승민's avatar
백승민 committed
74
          </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
75
          <div>
백승민's avatar
백승민 committed
76
            <div className=" md:mr-10 md:basis-4/5 overflow-hidden">
Kim, MinGyu's avatar
Kim, MinGyu committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
              <div
                className=" flex flex-row transition duration-500 relative"
                style={{
                  transform: "translate(-" + (selected - 1) * 100 + "%)",
                }}
              >
                <img
                  className="border-2"
                  src="https://t1.daumcdn.net/cfile/tistory/9947E0365C31C1BF0E"
                />
                <img
                  className="border-2"
                  src="https://t1.daumcdn.net/cfile/tistory/9947E0365C31C1BF0E"
                />
                <img
                  className="border-2"
                  src="https://t1.daumcdn.net/cfile/tistory/9947E0365C31C1BF0E"
                />
백승민's avatar
백승민 committed
95
              </div>
96
            </div>
백승민's avatar
백승민 committed
97
          </div>
98
99
        </div>
      </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
100

101
102
103
104
105
      <Outlet />
    </div>
    // Body Page
  );
}
Kim, MinGyu's avatar
Kim, MinGyu committed
106
107
108
109
110
{
  /* <div className=" md:mr-10 md:basis-4/5 grid grid-rows-3 grid-cols-5"></div> */
}
{
  /* {Idpics.slice(offset, offset + limit).map((pic, index: number) => (
백승민's avatar
백승민 committed
111
112
113
114
115
116
117
118
119
120
            <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-center"
                />
                <p className="text-center text-xs">{pic.name}</p>
                </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
121
122
123
124
125
126
127
128
              ))}  */
}
{
  /* <PaginationLeft total={Idpics.length} page={page} setPage={setPage} /> */
}
{
  /* <PaginationRight total={Idpics.length} page={page} setPage={setPage} /> */
}