-
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.
UPDATE: Request from api instead of local files
- Loading branch information
Showing
7 changed files
with
55 additions
and
811 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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,36 +1,34 @@ | ||
export interface ClusterProps { | ||
category: string; | ||
url: string; | ||
title: string; | ||
description: string; | ||
detail: string; | ||
links: { title: string, url: string }[]; | ||
} | ||
|
||
export function fetchAndFilterData( | ||
dataKey: string, | ||
isRandom: boolean = false, | ||
selectedCategory: string | null = null, | ||
searchTerm: string = '', | ||
setClusters: (value: ClusterProps[]) => void | ||
) { | ||
fetch('data.json') | ||
.then(response => response.json()) | ||
.then(data => { | ||
let clusters = data[dataKey]; | ||
if (selectedCategory) { | ||
clusters = clusters.filter((cluster: ClusterProps) => cluster.category === selectedCategory); | ||
} | ||
if (searchTerm) { | ||
clusters = clusters.filter((cluster: ClusterProps) => | ||
Object.values(cluster).some(value => | ||
value.toString().toLowerCase().includes(searchTerm.toLowerCase()) | ||
) | ||
); | ||
const api = "https://api.mind.ch3nyang.top"; | ||
let url = `${api}/linkcard?collection=${dataKey}`; | ||
if (selectedCategory) { | ||
url += `&category=${selectedCategory}`; | ||
} | ||
if (searchTerm) { | ||
url += `&search=${searchTerm}`; | ||
} | ||
|
||
fetch(url, { method: 'GET' }) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
if (isRandom) { | ||
clusters = clusters.sort(() => Math.random() - 0.5); | ||
data = data.sort(() => Math.random() - 0.5); | ||
} | ||
setClusters(clusters); | ||
setClusters(data); | ||
}) | ||
.catch(e => { | ||
console.error(`Fetch failed: ${e.message}`); | ||
console.error(`Failed URL: ${url}`); | ||
}); | ||
} |
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,9 @@ | ||
interface ClusterProps { | ||
Col: string; | ||
Category: string; | ||
Title: string; | ||
Urlpath: string; | ||
Descr: string; | ||
Detail: string; | ||
links: { Title: string, Urlpath: string }[]; | ||
} |