Skip to content

Commit

Permalink
Refactor FetchState to use discriminated union
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Jan 8, 2025
1 parent 363166e commit 06a5ddf
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 83 deletions.
9 changes: 3 additions & 6 deletions frontend/shared/types/fetch-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export interface FetchingError {
details?: Record<string, string>
}

export interface FetchState {
isFetching: boolean
hasStarted?: boolean
isFinished?: boolean
fetchingError: FetchingError | null
}
export type FetchState =
| { status: 'idle' | 'fetching' | 'success'; error: null }
| { status: 'error'; error: FetchingError };
2 changes: 1 addition & 1 deletion frontend/shared/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const isNonRetryableErrorStatusCode = (statusCode: number | undefined) => {
* TODO: Update this function with other error codes if needed.
*/
export const isRetriable = (error: FetchingError) => {
const { statusCode, code } = error
const { statusCode, code } = error.error
return !(isNonRetryableErrorStatusCode(statusCode) || code === NO_RESULT)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const showCollectionExternalLink = computed(() => {
const { getI18nCollectionResultCountLabel } = useI18nResultsCount()
const resultsLabel = computed(() => {
if (mediaStore.resultCount === 0 && mediaStore.fetchState.isFetching) {
if (mediaStore.resultCount === 0 && mediaStore.fetchState.status === 'loading') {
return ""
}
const resultsCount = mediaStore.results[props.mediaType].count
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/VHeader/VHeaderDesktop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const uiStore = useUiStore()
const isSidebarVisible = inject<Ref<boolean>>(IsSidebarVisibleKey)
const isFetching = computed(() => mediaStore.fetchState.isFetching)
const isFetching = computed(() => mediaStore.fetchState.status === 'loading')
const { $sendCustomEvent } = useNuxtApp()
Expand Down
Loading

0 comments on commit 06a5ddf

Please sign in to comment.