Skip to content

Commit

Permalink
feat: button change priority server
Browse files Browse the repository at this point in the history
  • Loading branch information
nxhawk committed Jun 6, 2024
1 parent f2c6a2c commit bd0932c
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 105 deletions.
68 changes: 0 additions & 68 deletions src/components/Button/ScrollButton.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Button/Settings/ButtonChild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Props {
const ButtonChild = ({ children, func }: Props) => {
return (
<button
className="notranslate bg-black/10 dark:bg-black/50 !w-8 !h-8 rounded-full text-white flex justify-center items-center hover:bg-black/20 dark:hover:bg-slate-900/40"
className="notranslate bg-black/10 dark:bg-black/50 !w-8 !h-8 rounded-full text-white flex justify-center items-center hover:bg-black/20 dark:hover:bg-slate-900/40 outline-none"
onClick={func}
>
{children}
Expand Down
61 changes: 35 additions & 26 deletions src/components/Button/Settings/ButtonSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { useNavigate } from "react-router-dom";
import { easeInOutCubic } from "../../../utils/helpers";
import { AppState } from "../../../store";
import { useSelector } from "react-redux";
import PriorityServerPopup from "../../Popup/PriorityServerPopup";

const ButtonSettings = () => {
const navigate = useNavigate();
const isOpen = useSelector((state: AppState) => state.chapterOpen.isOpen);
const [isActive, setIsActive] = useState<boolean>(false);
const [visible, setVisible] = useState<boolean>(false);
const [isShowPriorityServer, setIsShowPriorityServer] = useState<boolean>(false);

let lastScrollTop = 0;

const handleClickToHome = () => {
Expand Down Expand Up @@ -73,39 +76,45 @@ const ButtonSettings = () => {
useEffect(() => {
if (isOpen) {
window.addEventListener("scroll", toggleVisible);
console.log("add");
} else {
window.removeEventListener("scroll", toggleVisible);
console.log("remove");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isOpen]);

return (
<div className={`setting ${isActive && "active"} ${!visible && isOpen && "hidden"}`}>
<div className="toggle">
<button
type="button"
className="nav-btn btn-default-icon !w-9 !h-9 cursor-pointer"
onClick={() => setIsActive(!isActive)}
>
<IconSetting />
</button>
</div>
<div className="action-item" style={{ "--i": 0 } as React.CSSProperties}>
<ButtonChild func={handleClickToHome}>
<IoMdHome className="rotate-[18deg] text-sky-400 text-lg" />
</ButtonChild>
</div>
<div className="action-item" style={{ "--i": 1 } as React.CSSProperties}>
<ButtonChild func={() => {}}>
<FaServer className="rotate-[10deg] text-green-700" />
</ButtonChild>
</div>
<div className="action-item" style={{ "--i": 2 } as React.CSSProperties}>
<ButtonChild func={scrollToTop}>
<FaLongArrowAltUp className="text-red-600 text-xl" />
</ButtonChild>
<div>
{isShowPriorityServer && <PriorityServerPopup close={() => setIsShowPriorityServer(false)} />}
<div className={`setting ${isActive && "active"} ${!visible && isOpen && "hidden"}`}>
<div className="toggle">
<button
type="button"
className="nav-btn btn-default-icon !w-9 !h-9 cursor-pointer outline-none"
onClick={() => setIsActive(!isActive)}
>
<IconSetting />
</button>
</div>
<div className="action-item" style={{ "--i": 0 } as React.CSSProperties}>
<ButtonChild func={handleClickToHome}>
<IoMdHome className="rotate-[20deg] text-sky-400 text-lg" />
</ButtonChild>
</div>
<div className="action-item" style={{ "--i": 1 } as React.CSSProperties}>
<ButtonChild
func={() => {
setIsShowPriorityServer(true);
setIsActive(false);
}}
>
<FaServer className="rotate-[10deg] text-green-700" />
</ButtonChild>
</div>
<div className="action-item" style={{ "--i": 2 } as React.CSSProperties}>
<ButtonChild func={scrollToTop}>
<FaLongArrowAltUp className="text-red-600 text-xl" />
</ButtonChild>
</div>
</div>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Button/Settings/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
justify-content: center;
align-items: center;
transform: rotate(-20deg);
z-index: 1000;
z-index: 10;
.toggle {
position: absolute;
width: 60px;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
z-index: 99;
z-index: 10;
transition: transform 1.2s;
}
.notranslate {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popup/ChapterPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const ChapterPopup = ({ close, novelId, name, server, chapterId }: Props) => {
<div
ref={modalRef}
onClick={handleClickOutside}
className="fixed left-0 mt-0 z-10 top-0 w-full h-screen px-2"
className="fixed left-0 mt-0 z-[1000] top-0 w-full h-screen px-2"
style={{
backgroundColor: "rgba(0, 0, 0, 0.6)",
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popup/ExportEBookPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ExportEBookPopup = ({ close, novelId, server }: Props) => {
<div
ref={modalRef}
onClick={handleClickOutside}
className="z-10 px-1 fixed left-0 top-0 w-full h-full flex justify-center items-center shadow-lg backdrop-blur-sm"
className="z-[1000] px-1 fixed left-0 top-0 w-full h-full flex justify-center items-center shadow-lg backdrop-blur-sm"
>
<div className="shadow-2xl p-2 md:py-5 md:px-4 mx-auto border rounded-lg border-amber-600 bg-white dark:bg-black dark:text-white">
<div className="flex justify-between items-center mb-5">
Expand Down
118 changes: 118 additions & 0 deletions src/components/Popup/PriorityServerPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { useEffect, useState } from "react";
import { useModal } from "../../hooks/useModal";
import { useDispatch, useSelector } from "react-redux";
import { AppDispatch, AppState } from "../../store";
import { DragDropContext, Droppable, Draggable, DropResult } from "@hello-pangea/dnd";
import ButtonClose from "../Button/ButtonClose";
import { changeServerIndex } from "../../store/server";
import { toast } from "react-toastify";

interface Props {
close: () => void;
}

const PriorityServerPopup = ({ close }: Props) => {
const dispatch = useDispatch<AppDispatch>();
const { listServer } = useSelector((state: AppState) => state.server);
const [stores, setStores] = useState(listServer);

useEffect(() => {
document.body.style.overflowY = "hidden";
return () => {
document.body.style.overflowY = "scroll";
};
}, []);

const { modalRef, handleClickOutside } = useModal(close);

const handleDragDrop = (results: DropResult) => {
const { source, destination, type } = results;
if (!destination) return;

if (source.droppableId === destination.droppableId && source.index === destination.index) return;

if (type === "group") {
const tmpStores = [...stores];
const sourceIndex = source.index;
const destinationIndex = destination.index;

const [removedStore] = tmpStores.splice(sourceIndex, 1);
tmpStores.splice(destinationIndex, 0, removedStore);

return setStores(tmpStores);
}
};

const handleSaveNewPriority = () => {
dispatch(changeServerIndex(stores));
toast.success("Đã cập nhật độ ưu tiên nguồn truyện");
close();
};

return (
<div
ref={modalRef}
onClick={handleClickOutside}
className="fixed flex justify-center items-center left-0 mt-0 z-[1000] top-0 w-full h-screen px-2"
style={{
backgroundColor: "rgba(0, 0, 0, 0.6)",
}}
>
<div className="shadow-2xl p-2 mx-auto border rounded-lg border-amber-600 bg-amber-50 dark:bg-stone-950 w-fit">
<div className="flex justify-between items-center border-b shadow-sm pb-3 md:px-2 px-1 dark:border-b-gray-800">
<h1 className="text-lg md:text-xl mr-5 text-nowrap font-bold dark:text-white">
Thay đổi độ ưu tiên nguồn truyện
</h1>
<ButtonClose close={close} />
</div>

<div className="border border-slate-400 p-2 px-3 rounded">
<DragDropContext onDragEnd={handleDragDrop}>
<div className="md:mt-2 flex gap-1 flex-col text-white md:text-base text-sm mb-1">
<Droppable droppableId="ROOT" type="group">
{(provided) => (
<div className="flex gap-1 flex-col" {...provided.droppableProps} ref={provided.innerRef}>
{stores.map((srv, index) => (
<Draggable draggableId={srv} key={srv} index={index}>
{(provided) => (
<div
{...provided.dragHandleProps}
{...provided.draggableProps}
ref={provided.innerRef}
className="border border-slate-800 dark:border-slate-50 text-white rounded px-10 py-2 mb-0.5 text-center bg-amber-500 hover:bg-amber-500/90 md:text-lg text-base"
>
{srv}
</div>
)}
</Draggable>
))}
{provided.placeholder}
</div>
)}
</Droppable>
</div>
</DragDropContext>
</div>

<div className="flex mt-5 gap-3 justify-around pb-1">
<button
type="button"
className="text-white bg-red-700 hover:bg-red-800 focus:outline-none focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-8 py-2 text-center dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900"
onClick={close}
>
Hủy
</button>
<button
type="button"
className="text-white bg-blue-700 hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-8 py-2 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
onClick={handleSaveNewPriority}
>
Lưu
</button>
</div>
</div>
</div>
);
};

export default PriorityServerPopup;
2 changes: 1 addition & 1 deletion src/components/Popup/SettingPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SettingPopup = ({ close }: Props) => {
<div
ref={modalRef}
onClick={handleClickOutside}
className="z-10 fixed left-0 top-0 w-full h-full"
className="z-[1000] fixed left-0 top-0 w-full h-full"
style={{
backgroundColor: "rgba(0, 0, 0, 0.5)",
}}
Expand Down
3 changes: 2 additions & 1 deletion src/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const Layout = () => {
<div className={`md:px-4 lg:px-6 px-0 w-full relative overflow-x-hidden`}>
<Header />
<main className="p-1">
<ButtonSettings />
<Outlet />
</main>
<Footer />

<ButtonSettings />
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/AuthorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ const AuthorPage = () => {
const [, setPerPage] = useState<number>(0);
const [totalPage, setTotalPage] = useState<number>(1);
const [novels, setNovels] = useState<INovelRoot[]>([]);
const { server, listServer } = useSelector((state: AppState) => state.server);
const { listServer } = useSelector((state: AppState) => state.server);
const [indexServer, setIndexServer] = useState(0);
const [myServer, setMyServer] = useState<string>(
listServer.includes(searchParams.get("server") || "a") ? searchParams.get("server") || "a" : listServer[0],
);

const { isFetching, isError } = useQuery({
queryKey: ["author", authorId, server, currentPage, indexServer],
queryKey: ["author", authorId, currentPage, indexServer],
queryFn: async () => {
const data: IResponse<INovelRoot[]> = await ApiGetAllNovelOfAuthor(myServer, authorId || "a", 1);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/error/Notfound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const Notfound = () => {
];

return (
<div className="w-full mx-auto rounded-md h-screen overflow-hidden">
<div className="w-full mx-auto rounded-md h-screen overflow-hidden">
<Vortex
backgroundColor="black"
rangeY={800}
particleCount={500}
baseHue={120}
className="flex items-center flex-col justify-center px-2 md:px-10 py-4 w-full h-full"
className="flex items-center flex-col justify-center px-2 md:px-10 w-full h-full"
>
<TypewriterEffect words={words} />
<Link
Expand Down

0 comments on commit bd0932c

Please sign in to comment.