diff --git a/src/i18n/zh-cn.json b/src/i18n/zh-cn.json index e919653..25f19f2 100644 --- a/src/i18n/zh-cn.json +++ b/src/i18n/zh-cn.json @@ -12,6 +12,7 @@ "No Dailies Present": "目前每日任务为空", "No habits present.": "目前习惯为空", "No Rewards present.": "目前奖励为空", + "No Todos present.": "目前待办事项为空", "There was an error running the cron. Please try again later.": "运行定时失败出错,请稍后再试。", "Login Failed, Please check credentials and try again!": "登录失败, 请检查凭据后再次尝试", "API Error: Please check credentials": "API错误,请检查凭据", diff --git a/src/view/App.tsx b/src/view/App.tsx index f93b048..2248622 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -168,9 +168,9 @@ class App extends React.Component { } } - async sendUpdateTask(id: string, type: string, message: string, title: string, notes: string) { + async sendUpdateTask(id: string, type: string, message: string, title: string, notes: string, coin: string = null) { try { - let response = await updateTask(this.username, this.credentials, id, type, title, notes); + let response = await updateTask(this.username, this.credentials, id, type, title, notes, coin); let result = await response.json(); if (result.success === true) { new Notice(message); @@ -183,7 +183,6 @@ class App extends React.Component { console.log(e); new Notice(i18next.t('API Error: Please check credentials')) } - // console.log(id, type,title,notes) } handleChangeTodos(event: any) { @@ -194,9 +193,12 @@ class App extends React.Component { this.state.tasks.todos.forEach((element: any) => { if (element.id == event.target.id) { if (event.type == "click") { - console.log(event) if (event.target.innerText == 'clear') { this.sendDeleteTask(event.target.id, i18next.t('Deleted!')) + } else if (event.target.attributes.title.value == 'submit') { + const task_title = event.target.attributes['data-title'].value ? event.target.attributes['data-title'].value : element.text + const task_notes = event.target.attributes['data-notes'].value ? event.target.attributes['data-notes'].value : element.notes + this.sendUpdateTask(event.target.id, 'todo', i18next.t("Update!"), task_title, task_notes) } } else { if (!element.completed) { @@ -218,18 +220,20 @@ class App extends React.Component { } else { this.state.tasks.dailys.forEach((element: any) => { if (element.id == event.target.id) { - if (element.id == event.target.id) { - if (event.target.attributes.title.value == 'submit') { - const task_title = event.target.attributes['data-title'].value ? event.target.attributes['data-title'].value : element.text - const task_notes = event.target.attributes['data-notes'].value ? event.target.attributes['data-notes'].value : element.notes - this.sendUpdateTask(event.target.id, 'daily', "Update!", task_title, task_notes) - } else if (event.target.attributes.title.value == 'delete') { - this.sendDeleteTask(event.target.id, i18next.t('Deleted!')) - } else if (!element.completed) { + if (event.target.type == 'checkbox') { + if (!element.completed) { this.sendScore(event.target.id, "up", i18next.t('Checked!')) } else { this.sendScore(event.target.id, "down", i18next.t('Un-Checked!')) } + } else { + if (event.target.attributes.title.value == 'submit') { + const task_title = event.target.attributes['data-title'].value ? event.target.attributes['data-title'].value : element.text + const task_notes = event.target.attributes['data-notes'].value ? event.target.attributes['data-notes'].value : element.notes + this.sendUpdateTask(event.target.id, 'daily', i18next.t("Update!"), task_title, task_notes) + } else if (event.target.attributes.title.value == 'delete') { + this.sendDeleteTask(event.target.id, i18next.t('Deleted!')) + } } } }) @@ -240,26 +244,23 @@ class App extends React.Component { if (event.target.id == "add-habit") { const title = event.target.name this.sendAddTask("habit", title, i18next.t('Add!')) + } else if (event.target.innerText == 'clear') { + this.sendDeleteTask(event.target.id, i18next.t('Deleted!')) } else { - if (event.target.innerText == 'clear') { - this.sendDeleteTask(event.target.id, i18next.t('Deleted!')) - } else { - const target_id = event.target.id.slice(4) - 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", i18next.t('Plus!')) - } - }) + this.state.tasks.habits.forEach((element: any) => { + if (event.target.attributes.title.value == 'submit') { + const task_title = event.target.attributes['data-title'].value ? event.target.attributes['data-title'].value : element.text + const task_notes = event.target.attributes['data-notes'].value ? event.target.attributes['data-notes'].value : element.notes + this.sendUpdateTask(event.target.id, 'daily', i18next.t("Update!"), task_title, task_notes) + } else { + const target_id = event.target.id.slice(4) + if (event.target.id.slice(0, 4) == "plus") { + this.sendScore(target_id, "up", i18next.t('Plus!')) + } else { + this.sendScore(target_id, "down", i18next.t("Minus :(")) + } } - else { - this.state.tasks.habits.forEach((element: any) => { - if (element.id == target_id) { - this.sendScore(target_id, "down", i18next.t("Minus :(")) - } - }) - } - } + }) } } @@ -274,8 +275,11 @@ class App extends React.Component { if (element.id == target_id) { if (event.target.innerText == 'clear') { this.sendDeleteTask(event.target.id, i18next.t('Deleted!')) - } else if (event.target.innerText == 'create') { - this.sendUpdateTask(event.target.id, 'reward', i18next.t('Edit!'), "1", "1") + } else if (event.target.attributes.title.value == 'submit') { + const task_title = event.target.attributes['data-title'].value ? event.target.attributes['data-title'].value : element.text + const task_notes = event.target.attributes['data-notes'].value ? event.target.attributes['data-notes'].value : element.notes + const task_coin = event.target.attributes['data-coin'].value ? event.target.attributes['data-coin'].value : element.reward_value + this.sendUpdateTask(event.target.id, 'reward', i18next.t('Edit!'), task_title, task_notes, task_coin) } else { this.sendReward(target_id, "down", i18next.t('Cost!')) } diff --git a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx index c9697d3..945f7df 100644 --- a/src/view/Components/Taskview/Dailiesview/DailyItem.tsx +++ b/src/view/Components/Taskview/Dailiesview/DailyItem.tsx @@ -6,7 +6,7 @@ function DailyItem(props: any) { const [state, setState] = React.useState('view') const [title, setTitle] = React.useState('') const [notes, setNotes] = React.useState('') - if (state == 'view') { + if (state === 'view') { return (
@@ -14,7 +14,7 @@ function DailyItem(props: any) {

- - +
+ + +
) } diff --git a/src/view/Components/Taskview/Dailiesview/index.tsx b/src/view/Components/Taskview/Dailiesview/index.tsx index 6149711..da4a1de 100644 --- a/src/view/Components/Taskview/Dailiesview/index.tsx +++ b/src/view/Components/Taskview/Dailiesview/index.tsx @@ -5,11 +5,13 @@ import { Trans, useTranslation } from 'react-i18next'; export default function Index(props: any) { const [title, setTitle] = React.useState('') - let { t ,i18n} = useTranslation() + let { t, i18n } = useTranslation() if (props.dailys == undefined) { return
- setTitle(event.target.value)} /> - +
+ setTitle(event.target.value)} value={title} /> + +
No Dailies Present
} @@ -17,7 +19,7 @@ export default function Index(props: any) { const incompleteDailies = props.dailys.map((daily: any) => { if (!daily.completed) return ( - + ) }) const completedDailies = props.dailys.map((daily: any) => { @@ -32,12 +34,13 @@ export default function Index(props: any) { Completed - setTitle(event.target.value)} value={title} /> - +
+ setTitle(event.target.value)} value={title} /> + +
    {incompleteDailies}
-
    {completedDailies}
diff --git a/src/view/Components/Taskview/Habitsview/HabitItem.tsx b/src/view/Components/Taskview/Habitsview/HabitItem.tsx index 055d2d7..81f5bb8 100644 --- a/src/view/Components/Taskview/Habitsview/HabitItem.tsx +++ b/src/view/Components/Taskview/Habitsview/HabitItem.tsx @@ -3,26 +3,43 @@ import * as React from "react"; import ReactMarkdown from "react-markdown"; function HabitItem(props: any) { - return ( -
- - -
-

- -
- + +
+

+ +
+ -
- ) + clear + + + ) + } else { + return ( +
+ setTitle(event.target.value)} defaultValue={props.habit_text}> + setNotes(event.target.value)} defaultValue={props.habit_notes}> +
+ + +
+
+ ) + } + } export default HabitItem \ No newline at end of file diff --git a/src/view/Components/Taskview/Habitsview/index.tsx b/src/view/Components/Taskview/Habitsview/index.tsx index d4619ed..d2aaad4 100644 --- a/src/view/Components/Taskview/Habitsview/index.tsx +++ b/src/view/Components/Taskview/Habitsview/index.tsx @@ -1,30 +1,32 @@ import * as React from "react"; import HabitItem from "./HabitItem" -import { useTranslation, Trans, Translation } from 'react-i18next' +import { useTranslation, Trans } from 'react-i18next' -export default function Index(props: any){ +export default function Index(props: any) { const [title, setTitle] = React.useState('') - let { t ,i18n} = useTranslation() - if(props.habits == undefined) { + let { t, i18n } = useTranslation() + if (props.habits == undefined) { return (
- setTitle(event.target.value)} /> - - No habits present. -
) +
+ setTitle(event.target.value)} value={title} /> + +
+ No habits present. + ) } else { const allHabits = props.habits.map((habit: any) => { - return + return }) - - const display =
- setTitle(event.target.value)} /> - -
    {allHabits}
