From 49f48896c83931ac0b0e89f4b5f94ecfab64ec69 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Sat, 14 May 2022 02:11:47 -0700 Subject: [PATCH] handle api rates n stuff --- src/ui/components/news/NewsSection.css | 1 + src/ui/components/news/NewsSection.tsx | 47 ++++++++++++++++++-------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/ui/components/news/NewsSection.css b/src/ui/components/news/NewsSection.css index 1c920b1..51b386c 100644 --- a/src/ui/components/news/NewsSection.css +++ b/src/ui/components/news/NewsSection.css @@ -47,6 +47,7 @@ .NewsContent { overflow-y: auto; + scrollbar-width: none; } .Commit { diff --git a/src/ui/components/news/NewsSection.tsx b/src/ui/components/news/NewsSection.tsx index 4a55823..c09cff1 100644 --- a/src/ui/components/news/NewsSection.tsx +++ b/src/ui/components/news/NewsSection.tsx @@ -12,6 +12,7 @@ interface IProps { interface IState { selected: string; news: any; + commitList: any; } export default class NewsSection extends React.Component { @@ -20,13 +21,19 @@ export default class NewsSection extends React.Component { this.state = { selected: props.selected || 'commits', - news: null + news: null, + commitList: null } this.setSelected = this.setSelected.bind(this) this.showNews = this.showNews.bind(this) } + componentDidMount() { + // Call showNews off the bat + this.showNews() + } + setSelected(item: string) { this.setState({ selected: item }) @@ -34,21 +41,31 @@ export default class NewsSection extends React.Component { } async showLatestCommits() { - const commits: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' }) - const obj = JSON.parse(commits) - - // Get only first 5 - const commitsList = obj.slice(0, 5) - const commitsListHtml = commitsList.map((commit: any) => { - return ( -
-
{commit.commit.author.name}
-
{commit.commit.message.substring(0, 50) + '...'}
-
- ) - }) + if (!this.state.commitList) { + const commits: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' }) + const obj = JSON.parse(commits) - return commitsListHtml + // Probably rate-limited + if (!Array.isArray(obj)) return + + // Get only first 5 + const commitsList = obj.slice(0, 5) + const commitsListHtml = commitsList.map((commit: any) => { + return ( +
+
{commit.commit.author.name}
+
{commit.commit.message.substring(0, 50) + '...'}
+
+ ) + }) + + this.setState({ + commitList: commitsListHtml, + news: commitsListHtml + }) + } + + return this.state.commitList } async showNews() {