-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
125 lines (107 loc) · 3.52 KB
/
App.jsx
File metadata and controls
125 lines (107 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// ANCHOR External Modules
import { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
// ANCHOR Internal Modules
import modeState from './recoil/atoms';
import Deployment from './Components/Deployment/Deployment';
import Action from './Components/Action/Action';
import Descriptions from './Components/Descriptions/Descriptions';
import GeneratedCommand from './Components/Command/GeneratedCommand';
// ANCHOR Images
import logo_dark from './images/Sourcegraph_Logo_FullColor_dark.png';
import logo_light from './images/Sourcegraph_Logo_FullColor_light.png';
// ANCHOR CSS
import './App.css';
function App() {
// determine user preference for dark or light mode.
const [mode, setMode] = useRecoilState(modeState)
// Use search params if present in URL
const queryParams = new URLSearchParams(window.location.search);
const deployment = queryParams.get('deployment');
const action = queryParams.get('function');
const nSpace = queryParams.get('namespace');
const opt = queryParams.get('option');
// States
const [selectedDeployment, setSelectedDeployment] = useState(deployment || "select-deployment");
const [selectedAction, setSelectedAction] = useState(action || "Function")
const [namespace, setNamespace] = useState(nSpace || "");
const [hasNamespace, setHasNamespace] = useState(nSpace ? true : false);
const [option, setOption] = useState(opt || "");
const [command, setCommand] = useState("");
const [generatedURI, setGeneratedURI] = useState("");
useEffect(() => {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
setMode('dark');
}
}, [mode, setMode])
return (
<div className={`App ${mode === 'dark' && "dark"}`}>
<img
alt={`sourcegraph-logo ${mode === "dark" && "dark"}`}
src={mode === 'dark'
? logo_dark
: logo_light}
className="logo"
/>
{mode === "dark" ? (
<h2 className="subtitle dark">command line generator</h2>
) : (
<h2 className="subtitle">command line generator</h2>
)}
<div className="container">
{/* USER selects their deployment */}
<div className="deploy-container">
<Deployment
selectedDeployment={selectedDeployment}
setSelectedDeployment={setSelectedDeployment}
setSelectedAction={setSelectedAction}
hasNamespace={hasNamespace}
setHasNamespace={setHasNamespace}
namespace={namespace}
setNamespace={setNamespace}
setCommand={setCommand}
setOption={setOption}
setGeneratedURI={setGeneratedURI}
mode={mode}
/>
{/* USER selects the function they want */}
<Action
selectedDeployment={selectedDeployment}
selectedAction={selectedAction}
setSelectedAction={setSelectedAction}
option={option}
setOption={setOption}
command={command}
setCommand={setCommand}
hasNamespace={hasNamespace}
namespace={namespace}
setGeneratedURI={setGeneratedURI}
mode={mode}
/>
</div>
<div className="line-break">
</div>
<div className="descriptions-container">
<Descriptions
selectedDeployment={selectedDeployment}
mode={mode}
/>
</div>
</div>
{/* Command generated from the first two options. */}
<div className="user-options-container">
<GeneratedCommand
selectedDeployment={selectedDeployment}
selectedAction={selectedAction}
command={command}
namespace={namespace}
option={option}
setGeneratedURI={setGeneratedURI}
generatedURI={generatedURI}
mode={mode}
/>
</div>
</div>
);
}
export default App;