Implemented Cron - untested
This commit is contained in:
parent
b7b1c3848f
commit
04f207db5d
3 changed files with 52 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import * as React from "react";
|
||||
import { Notice } from "obsidian";
|
||||
import { getStats, scoreTask } from "./habiticaAPI"
|
||||
import { getStats, scoreTask, makeCronReq } from "./habiticaAPI"
|
||||
import Statsview from "./Components/Statsview"
|
||||
import Taskview from "./Components/Taskview"
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ class App extends React.Component<any,any> {
|
|||
this.username = this.props.plugin.settings.userID
|
||||
this.credentials = this.props.plugin.settings.apiToken
|
||||
this.state = {
|
||||
needCron: false,
|
||||
isLoaded: false,
|
||||
user_data: {
|
||||
profile: {
|
||||
|
|
@ -20,7 +21,8 @@ class App extends React.Component<any,any> {
|
|||
stats: {
|
||||
hp: 0,
|
||||
lvl: 0,
|
||||
}
|
||||
},
|
||||
lastCron: "",
|
||||
},
|
||||
todos: [],
|
||||
dailys: [],
|
||||
|
|
@ -31,6 +33,31 @@ class App extends React.Component<any,any> {
|
|||
this.handleChangeHabits = this.handleChangeHabits.bind(this)
|
||||
|
||||
|
||||
}
|
||||
CheckCron(props: any) {
|
||||
let cronDate = new Date(props.lastCron).getTime();
|
||||
let now = new Date().getTime();
|
||||
if (now > cronDate + 86400000) {
|
||||
return(
|
||||
<div className="cron">
|
||||
<div id="cronMessage"> Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards. </div>
|
||||
<button onClick={() => {this.runCron()}}>Continue</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
else {
|
||||
console.log("Cron is up to date");
|
||||
return null
|
||||
};
|
||||
}
|
||||
runCron() {
|
||||
makeCronReq(this.username, this.credentials)
|
||||
.then(res => {
|
||||
this.setState({
|
||||
needCron: false
|
||||
})
|
||||
});
|
||||
this.reloadData();
|
||||
}
|
||||
async reloadData() {
|
||||
try {
|
||||
|
|
@ -40,6 +67,7 @@ class App extends React.Component<any,any> {
|
|||
new Notice('Login Failed, Please check credentials and try again!');
|
||||
}
|
||||
else {
|
||||
console.log(result);
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
user_data: result,
|
||||
|
|
@ -124,6 +152,7 @@ class App extends React.Component<any,any> {
|
|||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||
<Statsview user_data={this.state.user_data} />
|
||||
<Taskview data={this.state.tasks} handleChangeTodos={this.handleChangeTodos} handleChangeDailys={this.handleChangeDailys} handleChangeHabits={this.handleChangeHabits}/>
|
||||
<this.CheckCron lastCron={this.state.user_data.lastCron}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export async function scoreTask(username: string, credentials: string, taskID: s
|
|||
})
|
||||
return(response)
|
||||
}
|
||||
export async function makeCronReq(username: string, credentials: string, taskID: string){
|
||||
export async function makeCronReq(username: string, credentials: string){
|
||||
const url = "https://habitica.com/api/v3/cron";
|
||||
const response = fetch(url, {
|
||||
method: 'POST',
|
||||
|
|
|
|||
20
styles.css
20
styles.css
|
|
@ -159,3 +159,23 @@ ul li:not(.task-list-item)::before {
|
|||
font-weight: bold;
|
||||
text-shadow: 0 0 0.5em transparent;
|
||||
}
|
||||
body > div.app-container.is-left-sidedock-collapsed.is-right-sidedock-collapsed > div.horizontal-main-container > div > div.workspace-split.mod-horizontal.mod-right-split > div.workspace-tabs > div.workspace-leaf > div > div.view-content > div > div.cron > button {
|
||||
margin: auto;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.cron {
|
||||
display: inline-grid;
|
||||
justify-content: center;
|
||||
text-align: center;;
|
||||
margin-top: 5px;
|
||||
margin-left: 10%;
|
||||
margin-right: 10%;
|
||||
margin-bottom: 10px;
|
||||
background-color: var(--background-secondary-alt);
|
||||
border-radius: 10px;
|
||||
}
|
||||
#cronMessage {
|
||||
margin: 20px;
|
||||
margin-bottom: 10px;
|
||||
color: var(--text-normal)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue