more busy stuff

This commit is contained in:
Stepan Usatiuk
2023-12-17 18:25:21 +01:00
parent c31e32cc0e
commit 38de33fee5
3 changed files with 20 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import "./Post.scss"; import "./Post.scss";
import { Form, Link, useSubmit } from "react-router-dom"; import { Form, Link, useNavigation, useSubmit } from "react-router-dom";
import { useState } from "react"; import { useState } from "react";
import "./PostForm.scss"; import "./PostForm.scss";
@@ -19,6 +19,8 @@ export function Post({
}) { }) {
const [editing, setEditing] = useState(false); const [editing, setEditing] = useState(false);
const submit = useSubmit(); const submit = useSubmit();
const navigation = useNavigation();
const busy = navigation.state === "submitting";
if (editing) { if (editing) {
return ( return (
@@ -38,6 +40,7 @@ export function Post({
setEditing(false); setEditing(false);
submit(e.currentTarget); submit(e.currentTarget);
}} }}
disabled={busy}
> >
save save
</button> </button>
@@ -72,6 +75,7 @@ export function Post({
name="intent" name="intent"
value="deletePost" value="deletePost"
type={"submit"} type={"submit"}
disabled={busy}
> >
delete delete
</button> </button>

View File

@@ -1,4 +1,4 @@
import { Form, Link, useLoaderData } from "react-router-dom"; import { Form, Link, useLoaderData, useNavigation } from "react-router-dom";
import { LoaderToType, profileLoader } from "./loaders"; import { LoaderToType, profileLoader } from "./loaders";
import { isError } from "./api/dto"; import { isError } from "./api/dto";
import { Post } from "./Post"; import { Post } from "./Post";
@@ -28,6 +28,8 @@ export function Profile({ self }: IProfileProps) {
if (!user || isError(user)) { if (!user || isError(user)) {
return <div>Error</div>; return <div>Error</div>;
} }
const navigation = useNavigation();
const busy = navigation.state === "submitting";
return ( return (
<div className={"profileView"}> <div className={"profileView"}>
@@ -42,7 +44,12 @@ export function Profile({ self }: IProfileProps) {
placeholder={"Write something!"} placeholder={"Write something!"}
name="text" name="text"
/> />
<button name="intent" value="post" type="submit"> <button
name="intent"
value="post"
type="submit"
disabled={busy}
>
Post Post
</button> </button>
</Form> </Form>

View File

@@ -1,5 +1,5 @@
import "./ProfileCard.scss"; import "./ProfileCard.scss";
import { Form, Link } from "react-router-dom"; import { Form, Link, useNavigation } from "react-router-dom";
export function ProfileCard({ export function ProfileCard({
username, username,
@@ -14,6 +14,9 @@ export function ProfileCard({
actions: boolean; actions: boolean;
alreadyFollowing: boolean; alreadyFollowing: boolean;
}) { }) {
const navigation = useNavigation();
const busy = navigation.state === "submitting";
return ( return (
<div className={"profileCard"}> <div className={"profileCard"}>
<div className={"profileInfo"}> <div className={"profileInfo"}>
@@ -33,6 +36,7 @@ export function ProfileCard({
type={"submit"} type={"submit"}
name={"intent"} name={"intent"}
value={"unfollow"} value={"unfollow"}
disabled={busy}
> >
unfollow unfollow
</button> </button>
@@ -44,6 +48,7 @@ export function ProfileCard({
type={"submit"} type={"submit"}
name={"intent"} name={"intent"}
value={"follow"} value={"follow"}
disabled={busy}
> >
follow follow
</button> </button>