]> git.localhorst.tv Git - alttp.git/commitdiff
properly abort requests
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 12 Apr 2022 22:12:48 +0000 (00:12 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 12 Apr 2022 22:12:48 +0000 (00:12 +0200)
resources/js/components/pages/Tournament.js
resources/js/components/pages/User.js
resources/js/components/protocol/Protocol.js

index 00a19343c11b1c99c59d59937946f6ce85f89b17..061db2208a8a67ba35ddd05ff9fced3afd1323bf 100644 (file)
@@ -26,9 +26,10 @@ const Tournament = () => {
        const [tournament, setTournament] = useState(null);
 
        useEffect(() => {
+               const ctrl = new AbortController();
                setLoading(true);
                axios
-                       .get(`/api/tournaments/${id}`)
+                       .get(`/api/tournaments/${id}`, { signal: ctrl.signal })
                        .then(response => {
                                setError(null);
                                setLoading(false);
@@ -40,6 +41,9 @@ const Tournament = () => {
                                setLoading(false);
                                setTournament(null);
                        });
+               return () => {
+                       ctrl.abort();
+               };
        }, [id]);
 
        useEffect(() => {
index bb26bfae902e24fffec8501e6e6f1a34216b9546..3e868babb57f852190bf48e5d40511f1476d1361 100644 (file)
@@ -18,8 +18,9 @@ const User = () => {
 
        useEffect(() => {
                setLoading(true);
+               const ctrl = new AbortController();
                axios
-                       .get(`/api/users/${id}`)
+                       .get(`/api/users/${id}`, { signal: ctrl.signal })
                        .then(response => {
                                setError(null);
                                setLoading(false);
@@ -31,6 +32,9 @@ const User = () => {
                                setLoading(false);
                                setUser(null);
                        });
+               return () => {
+                       ctrl.abort();
+               };
        }, [id]);
 
        useEffect(() => {
index 7cd0b754b1b19944d0e5b1124b3a3932187dd43b..a2bb93060a3fce351938b60588a392d2d63d0a25 100644 (file)
@@ -13,11 +13,15 @@ const Protocol = ({ id }) => {
        const [protocol, setProtocol] = useState([]);
 
        useEffect(() => {
+               const ctrl = new AbortController();
                axios
-                       .get(`/api/protocol/${id}`)
+                       .get(`/api/protocol/${id}`, { signal: ctrl.signal })
                        .then(response => {
                                setProtocol(response.data);
                        });
+               return () => {
+                       ctrl.abort();
+               };
        }, [id]);
 
        useEffect(() => {