toggleFavourite(id, fav, "CUSTOM")}
+ disabled={!canCreateBoard}
+ disabledReason={!canCreateBoard ? t("Templates.TemplateCard.signInToCreateBoards") : undefined}
+ key={template.id}
+ />
+ ));
+ };
+
return (
<>
{/* settings */}
@@ -183,25 +214,7 @@ export const Templates = () => {
{renderContainerHeader("right", t("Templates.savedTemplates"))}
- {sortBy(
- templates
- .filter((template) => template.type === "CUSTOM")
- .filter(matchSearchInput)
- .filter(excludeDefaultTemplate),
- (template: Template) => !template.favourite
- ).map((template: Template) => (
- toggleFavourite(id, fav, "CUSTOM")}
- disabled={!canCreateBoard}
- disabledReason={!canCreateBoard ? t("Templates.TemplateCard.signInToCreateBoards") : undefined}
- key={template.id}
- />
- ))}
+ {renderCustomTemplatesContent()}
)}
diff --git a/src/utils/hooks/useDelayedLoading.ts b/src/utils/hooks/useDelayedLoading.ts
new file mode 100644
index 0000000000..8174f784d4
--- /dev/null
+++ b/src/utils/hooks/useDelayedLoading.ts
@@ -0,0 +1,22 @@
+import {useEffect, useState} from "react";
+
+// this hook delays the loading indicator (or in fact any boolean state) by a specified amount of time to prevent render flickering when the state changes quickly
+export const useDelayedLoading = (isLoading: boolean, delay = 200) => {
+ const [showLoading, setShowLoading] = useState(false);
+
+ useEffect(() => {
+ let timeout: ReturnType;
+
+ if (isLoading) {
+ timeout = setTimeout(() => {
+ setShowLoading(true);
+ }, delay);
+ } else {
+ setShowLoading(false);
+ }
+
+ return () => clearTimeout(timeout);
+ }, [isLoading, delay]);
+
+ return showLoading;
+};