Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: separate global hooks from app #1487

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist-isolation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
</script>
</body>

</html>
</html>
34 changes: 34 additions & 0 deletions src/App/AppEffects.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useEffect } from 'react';

import { useDetectMode, useDisableRefresh, useLangaugeResolver, useListenForExternalDependencies } from '@app/hooks';

import { fetchAppConfig } from '../store/useAppConfigStore.ts';
import setupLogger from '../utils/shared-logger.ts';
import useListenForCriticalProblem from '@app/hooks/useListenForCriticalProblem.tsx';
import { setMiningNetwork } from '@app/store/miningStoreActions.ts';
import useTauriEventsListener from '@app/hooks/app/useTauriEventsListener.ts';
import { useListenForAppUpdated } from '@app/hooks/app/useListenForAppUpdated.ts';

// This component is used to initialise the app and listen for any events that need to be listened to
// Created as separate component to avoid cluttering the main App component and unwanted re-renders

setupLogger();
export default function AppEffects() {
useDetectMode();
useDisableRefresh();
useLangaugeResolver();
useListenForExternalDependencies();
useListenForCriticalProblem();
useTauriEventsListener();
useListenForAppUpdated({ triggerEffect: true });

useEffect(() => {
async function initialize() {
await fetchAppConfig();
await setMiningNetwork();
}
void initialize();
}, []);

return null;
}
37 changes: 7 additions & 30 deletions src/App/AppWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
import { useEffect } from 'react';

import { useDetectMode, useDisableRefresh, useLangaugeResolver, useListenForExternalDependencies } from '@app/hooks';

import { fetchAppConfig } from '../store/useAppConfigStore.ts';
import setupLogger from '../utils/shared-logger.ts';
import useListenForCriticalProblem from '@app/hooks/useListenForCriticalProblem.tsx';
import { setMiningNetwork } from '@app/store/miningStoreActions.ts';
import App from './App.tsx';
import useTauriEventsListener from '@app/hooks/app/useTauriEventsListener.ts';
import { useListenForAppUpdated } from '@app/hooks/app/useListenForAppUpdated.ts';

// FOR ANYTHING THAT NEEDS TO BE INITIALISED
import AppEffects from './AppEffects.tsx';

setupLogger();
export default function AppWrapper() {
useDetectMode();
useDisableRefresh();
useLangaugeResolver();
useListenForExternalDependencies();
useListenForCriticalProblem();
useTauriEventsListener();
useListenForAppUpdated({ triggerEffect: true });

useEffect(() => {
async function initialize() {
await fetchAppConfig();
await setMiningNetwork();
}
void initialize();
}, []);

return <App />;
return (
<>
<AppEffects />
<App />
</>
);
}
7 changes: 3 additions & 4 deletions src/hooks/app/useListenForAppUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ interface ShowReleaseNotesPayload {
export const useListenForAppUpdated = (options: UseListenForAppUpdatedOptions) => {
const { triggerEffect } = options;
const { setDialogToShow } = useUIStore();
const { setReleaseNotes, setIsAppUpdateAvailable } = useAppStateStore((state) => ({
setReleaseNotes: state.setReleaseNotes,
setIsAppUpdateAvailable: state.setIsAppUpdateAvailable,
}));
const setReleaseNotes = useAppStateStore((state) => state.setReleaseNotes);
const setIsAppUpdateAvailable = useAppStateStore((state) => state.setIsAppUpdateAvailable);

useEffect(() => {
if (!triggerEffect) return;

Expand Down