diff --git a/src/view/App.tsx b/src/view/App.tsx index eb9af90..5e5e775 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import { Notice } from "obsidian"; -import { getStats, scoreTask, makeCronReq, costReward } from "./habiticaAPI" +import { getStats, scoreTask, makeCronReq, costReward, addTask } from "./habiticaAPI" import Statsview from "./Components/Statsview" import Taskview from "./Components/Taskview" import "../i18n" @@ -52,15 +52,11 @@ class App extends React.Component { let cronDate = new Date(lastCron); let now = new Date(); if (cronDate.getDate() != now.getDate() || (cronDate.getMonth() != now.getMonth() || cronDate.getFullYear() != now.getFullYear())) { - // return ( - //
- //
Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards.
- // - //
- // ); return ( -
- ) +
+ +
+ ); } else { return null @@ -136,6 +132,23 @@ class App extends React.Component { } } + async sendDaily(type: string, title: string, message: string) { + try { + let response = await addTask(this.username, this.credentials, title, type); + let result = await response.json(); + if (result.success === true) { + new Notice(message); + this.reloadData(); + } else { + new Notice("Resyncing, please try again"); + this.reloadData(); + } + } catch (e) { + console.log(e); + new Notice("API Error: Please check credentials") + } + } + handleChangeTodos(event: any) { this.state.tasks.todos.forEach((element: any) => { if (element.id == event.target.id) { @@ -162,6 +175,8 @@ class App extends React.Component { } }) } + + handleChangeHabits(event: any) { const target_id = event.target.id.slice(4) if (event.target.id.slice(0, 4) == "plus") { @@ -198,7 +213,7 @@ class App extends React.Component { else { return (
- + {content}
diff --git a/src/view/Components/Statsview/index.tsx b/src/view/Components/Statsview/index.tsx index 738ab51..c579e86 100644 --- a/src/view/Components/Statsview/index.tsx +++ b/src/view/Components/Statsview/index.tsx @@ -6,7 +6,7 @@ export default function Index(props: any) { return(
{/*
{props.user_data.profile.name}
*/} - {console.log(props)} + {/* {console.log(props)} */}
favorite{t('HP')}: {(props.user_data.stats.hp).toPrecision(2)}
star{t('LEVEL')}: {props.user_data.stats.lvl}
credit_card{t('GOLD')}: {(props.user_data.stats.gp).toPrecision(2)}
diff --git a/src/view/Components/Taskview/AddTask.tsx b/src/view/Components/Taskview/AddTask.tsx new file mode 100644 index 0000000..997dd23 --- /dev/null +++ b/src/view/Components/Taskview/AddTask.tsx @@ -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(); + 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 ( +
+ + +
+ ); +} \ No newline at end of file diff --git a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx index 8a4e104..09af3d6 100644 --- a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx +++ b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx @@ -5,6 +5,7 @@ import ReactMarkdown from "react-markdown"; function DailyItem(props: any) { return (
+ {console.log(props)}

diff --git a/src/view/Components/Taskview/Dailiesview/index.tsx b/src/view/Components/Taskview/Dailiesview/index.tsx index 0a885e9..d8388a2 100644 --- a/src/view/Components/Taskview/Dailiesview/index.tsx +++ b/src/view/Components/Taskview/Dailiesview/index.tsx @@ -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 }) - const { register, handleSubmit, watch, formState: { errors } } = useForm(); - const onSubmit: SubmitHandler = data => { - addDaily(this.props.plugin.settings.userID,this.props.plugin.settings.apiToken,data.title) - } const display =
@@ -33,10 +25,7 @@ export default function Index(props: any){ Active Completed -
- - -
+
    {incompleteDailies}
diff --git a/src/view/habiticaAPI.ts b/src/view/habiticaAPI.ts index bc12f73..e801287 100644 --- a/src/view/habiticaAPI.ts +++ b/src/view/habiticaAPI.ts @@ -56,7 +56,7 @@ export async function costReward(username: string, credentials: string, taskID: } -export async function addDaily(username: string, credentials: string, title: string) { +export async function addTask(username: string, credentials: string, title: string, type: string) { const url = "https://habitica.com/api/v4/tasks/user".concat(title) const response = fetch(url, { method: 'POST', @@ -66,7 +66,7 @@ export async function addDaily(username: string, credentials: string, title: str "x-api-user": username, "x-api-key": credentials, }, - body: JSON.stringify({type: "daliy", text: title}) + body: JSON.stringify({type: type, text: title}) }) return(response) } \ No newline at end of file diff --git a/styles.css b/styles.css index 7c097ab..62f557a 100644 --- a/styles.css +++ b/styles.css @@ -121,10 +121,6 @@ input[type=checkbox]:focus { outline: 0; } -.task-view { - overflow: scroll; -} - ::-webkit-scrollbar { display: none; /* Chrome Safari */ } @@ -132,13 +128,20 @@ input[type=checkbox]:focus { .plugin-root { min-width: 260px; display: grid; - grid-template-rows: 93% 5% 2%; + grid-template-rows: 97% 1% 0.5%; height: inherit; } +#classDisplay { + height: 100%; +} + .substats { font-size: medium; +} +ul { + margin: 0; } /* react-tabs internal file :wink: */ @@ -157,7 +160,7 @@ input[type=checkbox]:focus { .react-tabs { -webkit-tap-highlight-color: transparent; - + height: 100%; } .react-tabs__tab-list { @@ -208,6 +211,8 @@ input[type=checkbox]:focus { .react-tabs__tab-panel { display: none; left: 0px; + height: 88%; + overflow: scroll; } .react-tabs__tab-panel--selected { @@ -223,7 +228,7 @@ 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 { +button { margin: auto; margin-bottom: 5px; white-space: nowrap; @@ -238,7 +243,6 @@ body > div.app-container.is-left-sidedock-collapsed.is-right-sidedock-collapsed margin-left: 10%; margin-right: 10%; margin-bottom: 10px; - background-color: var(--background-secondary-alt); border-radius: 10px; } #cronMessage {