Skip to content

Commit 37a0993

Browse files
author
followDev
committed
chat loading fix
1 parent a3ae204 commit 37a0993

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

client/src/App.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type User = {
3030
export default function App() {
3131
const [messages, setMessages] = useState<Message[]>([]);
3232
const [loading, setLoading] = useState<boolean>(false);
33+
const [chatLoading, setChatloading] = useState(true);
3334
const [auth, setAuth] = useState<User | undefined>(() => {
3435
const user = localStorage.getItem("auth");
3536
if (!user) return undefined;
@@ -69,6 +70,9 @@ export default function App() {
6970
})
7071
.catch((err) => {
7172
console.log(err);
73+
})
74+
.finally(() => {
75+
setChatloading(false);
7276
});
7377
}, [auth]);
7478

@@ -108,6 +112,7 @@ export default function App() {
108112
)}
109113

110114
<Input
115+
chatLoading={chatLoading}
111116
handlelogout={handlelogout}
112117
img={auth?.avatar}
113118
apiKey={auth?.apiKey}

client/src/components/Input.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type InputProps = {
1010
apiKey: string;
1111
img: string;
1212
handlelogout: () => void;
13+
chatLoading: boolean;
1314
};
1415

1516
export default function Input({
@@ -18,6 +19,7 @@ export default function Input({
1819
apiKey,
1920
img,
2021
handlelogout,
22+
chatLoading,
2123
}: InputProps) {
2224
const [input, setInput] = useState<string>("");
2325
function handleInput() {
@@ -69,6 +71,7 @@ export default function Input({
6971
}}
7072
>
7173
<input
74+
disabled={chatLoading}
7275
autoFocus={true}
7376
onKeyDown={(e) => e.keyCode === 13 && input != "" && handleInput()}
7477
onChange={(e) => setInput(e.target.value)}

0 commit comments

Comments
 (0)