Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Implement delayed component to prevent loader flickering

Hakan Shehu58428584da02
diff --git a/desktop/src/components/app-loading.tsx b/desktop/src/components/app-loading.tsx
index 58215bff..3a344dd3 100644
--- a/desktop/src/components/app-loading.tsx
+++ b/desktop/src/components/app-loading.tsx
@@ -1,5 +1,5 @@
-import React from "react";
-import {Spinner} from "@/components/ui/spinner";
+import React from 'react';
+import { Spinner } from '@/components/ui/spinner';
export const AppLoading = () => {
return (
@@ -14,4 +14,4 @@ export const AppLoading = () => {
</div>
</div>
);
-}
\ No newline at end of file
+};
diff --git a/desktop/src/components/app.tsx b/desktop/src/components/app.tsx
index 979d35e8..68f575d3 100644
--- a/desktop/src/components/app.tsx
+++ b/desktop/src/components/app.tsx
@@ -16,6 +16,7 @@ import {
} from 'kysely';
import { AppDatabaseSchema } from '@/electron/schemas/app';
import { useQuery } from '@tanstack/react-query';
+import { DelayedComponent } from '@/components/ui/delayed-component';
const SERVER_URL = 'http://localhost:3000';
@@ -70,7 +71,11 @@ export const App = () => {
const isLoading = accountsQuery.isPending || workspacesQuery.isPending;
if (isLoading) {
- return <AppLoading />;
+ return (
+ <DelayedComponent>
+ <AppLoading />
+ </DelayedComponent>
+ );
}
if (accountsQuery.data.rows.length == 0) {
diff --git a/desktop/src/components/ui/delayed-component.tsx b/desktop/src/components/ui/delayed-component.tsx
new file mode 100644
index 00000000..fc9f7905
--- /dev/null
+++ b/desktop/src/components/ui/delayed-component.tsx
@@ -0,0 +1,24 @@
+import React from 'react';
+
+interface DelayedComponentProps {
+ children: React.ReactNode;
+ delay?: number;
+}
+
+const DelayedComponent = ({ children, delay }: DelayedComponentProps) => {
+ const [shouldRender, setShouldRender] = React.useState(false);
+
+ React.useEffect(() => {
+ const timer = setTimeout(() => {
+ setShouldRender(true);
+ }, delay ?? 100);
+
+ return () => clearTimeout(timer);
+ }, [delay]);
+
+ return shouldRender ? <React.Fragment>{children}</React.Fragment> : null;
+};
+
+DelayedComponent.displayName = 'DelayedComponent';
+
+export { DelayedComponent };