-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from shinyichen/SCIX-290-asso-articles
SCIX-290 Add related materials in abstract
- Loading branch information
Showing
4 changed files
with
118 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './resolver'; | ||
export * from './types'; |
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,34 @@ | ||
import api, { ApiRequestConfig } from '@api/api'; | ||
import { ApiTargets } from '@api/models'; | ||
import { ADSQuery } from '@api/types'; | ||
import { QueryFunction, useQuery } from '@tanstack/react-query'; | ||
import { IADSApiResolverParams, IADSApiResolverResponse } from './types'; | ||
|
||
export enum ResolverKeys { | ||
LINKS = 'resolver/links', | ||
} | ||
|
||
export const resolverKeys = { | ||
links: (params: IADSApiResolverParams) => [params] as const, | ||
}; | ||
|
||
export const useResolverQuery: ADSQuery<IADSApiResolverParams, IADSApiResolverResponse> = (params, options) => { | ||
return useQuery({ | ||
queryKey: resolverKeys.links(params), | ||
queryFn: fetchLinks, | ||
meta: { params }, | ||
...options, | ||
}); | ||
}; | ||
|
||
export const fetchLinks: QueryFunction<IADSApiResolverResponse> = async ({ meta }) => { | ||
const { params } = meta as { params: IADSApiResolverParams }; | ||
|
||
const config: ApiRequestConfig = { | ||
method: 'GET', | ||
url: `${ApiTargets.RESOLVER}/${params.bibcode}/${params.link_type}`, | ||
}; | ||
|
||
const { data } = await api.request<IADSApiResolverResponse>(config); | ||
return data; | ||
}; |
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,21 @@ | ||
export interface IADSApiResolverParams { | ||
bibcode: string; | ||
link_type: string; // TODO: https://ui.adsabs.harvard.edu/help/api/api-docs.html#tag--resolver | ||
} | ||
|
||
export interface IADSApiResolverResponse { | ||
action: string; | ||
links: { | ||
count: number; | ||
link_type: string; | ||
records: [ | ||
{ | ||
bibcode: string; | ||
count: number; | ||
title: string; | ||
type: string; | ||
url: string; | ||
}, | ||
]; | ||
}; | ||
} |
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