-
+
+ setTitle(event.target.value)} value={title} /> + +
+
    {allHabits}
+ - return(display); + return (display); } } diff --git a/src/view/Components/Taskview/Rewardview/RewardItem.tsx b/src/view/Components/Taskview/Rewardview/RewardItem.tsx index ec9e2df..6e45b14 100644 --- a/src/view/Components/Taskview/Rewardview/RewardItem.tsx +++ b/src/view/Components/Taskview/Rewardview/RewardItem.tsx @@ -2,21 +2,40 @@ import Emoji from "react-emoji-render"; import * as React from "react"; import ReactMarkdown from "react-markdown"; function RewardItem(props: any) { - return ( -
- -
-

- + const [state, setState] = React.useState('view') + const [title, setTitle] = React.useState('') + const [notes, setNotes] = React.useState('') + const [coin, setCoin] = React.useState(0) + if (state === 'view') { + return ( +
+ +
+

+ +
+ +
- - -
- ) + ) + } else { + return ( +
+ setTitle(event.target.value)} defaultValue={props.reward_text}> + setNotes(event.target.value)} defaultValue={props.reward_notes}> + setNotes(event.target.value)} defaultValue={props.reward_value}> +
+ + +
+
+ ) + + } } 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 index 39a5afd..45745ea 100644 --- a/src/view/Components/Taskview/Rewardview/index.tsx +++ b/src/view/Components/Taskview/Rewardview/index.tsx @@ -1,28 +1,32 @@ import * as React from "react"; import RewardItem from "./RewardItem" -import { Trans,useTranslation } from 'react-i18next' +import { Trans, useTranslation } from 'react-i18next' -export default function Index(props: any){ +export default function Index(props: any) { const [title, setTitle] = React.useState('') - let { t ,i18n} = useTranslation() - if(props.rewards == undefined) { + let { t, i18n } = useTranslation() + if (props.rewards == undefined) { return (
- setTitle(event.target.value)} /> - - No Rewards present. -
) +
+ setTitle(event.target.value)} value={title} /> + +
+ No Rewards present. +
) } else { const allRewards = props.rewards.map((reward: any) => { - return + return }) const display =
- setTitle(event.target.value)} /> - -
    {allRewards}
