Skip to content

Commit 97d6b06

Browse files
refactor: ErrorModal pt.2
1 parent 4f037a5 commit 97d6b06

2 files changed

Lines changed: 174 additions & 130 deletions

File tree

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import React from 'react';
2+
import { Simulators, TypeOfSimulator } from 'renderer/utils/SimManager';
3+
import { Button, ButtonType } from 'renderer/components/Button';
4+
import { Directories } from 'renderer/utils/Directories';
5+
import settings from 'renderer/rendererSettings';
6+
7+
type Error = {
8+
condition: boolean;
9+
title: string;
10+
description: React.ReactNode;
11+
actions: React.ReactNode;
12+
};
13+
14+
export const errorConfig = (
15+
platform: string,
16+
errors: {
17+
noSimInstalled: boolean;
18+
msfs2020BasePathError: boolean;
19+
msfs2024BasePathError: boolean;
20+
msfs2020InstallError: boolean;
21+
msfs2024InstallError: boolean;
22+
tempLocationError: boolean;
23+
},
24+
handlers: {
25+
enableSimulator: (sim: TypeOfSimulator) => void;
26+
handleSelectSimulatorBasePath: (sim: TypeOfSimulator) => Promise<void>;
27+
handleSimulatorNotInstalled: (sim: TypeOfSimulator) => void;
28+
handleSelectInstallPath: (sim: TypeOfSimulator) => Promise<void>;
29+
handleSelectTempLocation: () => Promise<void>;
30+
resetTempLocation: () => void;
31+
},
32+
): Error[] => [
33+
{
34+
condition: errors.noSimInstalled,
35+
title: 'No simulator detected',
36+
description: (
37+
<>
38+
{
39+
"We could not find an installed simulator. Please select for which simulator you'd like to manage your addons. You can change your selection any time in the settings."
40+
}
41+
</>
42+
),
43+
actions: (
44+
<>
45+
<Button type={ButtonType.Neutral} onClick={() => handlers.enableSimulator(Simulators.Msfs2020)}>
46+
Microsoft Flight Simulator 2020
47+
</Button>
48+
<Button type={ButtonType.Neutral} onClick={() => handlers.enableSimulator(Simulators.Msfs2024)}>
49+
Microsoft Flight Simulator 2024
50+
</Button>
51+
</>
52+
),
53+
},
54+
{
55+
condition: errors.msfs2020BasePathError,
56+
title: 'MSFS 2020 base path missing',
57+
description: (
58+
<>
59+
{"We couldn't determine the correct MSFS 2020 base path. Please select it manually."} <br />
60+
{platform === 'linux'
61+
? 'Usually: ~/.local/share/Steam/steamapps/compatdata/<APPID>/pfx/drive_c/users/steamuser/AppData/Microsoft Flight Simulator/'
62+
: 'Usually: "%LOCALAPPDATA%\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache"'}
63+
</>
64+
),
65+
actions: (
66+
<>
67+
<Button type={ButtonType.Neutral} onClick={() => handlers.handleSelectSimulatorBasePath(Simulators.Msfs2020)}>
68+
Select Path
69+
</Button>
70+
<Button type={ButtonType.Neutral} onClick={() => handlers.handleSimulatorNotInstalled(Simulators.Msfs2020)}>
71+
{"I don't have MSFS 2020 installed"}
72+
</Button>
73+
</>
74+
),
75+
},
76+
{
77+
condition: errors.msfs2024BasePathError,
78+
title: 'MSFS 2024 base path missing',
79+
description: (
80+
<>
81+
{"We couldn't determine the correct MSFS 2024 base path. Please select it manually."} <br />
82+
{platform === 'linux'
83+
? 'You can usually find it somewhere here:\n~/.local/share/Steam/steamapps/compatdata/<APPID>/pfx/drive_c/users/steamuser/AppData/Microsoft Flight Simulator 2024/'
84+
: 'You can usually find it somewhere here:\n"%LOCALAPPDATA%\\Packages\\Microsoft.Limitless_8wekyb3d8bbwe\\LocalCache"'}
85+
</>
86+
),
87+
actions: (
88+
<>
89+
<Button type={ButtonType.Neutral} onClick={() => handlers.handleSelectSimulatorBasePath(Simulators.Msfs2024)}>
90+
Select Path
91+
</Button>
92+
<Button type={ButtonType.Neutral} onClick={() => handlers.handleSimulatorNotInstalled(Simulators.Msfs2024)}>
93+
{"I don't have MSFS 2024 installed"}
94+
</Button>
95+
</>
96+
),
97+
},
98+
{
99+
condition: errors.msfs2020InstallError,
100+
title: 'MSFS 2020 Community folder not found',
101+
description: (
102+
<>
103+
Your MSFS 2020 Community folder is set to:
104+
<pre className="mx-auto my-2 w-3/5 overflow-x-auto rounded-lg bg-gray-700 px-6 py-2.5 text-center font-mono text-2xl">
105+
{Directories.installLocation(Simulators.Msfs2020) || 'not set'}
106+
</pre>
107+
{"but we couldn't find it there. Please set the correct location before continuing."}
108+
</>
109+
),
110+
actions: (
111+
<Button type={ButtonType.Neutral} onClick={() => handlers.handleSelectInstallPath(Simulators.Msfs2020)}>
112+
Select Path
113+
</Button>
114+
),
115+
},
116+
{
117+
condition: errors.msfs2024InstallError,
118+
title: 'MSFS 2024 Community folder not found',
119+
description: (
120+
<>
121+
Your MSFS 2024 Community folder is set to:
122+
<pre className="mx-auto my-2 w-3/5 overflow-x-auto rounded-lg bg-gray-700 px-6 py-2.5 text-center font-mono text-2xl">
123+
{Directories.installLocation(Simulators.Msfs2024) || 'not set'}
124+
</pre>
125+
{"but we couldn't find it there. Please set the correct location before continuing."}
126+
</>
127+
),
128+
actions: (
129+
<Button type={ButtonType.Neutral} onClick={() => handlers.handleSelectInstallPath(Simulators.Msfs2024)}>
130+
Select Path
131+
</Button>
132+
),
133+
},
134+
{
135+
condition: errors.tempLocationError,
136+
title: 'Temporary folder not found',
137+
description: (
138+
<>
139+
Your location for temporary folders is set to:
140+
<pre className="mx-auto my-2 w-3/5 overflow-x-auto rounded-lg bg-gray-700 px-6 py-2.5 text-center font-mono text-2xl">
141+
{settings.get('mainSettings.tempLocation') || 'not set'}
142+
</pre>
143+
{"but we couldn't find it there. Please set the correct location before continuing."}
144+
</>
145+
),
146+
actions: (
147+
<>
148+
<Button type={ButtonType.Neutral} onClick={handlers.handleSelectTempLocation}>
149+
Select Path
150+
</Button>
151+
<Button type={ButtonType.Neutral} onClick={handlers.resetTempLocation}>
152+
Reset
153+
</Button>
154+
</>
155+
),
156+
},
157+
];

