-
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.
- Loading branch information
Showing
14 changed files
with
103 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
|
||
.launch-filter-list { | ||
position: fixed; | ||
z-index: 10; | ||
top: 6rem; | ||
left: -2rem; | ||
margin: 0; | ||
list-style: none; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import { AxiosError } from 'axios'; | ||
import type { Launch } from '../../../shared/api/types/Launch'; | ||
import { LaunchActions } from './actionTypesTemplates'; | ||
import { LaunchFilters } from '../constants/filerConstants'; | ||
import { LaunchActions } from './actionTypes'; | ||
import type { FilterAction } from '../types/LaunchesAction'; | ||
import type { Launch } from '../../../shared/api/types/Launch'; | ||
|
||
export const requesAction = (filterValue: LaunchFilters) => ({ | ||
type: `${filterValue}_${LaunchActions.LAUNCH_REQUEST}`, | ||
payload: { filterValue }, | ||
export const filterRequestAction = ( | ||
filterValue: LaunchFilters, | ||
): FilterAction => ({ | ||
type: `${filterValue}${LaunchActions.LAUNCH_REQUEST}`, | ||
payload: { filterValue, error: '' }, | ||
}); | ||
|
||
export const successAction = ( | ||
export const filterSuccessAction = ( | ||
filterValue: LaunchFilters, | ||
launches: Launch[], | ||
) => ({ | ||
type: `${filterValue}_${LaunchActions.LAUNCH_SUCCESS}`, | ||
payload: { filterValue: filterValue, [filterValue]: launches }, | ||
): FilterAction => ({ | ||
type: `${filterValue}${LaunchActions.LAUNCH_SUCCESS}`, | ||
payload: { filterValue, [filterValue]: launches, error: '' }, | ||
}); | ||
|
||
export const errorAction = (filterValue: LaunchFilters, error: AxiosError) => ({ | ||
type: `${filterValue}_${LaunchActions.LAUNCH_ERROR}`, | ||
payload: { filterValue: filterValue, error: error as AxiosError }, | ||
export const filterErrorAction = ( | ||
filterValue: LaunchFilters, | ||
error: string, | ||
): FilterAction => ({ | ||
type: `${filterValue}${LaunchActions.LAUNCH_ERROR}`, | ||
payload: { filterValue, error }, | ||
}); |
File renamed without changes.
22 changes: 13 additions & 9 deletions
22
src/components/LaunchFilter/actions/getFilteredLaunches.ts
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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { Dispatch } from 'react'; | ||
import { AnyAction } from '@reduxjs/toolkit'; | ||
import { AxiosError } from 'axios'; | ||
import type { LaunchResponse } from '../types/LaunchResponse'; | ||
import { | ||
filterErrorAction, | ||
filterRequestAction, | ||
filterSuccessAction, | ||
} from './actionCreators'; | ||
import { AppDispatch } from '../../../store'; | ||
import { LaunchFilters } from '../constants/filerConstants'; | ||
import { fetchLaunches } from '../services/fetchLaunches'; | ||
import { errorAction, requesAction, successAction } from './actionCreators'; | ||
import type { LaunchResponse } from '../types/LaunchResponse'; | ||
|
||
export const getFilteredLaunches = | ||
(filterValue: LaunchFilters) => | ||
async (dispatch: Dispatch<AnyAction>): Promise<void> => { | ||
dispatch(requesAction(filterValue)); | ||
async (dispatch: AppDispatch): Promise<void> => { | ||
dispatch(filterRequestAction(filterValue)); | ||
try { | ||
const response: LaunchResponse = await fetchLaunches(filterValue); | ||
dispatch(successAction(filterValue, response.data.results)); | ||
if (response.data.results.length === 0) | ||
throw new Error('Error 404. No matches.'); | ||
dispatch(filterSuccessAction(filterValue, response.data.results)); | ||
} catch (error) { | ||
dispatch(errorAction(filterValue, error as AxiosError)); | ||
dispatch(filterErrorAction(filterValue, (error as Error).message)); | ||
} | ||
}; |
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
5 changes: 2 additions & 3 deletions
5
src/components/LaunchFilter/components/FilterLink/FilterLink.tsx
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { axiosInstance } from '../../../shared/api/services/axiosInstance'; | ||
import { fetchLaunchConfig } from './fetchLaunchConfig'; | ||
import { axiosInstance } from '../../../shared/api/services/axiosInstance'; | ||
|
||
export const fetchLaunches = async (launchFilter: string) => | ||
await axiosInstance(fetchLaunchConfig(launchFilter)); |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import { Launch } from '../../../shared/api/types/Launch'; | ||
import { LaunchFilters } from '../constants/filerConstants'; | ||
|
||
export interface FilterActionPayload { | ||
filterValue: LaunchFilters; | ||
error: string; | ||
[LaunchFilters.PREVIOUS]?: Launch[]; | ||
[LaunchFilters.CREWED]?: Launch[]; | ||
[LaunchFilters.CALIFORNIA]?: Launch[]; | ||
[LaunchFilters.FLORIDA]?: Launch[]; | ||
} | ||
|
||
export interface FilterAction { | ||
type: string; | ||
payload: FilterActionPayload; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { combineReducers, configureStore } from '@reduxjs/toolkit'; | ||
import { appReducer } from './app/reducer'; | ||
import { launchReducer } from '../components/LaunchFilter/reducers/launchReducer'; | ||
|
||
const reducer = combineReducers({ | ||
app: appReducer, | ||
launches: launchReducer, | ||
}); | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
app: appReducer, | ||
}, | ||
reducer, | ||
middleware: getDefaultMiddleware => | ||
getDefaultMiddleware({ | ||
serializableCheck: false, | ||
}), | ||
}); | ||
|
||
export type StoreState = ReturnType<typeof store.getState>; | ||
export type AppDispatch = typeof store.dispatch; |