Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/scan-go/mobile-ionic into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammedKpln committed Feb 27, 2024
2 parents c453f04 + 5a253c3 commit 998e72f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Suspense, useEffect } from "react";
import AppLoading from "./components/App/AppLoading";
import AppUrlListener from "./components/App/AppUrlListener";
import { useAppTheme } from "./hooks/app/useAppTheme";
import { useIsNative } from "./hooks/app/useIsNative";
import { useSplashScreen } from "./hooks/app/useSplashScreen";
import AppRoutes from "./routes/routes";
import { useAuthStore } from "./stores/auth.store";
Expand All @@ -30,23 +31,24 @@ import "./theme/variables.scss";
setupIonicReact();

export default function App() {
const isInitialized = useAuthStore((state) => state.isInitialized);
const listenToAuthClient = useAuthStore((state) => state.listenToAuthClient);

const { isNative } = useIsNative(false);
useAppTheme();
useSplashScreen();
const { showLoading, hideLoading } = useSplashScreen();

useEffect(() => {
const listener = listenToAuthClient();

if (!isNative) {
showLoading("Värmer upp...");
}

return () => {
hideLoading();
listener.data.subscription.unsubscribe();
};
}, []);

if (!isInitialized) {
return <AppLoading message="Starting App..." />;
}

return (
<IonApp>
<Suspense fallback={<AppLoading message="Loading route..." />}>
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/app/useSplashScreen.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { useAuthStore } from "@/stores/auth.store";
import { SplashScreen } from "@capacitor/splash-screen";
import { useIonLoading } from "@ionic/react";
import { useEffect } from "react";

export function useSplashScreen() {
const isInitialized = useAuthStore((state) => state.isInitialized);
const [showLoading, hideLoading] = useIonLoading();

useEffect(() => {
if (isInitialized) {
SplashScreen.hide();
hideLoading();
}
}, [isInitialized]);

return {
showLoading,
hideLoading,
};
}
19 changes: 10 additions & 9 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import Providers from "./Providers";

const container = document.getElementById("root");
const root = createRoot(container!);
SplashScreen.show();

defineCustomElements(window);
SplashScreen.show().then(() => {
defineCustomElements(window);

root.render(
<React.StrictMode>
<Providers>
<App />
</Providers>
</React.StrictMode>
);
root.render(
<React.StrictMode>
<Providers>
<App />
</Providers>
</React.StrictMode>
);
});

0 comments on commit 998e72f

Please sign in to comment.