src/renderer/components/ErrorModal/index.tsx

Lines changed: 17 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@ import {
77
} from 'renderer/actions/install-path.utils';
88
import settings from 'renderer/rendererSettings';
99
import { Directories } from 'renderer/utils/Directories';
10-
import { Button, ButtonType } from 'renderer/components/Button';
1110
import * as os from 'os';
1211
import { ipcRenderer } from 'electron';
1312
import channels from 'common/channels';
14-
import { Simulators, TypeOfSimulator } from 'renderer/utils/SimManager';
13+
import { TypeOfSimulator } from 'renderer/utils/SimManager';
1514
import { useErrors } from './useErrors';
16-
17-
type Error = {
18-
condition: boolean;
19-
title: string;
20-
description: React.ReactNode;
21-
actions: React.ReactNode;
22-
};
15+
import { errorConfig } from './errorConfig';
2316

2417
const platform = os.platform();
2518
const reload = () => ipcRenderer.send(channels.window.reload);
@@ -74,131 +67,25 @@ export const ErrorModal = (): JSX.Element => {
7467
reload();
7568
};
7669

77-
const errors: Error[] = [
78-
{
79-
condition: noSimInstalled,
80-
title: 'No simulator detected',
81-
description: (
82-
<>
83-
We could not find an installed simulator. Please select for which simulator you’d like to manage your addons.
84-
You can change your selection any time in the settings.
85-
</>
86-
),
87-
actions: (
88-
<>
89-
<Button type={ButtonType.Neutral} onClick={() => enableSimulator(Simulators.Msfs2020)}>
90-
Microsoft Flight Simulator 2020
91-
</Button>
92-
<Button type={ButtonType.Neutral} onClick={() => enableSimulator(Simulators.Msfs2024)}>
93-
Microsoft Flight Simulator 2024
94-
</Button>
95-
</>
96-
),
97-
},
98-
{
99-
condition: msfs2020BasePathError,
100-
title: 'MSFS 2020 base path missing',
101-
description: (
102-
<>
103-
We couldn’t determine the correct MSFS 2020 base path. Please select it manually. <br />
104-
{platform === 'linux'
105-
? 'Usually: ~/.local/share/Steam/steamapps/compatdata/<APPID>/pfx/drive_c/users/steamuser/AppData/Microsoft Flight Simulator/'
106-
: 'Usually: "%LOCALAPPDATA%\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache"'}
107-
</>
108-
),
109-
actions: (
110-
<>
111-
<Button type={ButtonType.Neutral} onClick={() => handleSelectSimulatorBasePath(Simulators.Msfs2020)}>
112-
Select Path
113-
</Button>
114-
<Button type={ButtonType.Neutral} onClick={() => handleSimulatorNotInstalled(Simulators.Msfs2020)}>
115-
I don’t have MSFS 2020 installed
116-
</Button>
117-
</>
118-
),
119-
},
70+
const errors = errorConfig(
71+
platform,
12072
{
121-
condition: msfs2024BasePathError,
122-
title: 'MSFS 2024 base path missing',
123-
description: (
124-
<>
125-
We couldn’t determine the correct MSFS 2024 base path. Please select it manually. <br />
126-
{platform === 'linux'
127-
? 'You can usually find it somewhere here:\n~/.local/share/Steam/steamapps/compatdata/<APPID>/pfx/drive_c/users/steamuser/AppData/Microsoft Flight Simulator 2024/'
128-
: 'You can usually find it somewhere here:\n"%LOCALAPPDATA%\\Packages\\Microsoft.Limitless_8wekyb3d8bbwe\\LocalCache"'}
129-
</>
130-
),
131-
actions: (
132-
<>
133-
<Button type={ButtonType.Neutral} onClick={() => handleSelectSimulatorBasePath(Simulators.Msfs2024)}>
134-
Select Path
135-
</Button>
136-
<Button type={ButtonType.Neutral} onClick={() => handleSimulatorNotInstalled(Simulators.Msfs2024)}>
137-
I don’t have MSFS 2024 installed
138-
</Button>
139-
</>
140-
),
73+
noSimInstalled,
74+
msfs2020BasePathError,
75+
msfs2024BasePathError,
76+
msfs2020InstallError,
77+
msfs2024InstallError,
78+
tempLocationError,
14179
},
14280
{
143-
condition: msfs2020InstallError,
144-
title: 'MSFS 2020 Community folder not found',
145-
description: (
146-
<>
147-
Your MSFS 2020 Community folder is set to:
148-
<pre className="mx-auto my-2 w-3/5 overflow-x-auto rounded-lg bg-gray-700 px-6 py-2.5 text-center font-mono text-2xl">
149-
{Directories.installLocation(Simulators.Msfs2020) || 'not set'}
150-
</pre>
151-
but we couldn’t find it there. Please set the correct location before continuing.
152-
</>
153-
),
154-
actions: (
155-
<Button type={ButtonType.Neutral} onClick={() => handleSelectInstallPath(Simulators.Msfs2020)}>
156-
Select Path
157-
</Button>
158-
),
81+
enableSimulator,
82+
handleSelectSimulatorBasePath,
83+
handleSimulatorNotInstalled,
84+
handleSelectInstallPath,
85+
handleSelectTempLocation,
86+
resetTempLocation,
15987
},
160-
{
161-
condition: msfs2024InstallError,
162-
title: 'MSFS 2024 Community folder not found',
163-
description: (
164-
<>
165-
Your MSFS 2024 Community folder is set to:
166-
<pre className="mx-auto my-2 w-3/5 overflow-x-auto rounded-lg bg-gray-700 px-6 py-2.5 text-center font-mono text-2xl">
167-
{Directories.installLocation(Simulators.Msfs2024) || 'not set'}
168-
</pre>
169-
but we couldn’t find it there. Please set the correct location before continuing.
170-
</>
171-
),
172-
actions: (
173-
<Button type={ButtonType.Neutral} onClick={() => handleSelectInstallPath(Simulators.Msfs2024)}>
174-
Select Path
175-
</Button>
176-
),
177-
},
178-
{
179-
condition: tempLocationError,
180-
title: 'Temporary folder not found',
181-
description: (
182-
<>
183-
Your location for temporary folders is set to:
184-
<pre className="mx-auto my-2 w-3/5 overflow-x-auto rounded-lg bg-gray-700 px-6 py-2.5 text-center font-mono text-2xl">
185-
{settings.get('mainSettings.tempLocation') || 'not set'}
186-
</pre>
187-
but we couldn’t find it there. Please set the correct location before continuing.
188-
</>
189-
),
190-
actions: (
191-
<>
192-
<Button type={ButtonType.Neutral} onClick={handleSelectTempLocation}>
193-
Select Path
194-
</Button>
195-
<Button type={ButtonType.Neutral} onClick={resetTempLocation}>
196-
Reset
197-
</Button>
198-
</>
199-
),
200-
},
201-
];
88+
);
20289

20390
const activeError = errors.find((e) => e.condition);
20491

0 commit comments

Comments
 (0)