-
+
+ setTitle(event.target.value)} value={title} /> + +
+
    {allRewards}
+ - return(display); + return (display); } } diff --git a/src/view/Components/Taskview/Todoview/TodoItem.tsx b/src/view/Components/Taskview/Todoview/TodoItem.tsx index c33ab2d..e0a56a0 100644 --- a/src/view/Components/Taskview/Todoview/TodoItem.tsx +++ b/src/view/Components/Taskview/Todoview/TodoItem.tsx @@ -3,21 +3,37 @@ import * as React from "react"; import ReactMarkdown from "react-markdown"; function TodoItem(props: any) { - return ( -
- -
-

- + const [state, setState] = React.useState('view') + const [title, setTitle] = React.useState('') + const [notes, setNotes] = React.useState('') + if (state === 'view') { + return ( +
+ +
+

+ +
+ +
- - -
- ) + ) + } else { + return ( +
+ setTitle(event.target.value)} defaultValue={props.todo_text}> + setNotes(event.target.value)} defaultValue={props.todo_notes}> +
+ + +
+
+ ) + } } export default TodoItem \ No newline at end of file diff --git a/src/view/Components/Taskview/Todoview/index.tsx b/src/view/Components/Taskview/Todoview/index.tsx index 46f2966..448280f 100644 --- a/src/view/Components/Taskview/Todoview/index.tsx +++ b/src/view/Components/Taskview/Todoview/index.tsx @@ -1,43 +1,47 @@ import * as React from "react"; import TodoItem from "./TodoItem" import { Tab, Tabs, TabList, TabPanel } from "react-tabs"; -import { Trans,useTranslation } from 'react-i18next' +import { Trans, useTranslation } from 'react-i18next' -export default function Index(props: any){ +export default function Index(props: any) { const [title, setTitle] = React.useState('') - let { t ,i18n} = useTranslation() - if(props.todos == undefined) { + let { t, i18n } = useTranslation() + if (props.todos == undefined) { return
- setTitle(event.target.value)} /> - - No Todos present. +
+ setTitle(event.target.value)} value={title} /> +
+ No Todos present. +
} else { const incompleteTodos = props.todos.map((todo: any) => { - if(!todo.completed) - return + if (!todo.completed) + return }) const completedTodos = props.todos.map((todo: any) => { - if(todo.completed) - return + if (todo.completed) + return }) const display =
- - - Active - Completed - - - setTitle(event.target.value)} /> - -
    {incompleteTodos}
-
- -
    {completedTodos}
-
-
-
- return(display); + + + Active + Completed + + +
+ setTitle(event.target.value)} value={title} /> + +
+
    {incompleteTodos}
+
+ +
    {completedTodos}
+
+
+
+ return (display); } } \ No newline at end of file diff --git a/src/view/habiticaAPI.ts b/src/view/habiticaAPI.ts index d69440a..a146b7e 100644 --- a/src/view/habiticaAPI.ts +++ b/src/view/habiticaAPI.ts @@ -85,7 +85,7 @@ export async function deleteTask(username: string, credentials: string, id: stri return(response) } -export async function updateTask(username: string, credentials: string, id: string, type: string, title: string, notes: string) { +export async function updateTask(username: string, credentials: string, id: string, type: string, title: string, notes: string, coin: string) { const url = "https://habitica.com/api/v4/tasks/".concat(id) const response = fetch(url, { method: 'PUT', @@ -95,7 +95,7 @@ export async function updateTask(username: string, credentials: string, id: stri "x-api-user": username, "x-api-key": credentials, }, - body: JSON.stringify({id: id,type: type, text: title,notes: notes}) + body: type === 'reward' ? JSON.stringify({id: id,type: type, text: title,notes: notes, coin: coin}):JSON.stringify({id: id,type: type, text: title,notes: notes}) }) return(response) } \ No newline at end of file diff --git a/styles.css b/styles.css index 54626e0..394b0fd 100644 --- a/styles.css +++ b/styles.css @@ -111,10 +111,12 @@ input[type=checkbox] { } .submit-button { - padding: 5px 15px; + /* padding: 5px 5px; */ font-size: 15px; border: 1px solid #aaa; - white-space: nowrap; + /* white-space: nowrap; */ + /* margin: 10px; */ + margin: 0; } input[type=checkbox]:focus { @@ -236,6 +238,34 @@ ul li:not(.task-list-item)::before { .task-operation { align-self: center; + margin: 0; + padding: 0; +} + +.edit-item { + display: flex; + flex-direction: column; + width: 100%; +} + +.edit-button { + display: flex; + flex-direction: row; + justify-content: flex-end; +} + +.task-submit { + display: grid; + grid-template-columns: 10fr 5fr; +} + +.add-task-input { + display: block; + width: 100%; +} + +.task-input-box { + margin-right: 10px; } button {