-
Notifications
You must be signed in to change notification settings - Fork 4
Fix: use explicit types instead of interface inheritance for hooks #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 +1,6 @@ | ||
| { | ||
| "name": "@developmentseed/stac-react", | ||
| "version": "1.0.0-alpha.1", | ||
| "version": "1.0.0-alpha.2", | ||
| "description": "React components and hooks for building STAC-API front-ends", | ||
| "repository": "[email protected]:developmentseed/stac-react.git", | ||
| "authors": [ | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ import { useCallback, useState, useMemo, useEffect } from 'react'; | |
| import { useQuery, useQueryClient } from '@tanstack/react-query'; | ||
| import debounce from '../utils/debounce'; | ||
| import { generateStacSearchQueryKey } from '../utils/queryKeys'; | ||
| import type { StacHook } from '../types'; | ||
| import { handleStacResponse } from '../utils/handleStacResponse'; | ||
| import type { | ||
| Link, | ||
|
|
@@ -17,7 +16,7 @@ import { ApiError } from '../utils/ApiError'; | |
|
|
||
| type PaginationHandler = () => void; | ||
|
|
||
| interface StacSearchHook extends StacHook { | ||
| type StacSearchHook = { | ||
| ids?: string[]; | ||
| setIds: (ids?: string[]) => void; | ||
| bbox?: Bbox; | ||
|
|
@@ -34,9 +33,12 @@ interface StacSearchHook extends StacHook { | |
| setLimit: (limit: number) => void; | ||
| submit: () => void; | ||
| results?: SearchResponse; | ||
| isLoading: boolean; | ||
| isFetching: boolean; | ||
| error: ApiError | null; | ||
| nextPage: PaginationHandler | undefined; | ||
| previousPage: PaginationHandler | undefined; | ||
| } | ||
| }; | ||
|
|
||
| function useStacSearch(): StacSearchHook { | ||
| const { stacApi } = useStacApiContext(); | ||
|
|
@@ -212,7 +214,7 @@ function useStacSearch(): StacSearchHook { | |
| results, | ||
| isLoading, | ||
| isFetching, | ||
| error, | ||
| error: error ?? null, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error is already null. Why is this needed? |
||
| sortby, | ||
| setSortby, | ||
| limit, | ||
|
|
||
This file contains hidden or 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,26 +1,3 @@ | ||
| import type { QueryObserverResult } from '@tanstack/react-query'; | ||
| import { ApiError } from '../utils/ApiError'; | ||
|
|
||
| export type GenericObject = { | ||
| [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any | ||
| }; | ||
|
|
||
| /** | ||
| * Base interface for all STAC hooks providing common loading state and error handling. | ||
| * All data-fetching hooks (useCollection, useCollections, useItem, useStacSearch) | ||
| * extend this interface with their specific data and refetch signatures. | ||
| */ | ||
| export interface StacHook { | ||
| /** True during initial data fetch (no cached data available) */ | ||
| isLoading: boolean; | ||
| /** True during any fetch operation (including background refetches) */ | ||
| isFetching: boolean; | ||
| /** Error information if the last request was unsuccessful */ | ||
| error: ApiError | null; | ||
| } | ||
|
|
||
| /** | ||
| * Generic refetch function type for STAC hooks. | ||
| * Returns a Promise with the query result including data and error information. | ||
| */ | ||
| export type StacRefetchFn<T> = () => Promise<QueryObserverResult<T, ApiError>>; | ||
|
Comment on lines
-7
to
-26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to keep this pattern and have the types correctly exported. Was there any reason not to? |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could extend with types too like