From b7b1c3848f127eeb5570199e23c11975bb087771 Mon Sep 17 00:00:00 2001 From: Zain Date: Sat, 30 Oct 2021 21:10:09 +0530 Subject: [PATCH 01/10] Changed Application name in Plugin and Added function to run Cron --- src/view/habiticaAPI.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/view/habiticaAPI.ts b/src/view/habiticaAPI.ts index 36f2b25..db4e2a8 100644 --- a/src/view/habiticaAPI.ts +++ b/src/view/habiticaAPI.ts @@ -6,7 +6,7 @@ export async function getStats(username: string, credentials: string){ method: 'GET', headers: { "Content-Type": "application/json", - "x-client": username.concat("-testAPI"), + "x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync", "x-api-user": username, "x-api-key": credentials, }, @@ -20,7 +20,20 @@ export async function scoreTask(username: string, credentials: string, taskID: s method: 'POST', headers: { "Content-Type": "application/json", - "x-client": username.concat("-testAPI"), + "x-client": "278e719e-5f9c-43b1-9dba-8b73343dc062-HabiticaSync", + "x-api-user": username, + "x-api-key": credentials, + } + }) + return(response) +} +export async function makeCronReq(username: string, credentials: string, taskID: string){ + const url = "https://habitica.com/api/v3/cron"; + 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, } From 04f207db5dc53fb0281bf0a118494b76ce590ee4 Mon Sep 17 00:00:00 2001 From: Zain Date: Sat, 30 Oct 2021 22:34:41 +0530 Subject: [PATCH 02/10] Implemented Cron - untested --- src/view/App.tsx | 33 +++++++++++++++++++++++++++++++-- src/view/habiticaAPI.ts | 2 +- styles.css | 20 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index 3b1882d..ea5e9a9 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 } 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 { 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 { stats: { hp: 0, lvl: 0, - } + }, + lastCron: "", }, todos: [], dailys: [], @@ -32,6 +34,31 @@ class App extends React.Component { } + CheckCron(props: any) { + let cronDate = new Date(props.lastCron).getTime(); + let now = new Date().getTime(); + if (now > cronDate + 86400000) { + return( +
+
Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards.
+ +
+ ); + } + 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 { let response = await getStats(this.username, this.credentials); @@ -40,6 +67,7 @@ class App extends React.Component { 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 { + ); } diff --git a/src/view/habiticaAPI.ts b/src/view/habiticaAPI.ts index db4e2a8..142a923 100644 --- a/src/view/habiticaAPI.ts +++ b/src/view/habiticaAPI.ts @@ -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', diff --git a/styles.css b/styles.css index 1f12342..bdb8bd1 100644 --- a/styles.css +++ b/styles.css @@ -158,4 +158,24 @@ ul li:not(.task-list-item)::before { padding: 0; 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) } \ No newline at end of file From af3b2fe53beab32e8b28b009538dd7fc3159c304 Mon Sep 17 00:00:00 2001 From: Zain Date: Sun, 31 Oct 2021 16:33:58 +0530 Subject: [PATCH 03/10] Cron implementation 2: Untested --- src/view/App.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index ea5e9a9..72f4a31 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -28,20 +28,20 @@ class App extends React.Component { dailys: [], habits: [], } - this.handleChangeTodos = this.handleChangeTodos.bind(this) - this.handleChangeDailys = this.handleChangeDailys.bind(this) - this.handleChangeHabits = this.handleChangeHabits.bind(this) - + this.handleChangeTodos = this.handleChangeTodos.bind(this); + this.handleChangeDailys = this.handleChangeDailys.bind(this); + this.handleChangeHabits = this.handleChangeHabits.bind(this); + this.runCron = this.runCron.bind(this); } - CheckCron(props: any) { - let cronDate = new Date(props.lastCron).getTime(); - let now = new Date().getTime(); - if (now > cronDate + 86400000) { + CheckCron(lastCron: string) { + let cronDate = new Date(lastCron).getDate(); + let now = new Date().getDate(); + if (cronDate < now) { return(
Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards.
- +
); } @@ -51,6 +51,7 @@ class App extends React.Component { }; } runCron() { + console.log("running cron"); makeCronReq(this.username, this.credentials) .then(res => { this.setState({ @@ -143,6 +144,7 @@ class App extends React.Component { } render(){ + let content = this.CheckCron(this.state.user_data.lastCron); if(this.state.error) return(
Loading....
) else if(!this.state.isLoaded) @@ -152,7 +154,7 @@ class App extends React.Component { - + {content} ); } From b3282a360c12c7534d336d046d82c0ee8cd02f6a Mon Sep 17 00:00:00 2001 From: Zain Date: Sun, 31 Oct 2021 16:39:47 +0530 Subject: [PATCH 04/10] Cron Implementation - tested --- src/view/App.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index 72f4a31..b8f8814 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -41,7 +41,7 @@ class App extends React.Component { return(
Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards.
- +
); } @@ -55,7 +55,7 @@ class App extends React.Component { makeCronReq(this.username, this.credentials) .then(res => { this.setState({ - needCron: false + needCron: false, }) }); this.reloadData(); From e0f400b761df61ba08be65c01e7f7862c7ad0d33 Mon Sep 17 00:00:00 2001 From: Zain Date: Mon, 1 Nov 2021 11:41:31 +0530 Subject: [PATCH 05/10] CronImplementation 3: tested --- src/view/App.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index b8f8814..c49cae7 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -37,7 +37,8 @@ class App extends React.Component { CheckCron(lastCron: string) { let cronDate = new Date(lastCron).getDate(); let now = new Date().getDate(); - if (cronDate < now) { + console.log(cronDate, now); + if (cronDate != now) { return(
Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards.
@@ -50,14 +51,17 @@ class App extends React.Component { return null }; } - runCron() { + async runCron() { console.log("running cron"); - makeCronReq(this.username, this.credentials) - .then(res => { + try { + let response = await makeCronReq(this.username, this.credentials); this.setState({ needCron: false, }) - }); + } catch (error) { + console.log(error); + new Notice("There was an error running the cron. Please try again later."); + } this.reloadData(); } async reloadData() { From 412f9ed431ea192bbf68b182845af5f3747614b3 Mon Sep 17 00:00:00 2001 From: Zain Date: Mon, 1 Nov 2021 11:53:35 +0530 Subject: [PATCH 06/10] MAdded getter and setter methods for username and credentials --- src/view/App.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index c49cae7..a36d771 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -5,8 +5,20 @@ import Statsview from "./Components/Statsview" import Taskview from "./Components/Taskview" class App extends React.Component { - username = "" - credentials = "" + private _username = ""; + public get username() { + return this._username; + } + public set username(value) { + this._username = value; + } + private _credentials = ""; + public get credentials() { + return this._credentials; + } + public set credentials(value) { + this._credentials = value; + } constructor(props: any) { super(props) this.username = this.props.plugin.settings.userID From 25a1505fd06f5ad2505ec502325e0abceadc4eb0 Mon Sep 17 00:00:00 2001 From: Zain Date: Tue, 16 Nov 2021 18:29:31 +0530 Subject: [PATCH 07/10] Cron-Implementation: Tested! --- src/view/App.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index a36d771..6dda418 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -47,10 +47,9 @@ class App extends React.Component { } CheckCron(lastCron: string) { - let cronDate = new Date(lastCron).getDate(); - let now = new Date().getDate(); - console.log(cronDate, now); - if (cronDate != now) { + 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.
From 3d61b94932e02d6990212e28584aa452e4a2847b Mon Sep 17 00:00:00 2001 From: Zain Date: Tue, 16 Nov 2021 18:53:03 +0530 Subject: [PATCH 08/10] Added Emoji Support --- package.json | 1 + src/view/Components/Taskview/Dailiesview/DailyItem.tsx | 5 +++-- src/view/Components/Taskview/Habitsview/HabitItem.tsx | 5 +++-- src/view/Components/Taskview/TodoItem.tsx | 5 +++-- src/view/Components/Taskview/Todoview/TodoItem.tsx | 5 +++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4acb414..344ca09 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "node-fetch": "^3.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-emoji-render": "^1.2.4", "react-tabs": "^3.2.2" } } diff --git a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx index 40650af..d2d308e 100644 --- a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx +++ b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx @@ -1,10 +1,11 @@ - import * as React from "react"; +import Emoji from "react-emoji-render"; +import * as React from "react"; function DailyItem(props: any) { return (
-

{props.daily_text}

+

) } diff --git a/src/view/Components/Taskview/Habitsview/HabitItem.tsx b/src/view/Components/Taskview/Habitsview/HabitItem.tsx index faff665..fa397cc 100644 --- a/src/view/Components/Taskview/Habitsview/HabitItem.tsx +++ b/src/view/Components/Taskview/Habitsview/HabitItem.tsx @@ -1,4 +1,5 @@ - import * as React from "react"; +import Emoji from "react-emoji-render"; +import * as React from "react"; function HabitItem(props: any) { return ( @@ -6,7 +7,7 @@ function HabitItem(props: any) { -

{props.habit_text}

+

diff --git a/src/view/Components/Taskview/TodoItem.tsx b/src/view/Components/Taskview/TodoItem.tsx index 4adc70f..c02e230 100644 --- a/src/view/Components/Taskview/TodoItem.tsx +++ b/src/view/Components/Taskview/TodoItem.tsx @@ -1,10 +1,11 @@ - import * as React from "react"; +import { Emoji } from 'react-emoji-render'; +import * as React from "react"; function TodoItem(props: any) { return (
-

{props.todo_text}

+
) } diff --git a/src/view/Components/Taskview/Todoview/TodoItem.tsx b/src/view/Components/Taskview/Todoview/TodoItem.tsx index 4adc70f..2766dbe 100644 --- a/src/view/Components/Taskview/Todoview/TodoItem.tsx +++ b/src/view/Components/Taskview/Todoview/TodoItem.tsx @@ -1,10 +1,11 @@ - import * as React from "react"; +import Emoji from "react-emoji-render"; +import * as React from "react"; function TodoItem(props: any) { return (
-

{props.todo_text}

+

) } From 9d6c50ef88e7e4b6a9fcd155c3a4f159d0b98515 Mon Sep 17 00:00:00 2001 From: Zain Date: Tue, 16 Nov 2021 18:59:11 +0530 Subject: [PATCH 09/10] fixed css problem: habit content width too thin --- styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles.css b/styles.css index bdb8bd1..423fe18 100644 --- a/styles.css +++ b/styles.css @@ -23,7 +23,7 @@ .habit-text { text-align: center !important; padding: 0px; - width: 80px; + width: 50%; margin-right: 20px; } From 288f0a0b09fa628dd76e741ab8931ba1b74f69b9 Mon Sep 17 00:00:00 2001 From: Zain Date: Tue, 16 Nov 2021 19:06:15 +0530 Subject: [PATCH 10/10] updated version number --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index b537c6e..c9b0afa 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-habitica-integration", "name": "Habitica Sync", - "version": "0.9.7", + "version": "0.9.15", "minAppVersion": "0.9.12", "description": "This plugin helps integrate Habitica user tasks and stats into Obsidian", "author": "Leoh and Ran",