aboutsummaryrefslogtreecommitdiff
path: root/components/manga/rightBar.js
blob: 9672fc439bb07038c5546f63ab412b91fc76d8ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import {
  ChevronDownIcon,
  ExclamationCircleIcon,
} from "@heroicons/react/24/outline";
import { useEffect, useState } from "react";
import { useAniList } from "../../lib/anilist/useAnilist";
import AniList from "../media/aniList";
import { signIn } from "next-auth/react";
import { toast } from "sonner";

export default function RightBar({
  id,
  hasRun,
  session,
  data,
  currentChapter,
  paddingX,
  setPaddingX,
  layout,
  setLayout,
  setIsKeyOpen,
  scaleImg,
  setScaleImg,
}) {
  const { markProgress } = useAniList(session);

  const [status, setStatus] = useState("CURRENT");
  const [progress, setProgress] = useState(0);
  const [volumeProgress, setVolumeProgress] = useState(0);

  useEffect(() => {
    if (currentChapter?.number) {
      setProgress(currentChapter.number);
    }
  }, [currentChapter]);

  const saveProgress = async () => {
    if (session) {
      const parsedProgress = parseFloat(progress);
      const parsedVolumeProgress = parseFloat(volumeProgress);

      if (
        parsedProgress === parseInt(parsedProgress) &&
        parsedVolumeProgress === parseInt(parsedVolumeProgress)
      ) {
        markProgress(id, progress, status, volumeProgress);
        hasRun.current = true;
      } else {
        toast.error("Progress must be a whole number!");
      }
    }
  };

  // console.log({ id });

  const changeMode = (e) => {
    setLayout(Number(e.target.value));
    // console.log(e.target.value);
  };

  return (
    <div className="hidden lg:flex flex-col gap-5 shrink-0 w-[16rem] bg-secondary py-5 px-3 relative">
      <div
        className="fixed right-5 bottom-5 group cursor-pointer"
        title="Keyboard Shortcuts"
        onClick={() => setIsKeyOpen(true)}
      >
        <ExclamationCircleIcon className="w-6 h-6" />
      </div>
      {Array.isArray(data) ? (
        <div className="flex flex-col gap-3 w-full">
          <h1 className="font-karla font-bold xl:text-lg">Reading mode</h1>
          <div className="flex relative">
            <select
              className="bg-[#161617] text-sm xl:text-base cursor-pointer w-full p-1 px-3 font-karla rounded-md appearance-none"
              defaultValue={layout}
              onChange={changeMode}
            >
              <option value={1}>Vertical</option>
              <option value={2}>Right to Left</option>
              <option value={3}>Right to Left {"(1 Page)"}</option>
            </select>
            <ChevronDownIcon className="w-5 h-5 text-white absolute inset-0 my-auto mx-52" />
          </div>
        </div>
      ) : (
        ""
      )}
      {/* Zoom */}
      <div className="flex flex-col gap-3 w-full">
        <h1 className="font-karla font-bold xl:text-lg">Scale Image</h1>
        <div className="grid grid-cols-3 text-sm xl:text-base gap-5 place-content-evenly justify-items-center">
          <button
            type="button"
            onClick={() => {
              setPaddingX(paddingX - 50);
              setScaleImg(scaleImg + 0.1);
            }}
            className="bg-[#161617] w-full flex-center p-1 rounded-md"
          >
            +
          </button>
          <button
            type="button"
            onClick={() => {
              setPaddingX(paddingX + 50);
              setScaleImg(scaleImg - 0.1);
            }}
            className="bg-[#161617] w-full flex-center p-1 rounded-md"
          >
            -
          </button>
          <button
            type="button"
            onClick={() => {
              setPaddingX(208);
              setScaleImg(1);
            }}
            className="bg-[#161617] w-full flex-center p-1 rounded-md"
          >
            reset
          </button>
        </div>
      </div>
      {/* <div className="flex flex-col gap-3 w-full">
        <h1 className="font-karla font-bold xl:text-lg">Set Quality</h1>
      </div> */}
      <div className="flex flex-col gap-3 w-full">
        <h1 className="font-karla font-bold xl:text-lg">Tracking</h1>
        {session ? (
          id?.length > 6 ? (
            <p className="flex-center w-full py-2 font-karla">
              Not available on AniList
            </p>
          ) : (
            <div className="flex flex-col gap-2">
              <div className="space-y-1">
                <label className="font-karla font-semibold text-gray-500 text-xs">
                  Status
                </label>
                <div className="relative">
                  <select
                    onChange={(e) => setStatus(e.target.value)}
                    className="w-full px-2 py-1 font-karla rounded-md bg-[#161617] appearance-none text-sm"
                  >
                    <option value="CURRENT">Reading</option>
                    <option value="PLANNING">Plan to Read</option>
                    <option value="COMPLETED">Completed</option>
                    <option value="REPEATING">Rereading</option>
                    <option value="PAUSED">Paused</option>
                    <option value="DROPPED">Dropped</option>
                  </select>
                  <ChevronDownIcon className="w-5 h-5 text-white absolute inset-0 my-auto mx-52" />
                </div>
              </div>
              <div className="space-y-1">
                <label className="font-karla font-semibold text-gray-500 text-xs">
                  Chapter Progress
                </label>
                <input
                  id="chapter-progress"
                  type="number"
                  placeholder="0"
                  min={0}
                  value={progress}
                  onChange={(e) => setProgress(e.target.value)}
                  className="w-full px-2 py-1 rounded-md bg-[#161617] text-sm"
                />
              </div>
              <div className="space-y-1">
                <label className="font-karla font-semibold text-gray-500 text-xs">
                  Volume Progress
                </label>
                <input
                  type="number"
                  placeholder="0"
                  min={0}
                  onChange={(e) => setVolumeProgress(e.target.value)}
                  className="w-full px-2 py-1 rounded-md bg-[#161617] text-sm"
                />
              </div>
              <button
                type="button"
                onClick={saveProgress}
                className="w-full bg-[#424245] py-1 my-5 rounded-md text-white text-sm xl:text-base shadow-md font-karla font-semibold"
              >
                Save Progress
              </button>
            </div>
          )
        ) : (
          <button
            type="button"
            onClick={() => signIn("AniListProvider")}
            className="flex-center gap-2 bg-[#363639] hover:bg-[#363639]/50 text-white hover:text-txt p-2 rounded-md cursor-pointer shadow-md"
          >
            <span className="font-karla">Login to AniList</span>
            <div className="flex-center w-5 h-5">
              <AniList />
            </div>
          </button>
        )}
      </div>
    </div>
  );
}