add task function
This commit is contained in:
parent
67af22829f
commit
070b437bab
6 changed files with 47 additions and 37 deletions
|
|
@ -7,9 +7,9 @@ export default function Index(props: any) {
|
|||
<div className="stats">
|
||||
{/* <div id="profile-name">{props.user_data.profile.name}</div> */}
|
||||
{console.log(props)}
|
||||
<div className = "substats" id="hp">{t('HP')}: {(props.user_data.stats.hp).toPrecision(3)}</div>
|
||||
<div className = "substats" id="lvl">{t('LEVEL')}: {props.user_data.stats.lvl}</div>
|
||||
<div className = "substats" id="gold">{t('GOLD')}: {(props.user_data.stats.gp).toPrecision(3)}</div>
|
||||
<div className = "substats" id="hp"><i className="material-icons">favorite</i>{t('HP')}: {(props.user_data.stats.hp).toPrecision(2)}</div>
|
||||
<div className = "substats" id="lvl"><i className="material-icons">star</i>{t('LEVEL')}: {props.user_data.stats.lvl}</div>
|
||||
<div className = "substats" id="gold"><i className="material-icons">credit_card</i>{t('GOLD')}: {(props.user_data.stats.gp).toPrecision(2)}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import * as React from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Trans,useTranslation } from 'react-i18next'
|
||||
|
||||
export default function Index(props: any) {
|
||||
|
||||
const display = <div id="addDisplay">
|
||||
<form>
|
||||
<label><Trans>type</Trans>
|
||||
<select>
|
||||
<option value="Daily">Daily</option>
|
||||
<option value="Habit">Habit</option>
|
||||
<option value="Todo">Todo</option>
|
||||
<option value="Reward">Reward</option>
|
||||
</select>
|
||||
</label>
|
||||
<label><Trans>title</Trans>
|
||||
<input type="text" />
|
||||
</label>
|
||||
<label><Trans>notes</Trans>
|
||||
<input type="text" />
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
return (display);
|
||||
}
|
||||
|
|
@ -2,6 +2,12 @@ import * as React from "react";
|
|||
import DailyItem from "./DailyItem"
|
||||
import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
|
||||
import { useTranslation, Trans, Translation } from 'react-i18next'
|
||||
import { useForm, SubmitHandler } from "react-hook-form";
|
||||
import { addDaily } from "src/view/habiticaAPI";
|
||||
|
||||
type Inputs = {
|
||||
title: string
|
||||
};
|
||||
|
||||
export default function Index(props: any){
|
||||
if(props.dailys == undefined) {
|
||||
|
|
@ -16,17 +22,21 @@ export default function Index(props: any){
|
|||
if(daily.completed)
|
||||
return <DailyItem key={daily.id} id={daily.id} daily_text={daily.text} daily_notes={daily.notes} onChange={props.onChange} completed={daily.completed}/>
|
||||
})
|
||||
const { register, handleSubmit, watch, formState: { errors } } = useForm<Inputs>();
|
||||
const onSubmit: SubmitHandler<Inputs> = data => {
|
||||
addDaily(this.props.plugin.settings.userID,this.props.plugin.settings.apiToken,data.title)
|
||||
}
|
||||
|
||||
const display = <div id="classDisplay">
|
||||
<Tabs>
|
||||
<TabList>
|
||||
<Tab><Trans>Active</Trans></Tab>
|
||||
<Tab><Trans>Completed</Trans></Tab>
|
||||
</TabList>
|
||||
<div className="add-task-input">
|
||||
<input type="text">
|
||||
</input>
|
||||
<button className="submit-button"><Trans>submit</Trans></button>
|
||||
</div>
|
||||
<form className="add-task-input" onSubmit={handleSubmit(onSubmit)}>
|
||||
<input type="text" defaultValue="" {...register("title")}></input>
|
||||
<button className="submit-button" type="submit"><Trans>submit</Trans></button>
|
||||
</form>
|
||||
<TabPanel>
|
||||
<ul>{incompleteDailies}</ul>
|
||||
</TabPanel>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import Dailiesview from "./Dailiesview"
|
|||
import Habitsview from "./Habitsview"
|
||||
import Todoview from "./Todoview"
|
||||
import Rewardview from "./Rewardview"
|
||||
import Addview from "./Addview"
|
||||
import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
|
||||
import { useTranslation, Trans, Translation } from 'react-i18next'
|
||||
|
||||
|
|
|
|||
|
|
@ -54,3 +54,19 @@ export async function costReward(username: string, credentials: string, taskID:
|
|||
})
|
||||
return(response)
|
||||
}
|
||||
|
||||
|
||||
export async function addDaily(username: string, credentials: string, title: string) {
|
||||
const url = "https://habitica.com/api/v4/tasks/user".concat(title)
|
||||
const response = fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
|
||||
"x-api-user": username,
|
||||
"x-api-key": credentials,
|
||||
},
|
||||
body: JSON.stringify({type: "daliy", text: title})
|
||||
})
|
||||
return(response)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue