Skip to content

Commit

Permalink
Update API endpoints to include limit parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Anoop K. Chandran committed Dec 10, 2023
1 parent 1a0ee65 commit 519fb73
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/apis/s2agAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const getIndexItem = async (paperId: string, debugMode = false): Promise<
return response.json as Reference;
};

export const getReferenceItems = async (paperId: string, debugMode = false): Promise<Reference[]> => {
const url = `${SEMANTIC_SCHOLAR_API_URL}/paper/${paperId}/references?fields=${SEMANTIC_FIELDS.join(',')}`;
export const getReferenceItems = async (paperId: string, limit = 100, debugMode = false): Promise<Reference[]> => {
const url = `${SEMANTIC_SCHOLAR_API_URL}/paper/${paperId}/references?limit=${limit}&fields=${SEMANTIC_FIELDS.join(',')}`;
const response = await requestUrl(url);
if (response.status !== 200) {
if (debugMode) console.log(`Error ${response.status}`); //TODO: better error handling
Expand All @@ -47,8 +47,8 @@ export const getReferenceItems = async (paperId: string, debugMode = false): Pro
return _.map(response.json.data, 'citedPaper');
};

export const getCitationItems = async (paperId: string, debugMode = false): Promise<Reference[]> => {
const url = `${SEMANTIC_SCHOLAR_API_URL}/paper/${paperId}/citations?fields=${SEMANTIC_FIELDS.join(',')}`;
export const getCitationItems = async (paperId: string, limit = 100, debugMode = false): Promise<Reference[]> => {
const url = `${SEMANTIC_SCHOLAR_API_URL}/paper/${paperId}/citations?limit=${limit}&fields=${SEMANTIC_FIELDS.join(',')}`;
const response = await requestUrl(url);
if (response.status !== 200) {
if (debugMode) console.log(`Error ${response.status}`); //TODO: better error handling
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const DEFAULT_SETTINGS: ReferenceMapSettings = {
linkCiteKey: true,
findZoteroCiteKeyFromID: true,
findCiteKeyFromLinksWithoutPrefix: false,
citedLimit: 100,
citingLimit: 100,
enableReferenceSorting: false,
sortByReference: 'year',
sortOrderReference: 'desc',
Expand Down
4 changes: 2 additions & 2 deletions src/data/viewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ViewManager {

const debugMode = this.plugin.settings.debugMode
try {
const references = await getReferenceItems(paperId, debugMode)
const references = await getReferenceItems(paperId, this.plugin.settings.citedLimit, debugMode)
this.refCache.set(paperId, references)
return references
} catch (e) {
Expand All @@ -114,7 +114,7 @@ export class ViewManager {

const debugMode = this.plugin.settings.debugMode
try {
const citations = await getCitationItems(paperId, debugMode)
const citations = await getCitationItems(paperId, this.plugin.settings.citingLimit, debugMode)
this.citeCache.set(paperId, citations)
return citations
} catch (e) {
Expand Down
4 changes: 4 additions & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export default {
'<b>Toggle ON:</b> Enable sorting of the Index cards<br>' +
'<b>Toggle OFF:</b> Default sorting, as appear in the markdown',
SORT_BY: 'Sort By',
CITED_MAX_LIMIT: 'Maximum number of cited papers',
CITED_MAX_LIMIT_DESC: 'Maximum number of cited papers to show for each index card.<br>' + ' Default is set to 100. Maximum is 1000.',
CITING_MAX_LIMIT: 'Maximum number of citing papers',
CITING_MAX_LIMIT_DESC: 'Maximum number of citing papers to show for each index card.<br>' + ' Default is set to 100. Maximum is 1000.',
// SORT_BY_DESC: "Sort references and citations by the selected value",
SORT_BY_YEAR: 'Year',
SORT_BY_CITATION_COUNT: 'Citation count',
Expand Down
51 changes: 51 additions & 0 deletions src/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,57 @@ export class ReferenceMapSettingTab extends PluginSettingTab {
)
}

let citedMaxLimit: HTMLDivElement
new Setting(containerEl)
.setName(t('CITED_MAX_LIMIT'))
// .setDesc(fragWithHTML(t('CITED_MAX_LIMIT_DESC')))
.addSlider((slider) =>
slider
.setLimits(50, 1000, 50)
.setValue(this.plugin.settings.citedLimit)
.onChange(async (value) => {
citedMaxLimit.innerText = ` ${value.toString()}`
this.plugin.settings.citedLimit = value
this.plugin.saveSettings().then(() => {
if (this.plugin.view)
this.plugin.referenceMapData.reload(RELOAD.VIEW)
})
})
)
.settingEl.createDiv('', (el) => {
citedMaxLimit = el
el.style.minWidth = '2.3em'
el.style.textAlign = 'right'
el.innerText = ` ${this.plugin.settings.citedLimit.toString()}`
})

let citingMaxLimit: HTMLDivElement
new Setting(containerEl)
.setName(t('CITING_MAX_LIMIT'))
// .setDesc(fragWithHTML(t('CITING_MAX_LIMIT_DESC')))
.addSlider((slider) =>
slider
.setLimits(50, 1000, 50)
.setValue(this.plugin.settings.citingLimit)
.onChange(async (value) => {
citingMaxLimit.innerText = ` ${value.toString()}`
this.plugin.settings.citingLimit = value
this.plugin.saveSettings().then(() => {
if (this.plugin.view)
this.plugin.referenceMapData.reload(RELOAD.VIEW)
})
})
)
.settingEl.createDiv('', (el) => {
citingMaxLimit = el
el.style.minWidth = '2.3em'
el.style.textAlign = 'right'
el.innerText = ` ${this.plugin.settings.citingLimit.toString()}`
})




new Setting(this.containerEl)
.setName("Citation style ")
.addSearch((cb) => {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type ReferenceMapSettings = {
linkCiteKey: boolean
findZoteroCiteKeyFromID: boolean
findCiteKeyFromLinksWithoutPrefix: boolean
citedLimit: number
citingLimit: number
enableReferenceSorting: boolean
sortByReference: string
sortOrderReference: string
Expand Down

0 comments on commit 519fb73

Please sign in to comment.