mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 17:14:36 +01:00
handle api rates n stuff
This commit is contained in:
@@ -47,6 +47,7 @@
|
|||||||
|
|
||||||
.NewsContent {
|
.NewsContent {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Commit {
|
.Commit {
|
||||||
|
|||||||
@@ -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,9 +41,13 @@ export default class NewsSection extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async showLatestCommits() {
|
async showLatestCommits() {
|
||||||
|
if (!this.state.commitList) {
|
||||||
const commits: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' })
|
const commits: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' })
|
||||||
const obj = JSON.parse(commits)
|
const obj = JSON.parse(commits)
|
||||||
|
|
||||||
|
// Probably rate-limited
|
||||||
|
if (!Array.isArray(obj)) return
|
||||||
|
|
||||||
// Get only first 5
|
// Get only first 5
|
||||||
const commitsList = obj.slice(0, 5)
|
const commitsList = obj.slice(0, 5)
|
||||||
const commitsListHtml = commitsList.map((commit: any) => {
|
const commitsListHtml = commitsList.map((commit: any) => {
|
||||||
@@ -48,7 +59,13 @@ export default class NewsSection extends React.Component<IProps, IState> {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return commitsListHtml
|
this.setState({
|
||||||
|
commitList: commitsListHtml,
|
||||||
|
news: commitsListHtml
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.state.commitList
|
||||||
}
|
}
|
||||||
|
|
||||||
async showNews() {
|
async showNews() {
|
||||||
|
|||||||
Reference in New Issue
Block a user