new feature: add task
This commit is contained in:
parent
070b437bab
commit
bfb4ae627f
7 changed files with 74 additions and 35 deletions
|
|
@ -6,7 +6,7 @@ export default function Index(props: any) {
|
|||
return(
|
||||
<div className="stats">
|
||||
{/* <div id="profile-name">{props.user_data.profile.name}</div> */}
|
||||
{console.log(props)}
|
||||
{/* {console.log(props)} */}
|
||||
<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>
|
||||
|
|
|
|||
30
src/view/Components/Taskview/AddTask.tsx
Normal file
30
src/view/Components/Taskview/AddTask.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import * as React from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Trans } from 'react-i18next';
|
||||
|
||||
type FormData = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
export default function Index(props: any) {
|
||||
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>();
|
||||
const onSubmit = handleSubmit(data => {
|
||||
const url = "https://habitica.com/api/v4/tasks/user"
|
||||
const response = fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync",
|
||||
"x-api-user": this.app.plugins.plugins["obsidian-habitica-integration"].settings.userID,
|
||||
"x-api-key": this.app.plugins.plugins["obsidian-habitica-integration"].settings.apiToken,
|
||||
},
|
||||
body: JSON.stringify({ type: props.type, text: data.title })
|
||||
})
|
||||
})
|
||||
return (
|
||||
<form className="add-task-input" onSubmit={onSubmit}>
|
||||
<input type="text" defaultValue="" {...register("title")}></input>
|
||||
<button className="submit-button" type="submit" ><Trans>submit</Trans></button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import ReactMarkdown from "react-markdown";
|
|||
function DailyItem(props: any) {
|
||||
return (
|
||||
<div className="todo-item" id={props.id}>
|
||||
{console.log(props)}
|
||||
<input type="checkbox" className="checkbox" id={props.id} onChange={props.onChange} checked={props.completed} />
|
||||
<div className="todo-content">
|
||||
<p><Emoji text={props.daily_text}></Emoji></p>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
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 { useTranslation, Trans, Translation } from 'react-i18next';
|
||||
import { useForm, SubmitHandler } from "react-hook-form";
|
||||
import { addDaily } from "src/view/habiticaAPI";
|
||||
|
||||
type Inputs = {
|
||||
title: string
|
||||
};
|
||||
import AddTask from "../AddTask";
|
||||
|
||||
export default function Index(props: any){
|
||||
if(props.dailys == undefined) {
|
||||
|
|
@ -22,10 +18,6 @@ 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>
|
||||
|
|
@ -33,10 +25,7 @@ export default function Index(props: any){
|
|||
<Tab><Trans>Active</Trans></Tab>
|
||||
<Tab><Trans>Completed</Trans></Tab>
|
||||
</TabList>
|
||||
<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>
|
||||
<AddTask type="daily"></AddTask>
|
||||
<TabPanel>
|
||||
<ul>{incompleteDailies}</ul>
|
||||
</TabPanel>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue