Skip to content

Commit

Permalink
fix: FRON-36 Migrate default values from hydrating the state to stric…
Browse files Browse the repository at this point in the history
…tly populating the ui (#39)
  • Loading branch information
Lombardoc4 committed Jun 10, 2024
1 parent 87e48c1 commit 0bcdb55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/components/QueryNav/DropdownGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export const DropdownGroup = () => {
// *** Param variables
const seasonParam =
searchParams.get('season') || new Date().getFullYear().toString();
const eventParam = searchParams.get('event') || eventDefault;
const sessionParam = searchParams.get('session') || sessionDefault;
const driversParam = searchParams.get('drivers') || driverDefault;
const eventParam = searchParams.get('event') || '';
const sessionParam = searchParams.get('session') || '';
const driversParam = searchParams.get('drivers') || '';

// *** Handles hydration on page load
// Populate state from params
Expand Down Expand Up @@ -165,7 +165,7 @@ export const DropdownGroup = () => {
action={(value) => dropdownAction('season', value)}
/>
<Dropdown
value={event}
value={event || eventDefault}
items={
// Todo remove logic from jsx
eventList.length <= 0
Expand All @@ -175,12 +175,12 @@ export const DropdownGroup = () => {
action={(value) => dropdownAction('event', value)}
/>
<Dropdown
value={session}
value={session || sessionDefault}
items={sessionList}
action={(value) => dropdownAction('session', value)}
/>
<Dropdown
value={driver}
value={driver || driverDefault}
items={
driverList.length <= 0
? []
Expand Down
6 changes: 4 additions & 2 deletions src/state-mgmt/fetchCalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,18 @@ export const fetchDriverList = atomEffect((get, set) => {
const eventList = get(EventListState);

// This indicated eventList has not been fetched has not loaded
if (eventName && eventList.length <= 0) {
// Or that no event has been input
if (!eventName || (eventName && eventList.length <= 0)) {
return;
}

// Find specfic event from event states
const event = eventList.find((evt) => evt.EventName === eventName);

// Set error if no matching event && there is an event specified
if (!event && eventName !== eventDefault) {
set(serverErrorState, eventErrorMsg);
return;
// return;
}

// Confirm event exists
Expand Down

0 comments on commit 0bcdb55

Please sign in to comment.