Normalize this code.

This commit is contained in:
Dane Everitt 2021-04-04 09:45:20 -07:00
parent c71c1e57db
commit 52308af74d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -46,9 +46,9 @@ const ActivePill = ({ active }: { active: boolean }) => (
); );
export default () => { export default () => {
const params = useParams() as Params;
const history = useHistory(); const history = useHistory();
const state: State = useLocation().state; const { state } = useLocation<State>();
const { id: scheduleId } = useParams<Params>();
const id = ServerContext.useStoreState(state => state.server.data!.id); const id = ServerContext.useStoreState(state => state.server.data!.id);
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
@ -61,20 +61,20 @@ export default () => {
const appendSchedule = ServerContext.useStoreActions(actions => actions.schedules.appendSchedule); const appendSchedule = ServerContext.useStoreActions(actions => actions.schedules.appendSchedule);
useEffect(() => { useEffect(() => {
if (schedule?.id === Number(params.id)) { if (schedule?.id === Number(scheduleId)) {
setIsLoading(false); setIsLoading(false);
return; return;
} }
clearFlashes('schedules'); clearFlashes('schedules');
getServerSchedule(uuid, Number(params.id)) getServerSchedule(uuid, Number(scheduleId))
.then(schedule => appendSchedule(schedule)) .then(schedule => appendSchedule(schedule))
.catch(error => { .catch(error => {
console.error(error); console.error(error);
clearAndAddHttpError({ error, key: 'schedules' }); clearAndAddHttpError({ error, key: 'schedules' });
}) })
.then(() => setIsLoading(false)); .then(() => setIsLoading(false));
}, [ params ]); }, [ scheduleId ]);
const toggleEditModal = useCallback(() => { const toggleEditModal = useCallback(() => {
setShowEditModal(s => !s); setShowEditModal(s => !s);