diff --git a/.gitignore b/.gitignore index f36d0a2..de7c3d1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ node_modules package-lock.json +# yarn +yarn.lock + *.js.map diff --git a/.hotreload b/.hotreload new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 344ca09..174f5f6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "main.js", "scripts": { "dev": "rollup --config rollup.config.js -w", - "build": "rollup --config rollup.config.js --environment BUILD:production" + "build": "rollup --config rollup.config.js --environment BUILD:production", + "dev2": "obsidian-plugin dev src/main.ts" }, "keywords": [], "author": "Leonard and Ran", @@ -21,6 +22,7 @@ "css-loader": "^6.4.0", "extract-text-webpack-plugin": "^2.1.2", "obsidian": "^0.12.0", + "obsidian-plugin-cli": "^0.4.3", "rollup": "^2.32.1", "style-loader": "^3.3.0", "tslib": "^2.2.0", @@ -32,6 +34,7 @@ "react": "^17.0.2", "react-dom": "^17.0.2", "react-emoji-render": "^1.2.4", + "react-markdown": "^7.1.0", "react-tabs": "^3.2.2" } } diff --git a/src/main.ts b/src/main.ts index bdf0312..7fdc89b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ export default class HabiticaSync extends Plugin { view: HabiticaSyncView; async onload() { + console.log("load plugin: habitica-sync") await this.loadSettings(); this.addSettingTab(new HabiticaSyncSettingsTab(this.app, this)); this.registerView( @@ -32,6 +33,8 @@ export default class HabiticaSync extends Plugin { this.activateView(); } }); + this.activateView(); + } async loadSettings() { this.settings = Object.assign(DEFAULT_SETTINGS, await this.loadData()) @@ -39,9 +42,10 @@ export default class HabiticaSync extends Plugin { async saveSettings() { await this.saveData(this.settings); } - async onunload() { - await this.view.onClose(); + async onunload() { + // await this.view.onClose(); + this.app.workspace .getLeavesOfType(VIEW_TYPE) .forEach((leaf) => leaf.detach()); diff --git a/src/view.tsx b/src/view.tsx index e73dbb7..be66720 100644 --- a/src/view.tsx +++ b/src/view.tsx @@ -31,8 +31,7 @@ export class HabiticaSyncView extends ItemView { this.containerEl.children[1] ) } - - async onClose(){ + async onClose(){ ReactDOM.unmountComponentAtNode(this.containerEl.children[1]); } } \ No newline at end of file diff --git a/src/view/App.tsx b/src/view/App.tsx index 6dda418..36879c9 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -1,10 +1,10 @@ import * as React from "react"; import { Notice } from "obsidian"; -import { getStats, scoreTask, makeCronReq } from "./habiticaAPI" +import { getStats, scoreTask, makeCronReq, costReward } from "./habiticaAPI" import Statsview from "./Components/Statsview" import Taskview from "./Components/Taskview" -class App extends React.Component { +class App extends React.Component { private _username = ""; public get username() { return this._username; @@ -43,6 +43,7 @@ class App extends React.Component { this.handleChangeTodos = this.handleChangeTodos.bind(this); this.handleChangeDailys = this.handleChangeDailys.bind(this); this.handleChangeHabits = this.handleChangeHabits.bind(this); + this.handleChangeRewards = this.handleChangeRewards.bind(this); this.runCron = this.runCron.bind(this); } @@ -50,15 +51,17 @@ 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 ( + //
+ //
Welcome back! Please check your tasks for the last day and hit continue to get your daily rewards.
+ // + //
+ // ); + return ( +
+ ) } else { - console.log("Cron is up to date"); return null }; } @@ -74,103 +77,131 @@ class App extends React.Component { new Notice("There was an error running the cron. Please try again later."); } this.reloadData(); - } + } async reloadData() { try { - let response = await getStats(this.username, this.credentials); - let result = await response.json(); - if (result.success === false) { - new Notice('Login Failed, Please check credentials and try again!'); - } - else { - console.log(result); - this.setState({ - isLoaded: true, - user_data: result, - tasks: result.tasks, - }); - } - } catch (e) { + let response = await getStats(this.username, this.credentials); + let result = await response.json(); + if (result.success === false) { + new Notice('Login Failed, Please check credentials and try again!'); + } + else { + this.setState({ + isLoaded: true, + user_data: result, + tasks: result.tasks, + }); + } + } catch (e) { console.log(e); new Notice("API Error: Please check credentials") - } + } } componentDidMount() { this.reloadData() } - - async sendScore(id:string , score: string, message: string){ + + async sendScore(id: string, score: string, message: string) { try { - let response = await scoreTask(this.username, this.credentials, id, score); - let result = await response.json(); - if(result.success === true){ + let response = await scoreTask(this.username, this.credentials, id, score); + 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) { + } catch (e) { console.log(e); new Notice("API Error: Please check credentials") - } + } } - handleChangeTodos(event: any){ + async sendReward(id: string, score: string, message: string) { + try { + let response = await costReward(this.username, this.credentials, id, score); + 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){ - if(!element.completed){ - this.sendScore(event.target.id,"up", "Checked!") + if (element.id == event.target.id) { + if (!element.completed) { + this.sendScore(event.target.id, "up", "Checked!") } else { - this.sendScore(event.target.id,"down", "Un-Checked!") + this.sendScore(event.target.id, "down", "Un-Checked!") } } }) } - handleChangeDailys(event: any){ + + + handleChangeDailys(event: any) { this.state.tasks.dailys.forEach((element: any) => { - if(element.id == event.target.id){ - if(element.id == event.target.id){ - if(!element.completed){ - this.sendScore(event.target.id,"up", "Checked!") + if (element.id == event.target.id) { + if (element.id == event.target.id) { + if (!element.completed) { + this.sendScore(event.target.id, "up", "Checked!") } else { - this.sendScore(event.target.id,"down", "Un-Checked!") + this.sendScore(event.target.id, "down", "Un-Checked!") } } } }) } - handleChangeHabits(event: any){ + handleChangeHabits(event: any) { const target_id = event.target.id.slice(4) - if(event.target.id.slice(0,4) == "plus"){ + if (event.target.id.slice(0, 4) == "plus") { this.state.tasks.habits.forEach((element: any) => { - if(element.id == target_id){ - this.sendScore(target_id,"up", "Plus!") + if (element.id == target_id) { + this.sendScore(target_id, "up", "Plus!") } }) } else { this.state.tasks.habits.forEach((element: any) => { - if(element.id == target_id){ - this.sendScore(target_id,"down", "Minus :(") + if (element.id == target_id) { + this.sendScore(target_id, "down", "Minus :(") } }) } } - - render(){ + handleChangeRewards(event: any) { + const target_id = event.target.id + this.state.tasks.rewards.forEach((element: any) => { + if (element.id == event.target.id) { + if (element.id == target_id) { + this.sendReward(target_id, "down", "Cost!") + } + } + }) + } + render() { let content = this.CheckCron(this.state.user_data.lastCron); - if(this.state.error) - return(
Loading....
) - else if(!this.state.isLoaded) + if (this.state.error) + return (
Loading....
) + else if (!this.state.isLoaded) return
Loading....
else { return (
- - + {content} -
+
+ + ); } } diff --git a/src/view/Components/Statsview/index.tsx b/src/view/Components/Statsview/index.tsx index f15d886..c84d10e 100644 --- a/src/view/Components/Statsview/index.tsx +++ b/src/view/Components/Statsview/index.tsx @@ -3,9 +3,11 @@ import * as React from 'react'; export default function Index(props: any) { return(
-
{props.user_data.profile.name}
-
favoriteHP: {(props.user_data.stats.hp).toPrecision(3)}
-
starLVL: {props.user_data.stats.lvl}
+ {/*
{props.user_data.profile.name}
*/} + {console.log(props)} +
HP: {(props.user_data.stats.hp).toPrecision(3)}
+
LEVEL: {props.user_data.stats.lvl}
+
GOLD: {(props.user_data.stats.gp).toPrecision(3)}
); } \ 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 d2d308e..741eb8c 100644 --- a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx +++ b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx @@ -1,11 +1,16 @@ import Emoji from "react-emoji-render"; import * as React from "react"; +import ReactMarkdown from "react-markdown"; function DailyItem(props: any) { return (
- -

+ +
+

+ +
+
) } diff --git a/src/view/Components/Taskview/Dailiesview/index.tsx b/src/view/Components/Taskview/Dailiesview/index.tsx index 0d0f192..e45c421 100644 --- a/src/view/Components/Taskview/Dailiesview/index.tsx +++ b/src/view/Components/Taskview/Dailiesview/index.tsx @@ -9,11 +9,11 @@ export default function Index(props: any){ else { const incompleteDailies = props.dailys.map((daily: any) => { if(!daily.completed) - return + return }) const completedDailies = props.dailys.map((daily: any) => { if(daily.completed) - return + return }) const display =
diff --git a/src/view/Components/Taskview/Habitsview/HabitItem.tsx b/src/view/Components/Taskview/Habitsview/HabitItem.tsx index fa397cc..f458752 100644 --- a/src/view/Components/Taskview/Habitsview/HabitItem.tsx +++ b/src/view/Components/Taskview/Habitsview/HabitItem.tsx @@ -1,16 +1,20 @@ import Emoji from "react-emoji-render"; import * as React from "react"; +import ReactMarkdown from "react-markdown"; function HabitItem(props: any) { return (
- -

- +
+

+ +
) } diff --git a/src/view/Components/Taskview/Habitsview/index.tsx b/src/view/Components/Taskview/Habitsview/index.tsx index dc322bb..1ee9eab 100644 --- a/src/view/Components/Taskview/Habitsview/index.tsx +++ b/src/view/Components/Taskview/Habitsview/index.tsx @@ -9,7 +9,7 @@ export default function Index(props: any){ } else { const allHabits = props.habits.map((habit: any) => { - return + return }) const display =
    {allHabits}
diff --git a/src/view/Components/Taskview/Rewardview/RewardItem.tsx b/src/view/Components/Taskview/Rewardview/RewardItem.tsx new file mode 100644 index 0000000..0d86c01 --- /dev/null +++ b/src/view/Components/Taskview/Rewardview/RewardItem.tsx @@ -0,0 +1,17 @@ +import Emoji from "react-emoji-render"; +import * as React from "react"; +import ReactMarkdown from "react-markdown"; +function RewardItem(props: any) { + return ( +
+ +
+

+ +
+ +
+ ) +} + +export default RewardItem \ No newline at end of file diff --git a/src/view/Components/Taskview/Rewardview/index.tsx b/src/view/Components/Taskview/Rewardview/index.tsx new file mode 100644 index 0000000..ff60917 --- /dev/null +++ b/src/view/Components/Taskview/Rewardview/index.tsx @@ -0,0 +1,21 @@ +import * as React from "react"; +import RewardItem from "./RewardItem" + +export default function Index(props: any){ + if(props.rewards == undefined) { + return (
+ No Rewards present. +
) + } + else { + const allRewards = props.rewards.map((reward: any) => { + return + }) + const display =
+
    {allRewards}
+
+ + return(display); + } +} + diff --git a/src/view/Components/Taskview/TodoItem.tsx b/src/view/Components/Taskview/TodoItem.tsx index c02e230..586fdc9 100644 --- a/src/view/Components/Taskview/TodoItem.tsx +++ b/src/view/Components/Taskview/TodoItem.tsx @@ -5,7 +5,7 @@ function TodoItem(props: any) { return (
- +
) } diff --git a/src/view/Components/Taskview/Todoview/TodoItem.tsx b/src/view/Components/Taskview/Todoview/TodoItem.tsx index 2766dbe..92b3d7f 100644 --- a/src/view/Components/Taskview/Todoview/TodoItem.tsx +++ b/src/view/Components/Taskview/Todoview/TodoItem.tsx @@ -1,11 +1,16 @@ import Emoji from "react-emoji-render"; import * as React from "react"; +import ReactMarkdown from "react-markdown"; function TodoItem(props: any) { return (
-

+ {/*

*/} +
+

+ +
) } diff --git a/src/view/Components/Taskview/Todoview/index.tsx b/src/view/Components/Taskview/Todoview/index.tsx index 7ce2edf..ec61448 100644 --- a/src/view/Components/Taskview/Todoview/index.tsx +++ b/src/view/Components/Taskview/Todoview/index.tsx @@ -9,11 +9,11 @@ export default function Index(props: any){ else { const incompleteTodos = props.todos.map((todo: any) => { if(!todo.completed) - return + return }) const completedTodos = props.todos.map((todo: any) => { if(todo.completed) - return + return }) const display =
diff --git a/src/view/Components/Taskview/index.tsx b/src/view/Components/Taskview/index.tsx index 9546979..64898b2 100644 --- a/src/view/Components/Taskview/index.tsx +++ b/src/view/Components/Taskview/index.tsx @@ -2,31 +2,39 @@ import * as React from "react"; import Dailiesview from "./Dailiesview" import Habitsview from "./Habitsview" import Todoview from "./Todoview" +import Rewardview from "./Rewardview" import { Tab, Tabs, TabList, TabPanel } from "react-tabs"; export default function Index(props: any){ const display =
- - task_alt - + today + + add_chart + - add_circle_outline + assignment_turned_in + + + account_balance - - - + + + + + +
return(display); diff --git a/src/view/habiticaAPI.ts b/src/view/habiticaAPI.ts index 142a923..478211b 100644 --- a/src/view/habiticaAPI.ts +++ b/src/view/habiticaAPI.ts @@ -39,4 +39,18 @@ export async function makeCronReq(username: string, credentials: string){ } }) return(response) -} \ No newline at end of file +} + +export async function costReward(username: string, credentials: string, taskID: string, direction: string) { + const url = "https://habitica.com/api/v4/tasks/".concat(taskID).concat("/score/").concat(direction) + 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, + } + }) + return(response) +} diff --git a/styles.css b/styles.css index b31b4a2..10a2bd6 100644 --- a/styles.css +++ b/styles.css @@ -1,3 +1,8 @@ +* { + /* margin: 0; */ + padding: 0; +} + #profile-name { font-size: x-large; @@ -5,7 +10,8 @@ padding-bottom: 3%; } .stats { - padding-bottom: 6px; + display: flex; + justify-content: space-between; } .todo-item { @@ -13,25 +19,38 @@ justify-content: flex-start; align-items: center; padding: 0px 0px 0; - width: 80%; + width: 100%; border-bottom: 1px solid #cecece; font-family: Roboto, sans-serif; font-weight: normal; font-size: 16px; } +.reward-item { + display: flex; + justify-content: flex-start; + align-items: center; + padding: 0px 0px 0; + width: 100%; + border-bottom: 1px solid #cecece; + font-family: Roboto, sans-serif; + font-weight: normal; + font-size: 16px; +} + + .habit-text { - text-align: center !important; + text-align: left !important; padding: 0px; - width: 50%; + width: 80%; margin-right: 20px; } .habit-plus { /* background-color: #fff; */ border: none; - color: white; - padding: 7px 10px; + /* color: black; */ + padding: 7px 5px; text-align: center; text-decoration: none; font-size: 16px; @@ -41,8 +60,8 @@ /* background-color: #fff; */ /* border-radius: 50%; */ border: none; - color: white; - padding: 7px 10px; + /* color: black; */ + padding: 7px 5px; text-align: center; text-decoration: none; font-size: 16px; @@ -70,8 +89,19 @@ input[type=checkbox]:focus { outline: 0; } +.task-view { + overflow: scroll; +} + +::-webkit-scrollbar { + display: none; /* Chrome Safari */ +} + .plugin-root { min-width: 260px; + display: grid; + grid-template-rows: 93% 5% 2%; + height: inherit; } .substats { @@ -144,6 +174,7 @@ input[type=checkbox]:focus { .react-tabs__tab-panel { display: none; + left: 0px; } .react-tabs__tab-panel--selected {