-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the `splashScreen.content` prop becomes unwieldy, we can move it to a separate config file. Closes #65
- Loading branch information
Showing
9 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useState } from 'react'; | ||
import { Button, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; | ||
import useLocalStorage from '../hooks/useLocalStorage'; | ||
import config from '../services/config'; | ||
|
||
export default function SplashScreen() { | ||
const [showOnLoad, setShowOnLoad] = useLocalStorage('wfrc-rtp-show-splash', true, true); | ||
const [isOpen, setIsOpen] = useState(showOnLoad); | ||
|
||
const toggle = () => setIsOpen(!isOpen); | ||
|
||
return ( | ||
<Modal isOpen={isOpen} toggle={toggle} centered> | ||
<ModalHeader toggle={toggle}>{config.splashScreen.title}</ModalHeader> | ||
<ModalBody> | ||
<div dangerouslySetInnerHTML={{ __html: config.splashScreen.content }}></div> | ||
</ModalBody> | ||
<ModalFooter className="d-flex flex-direction-row justify-content-between"> | ||
<FormGroup check inline> | ||
<Label check> | ||
<Input type="checkbox" onChange={(event) => setShowOnLoad(!event.target.checked)} checked={!showOnLoad} /> | ||
Don't Show This Again | ||
</Label> | ||
</FormGroup> | ||
<Button color="primary" onClick={toggle}> | ||
Dismiss | ||
</Button> | ||
</ModalFooter> | ||
</Modal> | ||
); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/services/useFilterReducer.js → src/hooks/useFilterReducer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/services/useFilterReducer.test.js → src/hooks/useFilterReducer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useState } from 'react'; | ||
|
||
export default function (key, initialValue, parseWithJSON = false) { | ||
const getValueFromLocalStorage = () => { | ||
const value = localStorage.getItem(key); | ||
|
||
return parseWithJSON ? JSON.parse(value) : value; | ||
}; | ||
|
||
const [value, setValue] = useState(() => getValueFromLocalStorage() ?? initialValue); | ||
|
||
const setNewValue = (newValue) => { | ||
setValue(newValue); | ||
localStorage.setItem(key, parseWithJSON ? JSON.stringify(newValue) : newValue); | ||
}; | ||
|
||
return [value, setNewValue]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import useLocalStorage from './useLocalStorage'; | ||
|
||
describe('useLocalStorage', () => { | ||
beforeEach(() => { | ||
vi.mock('react', () => { | ||
return { | ||
useState: (initialValue) => [initialValue(), () => {}], | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it('can parse using JSON', () => { | ||
const localStorageMock = { | ||
getItem: vi.fn().mockReturnValue('{"a":1}'), | ||
setItem: vi.fn(), | ||
}; | ||
vi.stubGlobal('localStorage', localStorageMock); | ||
|
||
const [value, setValue] = useLocalStorage('key', { a: 1 }, true); | ||
|
||
expect(localStorageMock.getItem).toHaveBeenCalledWith('key'); | ||
expect(value).toEqual({ a: 1 }); | ||
|
||
setValue({ a: 2 }); | ||
|
||
expect(localStorageMock.setItem).toHaveBeenCalledWith('key', '{"a":2}'); | ||
}); | ||
|
||
it('returns the initial value if none is in storage', () => { | ||
const localStorageMock = { | ||
getItem: vi.fn().mockReturnValue(undefined), | ||
setItem: vi.fn(), | ||
}; | ||
vi.stubGlobal('localStorage', localStorageMock); | ||
|
||
const initialValue = 'test value'; | ||
|
||
const [value] = useLocalStorage('key', initialValue); | ||
|
||
expect(value).toEqual(initialValue); | ||
}); | ||
|
||
it('returns the value from storage if it exists', () => { | ||
const localStorageValue = 'changed value'; | ||
const localStorageMock = { | ||
getItem: vi.fn().mockReturnValue(localStorageValue), | ||
setItem: vi.fn(), | ||
}; | ||
vi.stubGlobal('localStorage', localStorageMock); | ||
|
||
const initialValue = 'test value'; | ||
|
||
const [value] = useLocalStorage('key', initialValue); | ||
|
||
expect(value).toEqual(localStorageValue); | ||
}); | ||
}); |