handle api rates n stuff

This commit is contained in:
SpikeHD
2022-05-14 02:11:47 -07:00
parent 3d62512814
commit 49f48896c8
2 changed files with 33 additions and 15 deletions

View File

@@ -47,6 +47,7 @@
.NewsContent { .NewsContent {
overflow-y: auto; overflow-y: auto;
scrollbar-width: none;
} }
.Commit { .Commit {

View File

@@ -12,6 +12,7 @@ interface IProps {
interface IState { interface IState {
selected: string; selected: string;
news: any; news: any;
commitList: any;
} }
export default class NewsSection extends React.Component<IProps, IState> { export default class NewsSection extends React.Component<IProps, IState> {
@@ -20,13 +21,19 @@ export default class NewsSection extends React.Component<IProps, IState> {
this.state = { this.state = {
selected: props.selected || 'commits', selected: props.selected || 'commits',
news: null news: null,
commitList: null
} }
this.setSelected = this.setSelected.bind(this) this.setSelected = this.setSelected.bind(this)
this.showNews = this.showNews.bind(this) this.showNews = this.showNews.bind(this)
} }
componentDidMount() {
// Call showNews off the bat
this.showNews()
}
setSelected(item: string) { setSelected(item: string) {
this.setState({ selected: item }) this.setState({ selected: item })
@@ -34,21 +41,31 @@ export default class NewsSection extends React.Component<IProps, IState> {
} }
async showLatestCommits() { async showLatestCommits() {
const commits: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' }) if (!this.state.commitList) {
const obj = JSON.parse(commits) 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 // Probably rate-limited
const commitsList = obj.slice(0, 5) if (!Array.isArray(obj)) return
const commitsListHtml = commitsList.map((commit: any) => {
return (
<div className="Commit" key={commit.sha}>
<div className="CommitAuthor">{commit.commit.author.name}</div>
<div className="CommitMessage">{commit.commit.message.substring(0, 50) + '...'}</div>
</div>
)
})
return commitsListHtml // Get only first 5
const commitsList = obj.slice(0, 5)
const commitsListHtml = commitsList.map((commit: any) => {
return (
<div className="Commit" key={commit.sha}>
<div className="CommitAuthor">{commit.commit.author.name}</div>
<div className="CommitMessage">{commit.commit.message.substring(0, 50) + '...'}</div>
</div>
)
})
this.setState({
commitList: commitsListHtml,
news: commitsListHtml
})
}
return this.state.commitList
} }
async showNews() { async showNews() {