aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/components
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-09-14 18:58:44 +0800
committercrupest <crupest@outlook.com>2023-09-20 18:50:08 +0800
commitbdc69c18c1986544497b6974ffe5d8e073e4be6d (patch)
tree4283f2fcc4af9b8849588e8db21e4f52d136a1e7 /FrontEnd/src/components
parentaef14be13c3bd9e93eeea598dbfbf707ba98d448 (diff)
downloadtimeline-bdc69c18c1986544497b6974ffe5d8e073e4be6d.tar.gz
timeline-bdc69c18c1986544497b6974ffe5d8e073e4be6d.tar.bz2
timeline-bdc69c18c1986544497b6974ffe5d8e073e4be6d.zip
...
Diffstat (limited to 'FrontEnd/src/components')
-rw-r--r--FrontEnd/src/components/hooks/index.ts1
-rw-r--r--FrontEnd/src/components/hooks/useAutoUnsubscribePromise.tsx23
-rw-r--r--FrontEnd/src/components/index.css1
3 files changed, 25 insertions, 0 deletions
diff --git a/FrontEnd/src/components/hooks/index.ts b/FrontEnd/src/components/hooks/index.ts
index 771b0e2a..98ce729e 100644
--- a/FrontEnd/src/components/hooks/index.ts
+++ b/FrontEnd/src/components/hooks/index.ts
@@ -2,3 +2,4 @@ export { useMobile } from "./responsive";
export { default as useClickOutside } from "./useClickOutside";
export { default as useScrollToBottom } from "./useScrollToBottom";
export { default as useWindowLeave } from "./useWindowLeave";
+export { default as useAutoUnsubscribePromise } from "./useAutoUnsubscribePromise";
diff --git a/FrontEnd/src/components/hooks/useAutoUnsubscribePromise.tsx b/FrontEnd/src/components/hooks/useAutoUnsubscribePromise.tsx
new file mode 100644
index 00000000..78e21151
--- /dev/null
+++ b/FrontEnd/src/components/hooks/useAutoUnsubscribePromise.tsx
@@ -0,0 +1,23 @@
+import { useEffect, DependencyList } from "react";
+
+export default function useAutoUnsubscribePromise<T>(
+ promiseGenerator: () => Promise<T> | null | undefined,
+ resultHandler: (data: T) => void,
+ dependencies?: DependencyList | undefined,
+) {
+ useEffect(() => {
+ let subscribe = true;
+ const promise = promiseGenerator();
+ if (promise) {
+ void promise.then((data) => {
+ if (subscribe) {
+ resultHandler(data);
+ }
+ });
+
+ return () => {
+ subscribe = false;
+ };
+ }
+ }, dependencies);
+}
diff --git a/FrontEnd/src/components/index.css b/FrontEnd/src/components/index.css
index de156e0e..83b48318 100644
--- a/FrontEnd/src/components/index.css
+++ b/FrontEnd/src/components/index.css
@@ -16,6 +16,7 @@ body {
textarea {
transition: border-color 0.3s;
border-color: var(--cru-text-minor-color);
+ background: var(--cru-background-color);
}
textarea:hover {