Skip to content

Commit

Permalink
chore: small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nxhawk committed Jun 7, 2024
1 parent d591860 commit 5982d8d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
55 changes: 29 additions & 26 deletions src/components/Filter/SelectChangeServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,36 @@ interface Props {
const SelectChangeServer = ({ myServer, func }: Props) => {
const listServer = useSelector((state: AppState) => state.server.listServer);

return (
<form className="mr-2 mt-1 md:mb-0">
<div className="flex">
<label
id="states-button"
data-dropdown-toggle="dropdown-states"
className="flex-shrink-0 z-10 inline-flex items-center py-2.5 px-4 text-sm font-medium text-center text-gray-500 bg-gray-100 border border-gray-300 rounded-s-lg hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-100 dark:bg-slate-950 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:text-white dark:border-gray-700"
htmlFor="states"
>
Nguồn
</label>
if (listServer.length > 0)
return (
<form className="mr-2 mt-1 md:mb-0">
<div className="flex">
<label
id="states-button"
data-dropdown-toggle="dropdown-states"
className="flex-shrink-0 z-10 inline-flex items-center py-2.5 px-4 text-sm font-medium text-center text-gray-500 bg-gray-100 border border-gray-300 rounded-s-lg hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-gray-100 dark:bg-slate-950 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:text-white dark:border-gray-700"
htmlFor="states"
>
Nguồn
</label>

<select
value={myServer}
onChange={(e) => func(e.target.value)}
id="states"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-e-lg border-s-gray-100 dark:border-s-gray-900 border-s-2 focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-900 dark:border-gray-800 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
{listServer.map((srv) => (
<option value={srv} key={srv}>
{srv}
</option>
))}
</select>
</div>
</form>
);
<select
value={myServer}
onChange={(e) => func(e.target.value)}
id="states"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-e-lg border-s-gray-100 dark:border-s-gray-900 border-s-2 focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-900 dark:border-gray-800 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
{listServer.map((srv) => (
<option value={srv} key={srv}>
{srv}
</option>
))}
</select>
</div>
</form>
);

return;
};

export default SelectChangeServer;
6 changes: 4 additions & 2 deletions src/components/Popup/PriorityServerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ const PriorityServerPopup = ({ close }: Props) => {
};

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

Expand Down
2 changes: 1 addition & 1 deletion src/pages/AuthorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const AuthorPage = () => {

useEffect(() => {
if (isError) {
if (indexServer == listServer.length - 1)
if (listServer.length <= 0 || indexServer == listServer.length - 1)
navigate("/notfound", {
replace: true,
});
Expand Down
6 changes: 5 additions & 1 deletion src/pages/FilterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useSearchParams } from "react-router-dom";
import Slider from "../components/Slider";

import BoxNovelAuthor from "../components/Novel/BoxNovelAuthor";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { IResponse } from "../types/response";
import { INovelRoot } from "../types/novel";
Expand Down Expand Up @@ -41,6 +41,10 @@ const FilterPage = () => {
retry: 1,
});

useEffect(() => {
changeServerByHand(server);
}, [server]);

function changeServerByHand(srv: string) {
setMyServer(srv);
setCurrentPage(1);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NovelChapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const NovelChapter = () => {

useEffect(() => {
if (isError) {
if (indexServer == listServer.length - 1)
if (listServer.length <= 0 || indexServer == listServer.length - 1)
navigate("/notfound", {
replace: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NovelPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const NovelPreview = () => {

useEffect(() => {
if (isError) {
if (indexServer == listServer.length - 1)
if (listServer.length <= 0 || indexServer == listServer.length - 1)
navigate("/notfound", {
replace: true,
});
Expand Down

0 comments on commit 5982d8d

Please sign in to comment.