Skip to content

Commit e4f7ec4

Browse files
authored
Merge pull request #37 from unboxed/pqlqxa-codex/add-cool-feature
Add dark mode toggle
2 parents dc4bc56 + 34db183 commit e4f7ec4

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/App.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function App () {
121121
const [geojson, setGeojson] = useState(null);
122122
const [loading, setLoading] = useState(true);
123123
const [map, setMap] = useState(null);
124+
const [darkMode, setDarkMode] = useState(false);
124125
let toDisplay, allResults = [];
125126

126127
useEffect(() => {
@@ -226,6 +227,10 @@ function App () {
226227
toDisplay = searchMapArea(map);
227228
}
228229

230+
function toggleDarkMode() {
231+
setDarkMode((prev) => !prev);
232+
}
233+
229234
async function filterTableArea(event) {
230235
filterTable(event, toDisplay);
231236
}
@@ -274,15 +279,18 @@ function App () {
274279
<MapContainer ref={setMap} center={[51.505, -0.09]} zoom={13}>
275280
<TileLayer
276281
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
277-
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
282+
url={darkMode ? "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png" : "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}
278283
/>
279284
<GeoJSON data={geojson} onEachFeature={onEachFeature} />
280285
<div>
281286
<LocationMarker />
282-
<Button onClick={searchArea} buttonColour="#f3f2f1" buttonHoverColour="#ffdd00" buttonShadowColour="#929191" buttonTextColour="#0b0c0c"
287+
<Button onClick={searchArea} buttonColour="#f3f2f1" buttonHoverColour="#ffdd00" buttonShadowColour="#929191" buttonTextColour="#0b0c0c"
283288
style={{ position: 'absolute', bottom: '-4%', marginLeft: "11em", zIndex: 4000, width: '170px' }}>
284289
Search this area
285-
</Button>
290+
</Button>
291+
<Button onClick={toggleDarkMode} style={{ position: 'absolute', bottom: '-4%', marginLeft: "24em", zIndex: 4000, width: '150px' }}>
292+
{darkMode ? 'Light Mode' : 'Dark Mode'}
293+
</Button>
286294
</div>
287295
</MapContainer>
288296
</div>

src/App.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
2+
import { render, screen, waitFor, waitForElementToBeRemoved, fireEvent } from '@testing-library/react';
33
import '@testing-library/jest-dom/extend-expect';
44
import App from './App';
55
import axios from 'axios';
@@ -134,3 +134,21 @@ test("Status filter can exclude some values", async () => {
134134
expect(referenceElement1.parentElement.style.display).toEqual("none");
135135
// expect(referenceElement2.parentElement.style.display).not.toEqual("none");
136136
});
137+
138+
test('Dark mode toggle changes button label', async () => {
139+
axios.get.mockResolvedValue({
140+
data: {
141+
data: {},
142+
links: { next: null },
143+
},
144+
});
145+
146+
render(<App />);
147+
148+
await waitForElementToBeRemoved(() => screen.queryByText('Loading...'));
149+
150+
const toggleButton = screen.getByRole('button', { name: /dark mode/i });
151+
fireEvent.click(toggleButton);
152+
153+
expect(screen.getByRole('button', { name: /light mode/i })).toBeInTheDocument();
154+
});

0 commit comments

Comments
 (0)