mirror of
https://github.com/ershisan99/todolist_next.git
synced 2026-01-27 05:12:08 +00:00
refactor
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import "../styles/globals.css";
|
||||
|
||||
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
||||
import { type AppType } from "next/dist/shared/lib/utils";
|
||||
|
||||
import "../styles/globals.css";
|
||||
import { QueryClient } from "@tanstack/query-core";
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { AuthRedirect } from "../components/AuthRedirect";
|
||||
import { AuthRedirect } from "@/components";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import type { ChangeEvent } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
import { type NextPage } from "next";
|
||||
import Head from "next/head";
|
||||
import { Button } from "../components/Button";
|
||||
|
||||
import { Todolist, Button, FullscreenLoader, Input } from "@/components";
|
||||
import {
|
||||
useCreateTodolistMutation,
|
||||
useLogoutMutation,
|
||||
useTodolistsQuery,
|
||||
} from "../services/hooks";
|
||||
import { Loader } from "../components/loader";
|
||||
import { Input } from "../components/Input";
|
||||
import type { ChangeEvent } from "react";
|
||||
import { useState } from "react";
|
||||
import Todolist from "../components/todolist";
|
||||
} from "@/services";
|
||||
|
||||
const Home: NextPage = () => {
|
||||
const [newTodolistTitle, setNewTodolistTitle] = useState("");
|
||||
@@ -22,24 +21,19 @@ const Home: NextPage = () => {
|
||||
logout();
|
||||
};
|
||||
|
||||
const { mutateAsync: createTodolist } = useCreateTodolistMutation();
|
||||
const { mutate: createTodolist } = useCreateTodolistMutation();
|
||||
|
||||
const handleAddTodolist = () => {
|
||||
createTodolist(newTodolistTitle).then((res) => {
|
||||
if (res.data.resultCode === 0) setNewTodolistTitle("");
|
||||
});
|
||||
createTodolist({ title: newTodolistTitle });
|
||||
setNewTodolistTitle("");
|
||||
};
|
||||
|
||||
const handleNewTodolistTitleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setNewTodolistTitle(e.target.value);
|
||||
};
|
||||
|
||||
if (isTodolistsLoading)
|
||||
return (
|
||||
<div className={"flex h-screen items-center justify-center"}>
|
||||
<Loader />
|
||||
</div>
|
||||
);
|
||||
if (isTodolistsLoading) return <FullscreenLoader />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
import React from "react";
|
||||
import type { ChangeEvent } from "react";
|
||||
import React, { useState } from "react";
|
||||
|
||||
import type { NextPage } from "next";
|
||||
import { Input } from "../components/Input";
|
||||
import { Button } from "../components/Button";
|
||||
import { useLoginMutation } from "../services/hooks";
|
||||
import { useRouter } from "next/router";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { Button, Input } from "@/components";
|
||||
import { useLoginMutation } from "@/services";
|
||||
|
||||
const Login: NextPage = () => {
|
||||
const { mutateAsync: login } = useLoginMutation();
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
const [email, setEmail] = React.useState("");
|
||||
const [password, setPassword] = React.useState("");
|
||||
const [remember, setRemember] = React.useState(true);
|
||||
const { mutate: login } = useLoginMutation();
|
||||
|
||||
const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [remember, setRemember] = useState(true);
|
||||
|
||||
const handlePasswordChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setPassword(e.target.value);
|
||||
};
|
||||
|
||||
const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleEmailChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setEmail(e.target.value);
|
||||
};
|
||||
|
||||
const handleRememberChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleRememberChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setRemember(e.target.checked);
|
||||
};
|
||||
|
||||
@@ -31,9 +30,6 @@ const Login: NextPage = () => {
|
||||
email,
|
||||
password,
|
||||
rememberMe: remember,
|
||||
}).then(() => {
|
||||
queryClient.invalidateQueries(["me"]);
|
||||
router.push("/");
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user