chore: upgrade to Dioxus 0.7
All checks were successful
actionlint check / actionlint check (pull_request) Successful in 5s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 5s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 10s
hadolint check / hadolint check (pull_request) Successful in 16s
GitLeaks check / GitLeaks check (pull_request) Successful in 10s
htmlhint check / htmlhint check (pull_request) Successful in 35s
Prettier check / Prettier check (pull_request) Successful in 26s
markdownlint check / markdownlint check (pull_request) Successful in 31s
checkov check / checkov check (pull_request) Successful in 1m15s
ShellCheck check / ShellCheck check (pull_request) Successful in 30s
Stylelint check / Stylelint check (pull_request) Successful in 29s
yamllint check / yamllint check (pull_request) Successful in 27s
Rust check / Rust check (pull_request) Successful in 11m44s
All checks were successful
actionlint check / actionlint check (pull_request) Successful in 5s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 5s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 10s
hadolint check / hadolint check (pull_request) Successful in 16s
GitLeaks check / GitLeaks check (pull_request) Successful in 10s
htmlhint check / htmlhint check (pull_request) Successful in 35s
Prettier check / Prettier check (pull_request) Successful in 26s
markdownlint check / markdownlint check (pull_request) Successful in 31s
checkov check / checkov check (pull_request) Successful in 1m15s
ShellCheck check / ShellCheck check (pull_request) Successful in 30s
Stylelint check / Stylelint check (pull_request) Successful in 29s
yamllint check / yamllint check (pull_request) Successful in 27s
Rust check / Rust check (pull_request) Successful in 11m44s
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::internationalization::get_language_identifier;
|
||||
use crate::route::Route;
|
||||
use crate::server::internationalization::get_language_identifier;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::prelude::*;
|
||||
use dioxus_i18n::unic_langid::langid;
|
||||
use dioxus_query::prelude::use_init_query_client;
|
||||
|
||||
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
||||
const TAILWIND_CSS: Asset = asset!("/assets/styles/tailwind_output.css");
|
||||
const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");
|
||||
#[used]
|
||||
static FONTS_DIRECTORY: Asset = asset!(
|
||||
"/assets/fonts",
|
||||
AssetOptions::builder().with_hash_suffix(false)
|
||||
);
|
||||
const FONTS_CSS: Asset = asset!("/assets/styles/fonts.css");
|
||||
const INPUT_NUMBER_ARROWS_CSS: Asset = asset!("/assets/styles/input_number_arrows.css");
|
||||
const INPUT_RANGE_CSS: Asset = asset!("/assets/styles/input_range.css");
|
||||
@@ -17,13 +20,8 @@ const MANIFEST: Asset = asset!("/assets/manifest.json");
|
||||
|
||||
#[component]
|
||||
pub(crate) fn App() -> Element {
|
||||
use_init_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||
|
||||
let language_identifier = use_server_future(get_language_identifier)?
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
use_init_i18n(|| {
|
||||
I18nConfig::new(language_identifier)
|
||||
I18nConfig::new(get_language_identifier())
|
||||
.with_locale(Locale::new_static(
|
||||
langid!("cs-CZ"),
|
||||
include_str!("../internationalization/cs_cz.ftl"),
|
||||
@@ -44,7 +42,7 @@ pub(crate) fn App() -> Element {
|
||||
document::Script { src: "https://kit.fontawesome.com/3c1b409f8f.js" }
|
||||
|
||||
div {
|
||||
class: "min-h-screen text-zinc-200 bg-zinc-800 pt-4 pb-36",
|
||||
class: "min-h-screen pt-4 pb-36 flex flex-col text-zinc-200 bg-zinc-800",
|
||||
Router::<Route> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::components::navigation::Navigation;
|
||||
use crate::components::project_form::ProjectForm;
|
||||
use crate::components::task_form::TaskForm;
|
||||
@@ -23,6 +24,7 @@ pub(crate) fn BottomPanel(display_form: Signal<bool>) -> Element {
|
||||
} else {
|
||||
spawn(async move {
|
||||
// Necessary for a smooth – not instant – height transition.
|
||||
#[cfg(not(feature = "server"))]
|
||||
async_std::task::sleep(std::time::Duration::from_millis(500)).await;
|
||||
/* The check is necessary for the situation when the user expands the panel while
|
||||
it is being closed. */
|
||||
@@ -36,7 +38,7 @@ pub(crate) fn BottomPanel(display_form: Signal<bool>) -> Element {
|
||||
rsx! {
|
||||
div {
|
||||
class: format!(
|
||||
"pointer-events-auto bg-zinc-700/50 rounded-t-xl border-t-zinc-600 border-t backdrop-blur drop-shadow-[0_-5px_10px_rgba(0,0,0,0.2)] transition-[height] duration-[500ms] ease-[cubic-bezier(0.79,0.14,0.15,0.86)] overflow-y-scroll {}",
|
||||
"flex flex-col pointer-events-auto bg-zinc-700/50 rounded-t-xl border-t-zinc-600 border-t backdrop-blur drop-shadow-[0_-5px_10px_rgba(0,0,0,0.2)] transition-[height] duration-[500ms] ease-[cubic-bezier(0.79,0.14,0.15,0.86)] overflow-y-scroll {}",
|
||||
match (display_form(), current_route, navigation_expanded()) {
|
||||
(false, _, false) => "h-[66px]",
|
||||
(false, _, true) => "h-[130px]",
|
||||
@@ -45,22 +47,24 @@ pub(crate) fn BottomPanel(display_form: Signal<bool>) -> Element {
|
||||
}
|
||||
),
|
||||
if expanded() {
|
||||
match current_route {
|
||||
Route::ProjectsPage => rsx! {
|
||||
ProjectForm {
|
||||
project: project_being_edited(),
|
||||
on_successful_submit: move |_| {
|
||||
display_form.set(false);
|
||||
project_being_edited.set(None);
|
||||
ErrorBoundaryMessage {
|
||||
match current_route {
|
||||
Route::ProjectsPage => rsx! {
|
||||
ProjectForm {
|
||||
project: project_being_edited(),
|
||||
on_successful_submit: move |_| {
|
||||
display_form.set(false);
|
||||
project_being_edited.set(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => rsx! {
|
||||
TaskForm {
|
||||
task: task_being_edited(),
|
||||
on_successful_submit: move |_| {
|
||||
display_form.set(false);
|
||||
task_being_edited.set(None);
|
||||
},
|
||||
_ => rsx! {
|
||||
TaskForm {
|
||||
task: task_being_edited(),
|
||||
on_successful_submit: move |_| {
|
||||
display_form.set(false);
|
||||
task_being_edited.set(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
64
src/components/category_calendar_task_list.rs
Normal file
64
src/components/category_calendar_task_list.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use crate::components::task_list::TaskList;
|
||||
use crate::hooks::use_tasks_with_subtasks_in_category;
|
||||
use crate::internationalization::LocaleFromLanguageIdentifier;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::task::TaskWithSubtasks;
|
||||
use chrono::{Datelike, Local};
|
||||
use dioxus::core_macro::{component, rsx};
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::prelude::i18n;
|
||||
use dioxus_i18n::t;
|
||||
|
||||
const CALENDAR_LENGTH_DAYS: usize = 366 * 3;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryCalendarTaskList() -> Element {
|
||||
let today_date = Local::now().date_naive();
|
||||
let tasks = use_tasks_with_subtasks_in_category(Category::Calendar {
|
||||
date: today_date,
|
||||
reoccurrence: None,
|
||||
time: None,
|
||||
})?();
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
class: "pt-4 flex flex-col gap-8",
|
||||
for date_current in today_date.iter_days().take(CALENDAR_LENGTH_DAYS) {
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
div {
|
||||
class: "pt-1",
|
||||
{
|
||||
date_current.format_localized(t!(
|
||||
if date_current.year() == Local::now().year() {
|
||||
"date-weekday-format"
|
||||
} else {
|
||||
"date-weekday-year-format"
|
||||
}
|
||||
).as_str(),
|
||||
LocaleFromLanguageIdentifier::from(
|
||||
&i18n().language()
|
||||
).into()
|
||||
)
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
TaskList {
|
||||
tasks: tasks.iter().filter(|task| {
|
||||
if let Category::Calendar { date, .. }
|
||||
= task.task.category {
|
||||
date == date_current
|
||||
} else {
|
||||
panic!("Unexpected category.");
|
||||
}
|
||||
}).cloned().collect::<Vec<TaskWithSubtasks>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ pub(crate) fn CategoryInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg grow basis-0 {}",
|
||||
"py-2 rounded-lg grow basis-0 {} cursor-pointer",
|
||||
if selected_category() == Category::SomedayMaybe { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
),
|
||||
@@ -28,7 +28,7 @@ pub(crate) fn CategoryInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg grow basis-0 {}",
|
||||
"py-2 rounded-lg grow basis-0 {} cursor-pointer",
|
||||
if selected_category() == Category::LongTerm { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
),
|
||||
@@ -42,7 +42,7 @@ pub(crate) fn CategoryInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg grow basis-0 {}",
|
||||
"py-2 rounded-lg grow basis-0 {} cursor-pointer",
|
||||
if let Category::WaitingFor(_) = selected_category() { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
),
|
||||
@@ -56,7 +56,7 @@ pub(crate) fn CategoryInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg grow basis-0 {}",
|
||||
"py-2 rounded-lg grow basis-0 {} cursor-pointer",
|
||||
if selected_category() == Category::NextSteps { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
),
|
||||
@@ -70,7 +70,7 @@ pub(crate) fn CategoryInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg grow basis-0 {}",
|
||||
"py-2 rounded-lg grow basis-0 {} cursor-pointer",
|
||||
if let Category::Calendar { .. } = selected_category() { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
),
|
||||
@@ -88,7 +88,7 @@ pub(crate) fn CategoryInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg grow basis-0 {}",
|
||||
"py-2 rounded-lg grow basis-0 {} cursor-pointer",
|
||||
if selected_category() == Category::Inbox { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
),
|
||||
|
||||
133
src/components/category_today_task_list.rs
Normal file
133
src/components/category_today_task_list.rs
Normal file
@@ -0,0 +1,133 @@
|
||||
use crate::components::task_list::TaskList;
|
||||
use crate::components::task_list_item::TaskListItem;
|
||||
use crate::hooks::use_tasks_with_subtasks_in_category;
|
||||
use crate::internationalization::LocaleFromLanguageIdentifier;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::task::TaskWithSubtasks;
|
||||
use chrono::Local;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::t;
|
||||
use dioxus_i18n::use_i18n::i18n;
|
||||
use voca_rs::Voca;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryTodayTaskList() -> Element {
|
||||
let today_date = Local::now().date_naive();
|
||||
let calendar_tasks = use_tasks_with_subtasks_in_category(Category::Calendar {
|
||||
date: today_date,
|
||||
reoccurrence: None,
|
||||
time: None,
|
||||
})?();
|
||||
let today_tasks = calendar_tasks
|
||||
.iter()
|
||||
.filter(|task| {
|
||||
if let Category::Calendar { date, .. } = task.task.category {
|
||||
date == today_date
|
||||
} else {
|
||||
panic!("Unexpected category.");
|
||||
}
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<TaskWithSubtasks>>();
|
||||
let overdue_tasks = calendar_tasks
|
||||
.iter()
|
||||
.filter(|task| {
|
||||
if let Category::Calendar { date, .. } = task.task.category {
|
||||
date < today_date
|
||||
} else {
|
||||
panic!("Unexpected category.");
|
||||
}
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<TaskWithSubtasks>>();
|
||||
let long_term_tasks = use_tasks_with_subtasks_in_category(Category::LongTerm)?();
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
class: "pt-4 flex flex-col gap-8",
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
i {
|
||||
class: "fa-solid fa-water text-xl w-6 text-center"
|
||||
}
|
||||
div {
|
||||
class: "mt-1",
|
||||
{t!("long-term")._upper_first()}
|
||||
}
|
||||
}
|
||||
div {
|
||||
for task in long_term_tasks {
|
||||
div {
|
||||
key: "{task.task.id}",
|
||||
class: format!(
|
||||
"px-8 pt-5 {} flex flex-row gap-4",
|
||||
if task.task.deadline.is_some() {
|
||||
"pb-0.5"
|
||||
} else {
|
||||
"pb-5"
|
||||
}
|
||||
),
|
||||
TaskListItem {
|
||||
task: task.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !overdue_tasks.is_empty() {
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
i {
|
||||
class: "fa-solid fa-calendar-xmark text-xl w-6 text-center"
|
||||
}
|
||||
div {
|
||||
class: "mt-1",
|
||||
{t!("overdue")._upper_first()}
|
||||
}
|
||||
}
|
||||
TaskList {
|
||||
tasks: overdue_tasks,
|
||||
class: "pb-3"
|
||||
}
|
||||
}
|
||||
}
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
i {
|
||||
class: "fa-solid fa-calendar-check text-xl w-6 text-center"
|
||||
}
|
||||
div {
|
||||
class: "mt-1",
|
||||
{
|
||||
let format = t!("date-weekday-format");
|
||||
let today_date = today_date.format_localized(
|
||||
format.as_str(),
|
||||
LocaleFromLanguageIdentifier::from(
|
||||
&i18n().language()
|
||||
).into()
|
||||
).to_string();
|
||||
format!(
|
||||
"{} – {}",
|
||||
t!("today")._upper_first(),
|
||||
if t!("weekday-lowercase-first").parse().unwrap() {
|
||||
today_date._lower_first()
|
||||
} else {
|
||||
today_date
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
TaskList {
|
||||
tasks: today_tasks
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/components/error_boundary_message.rs
Normal file
27
src/components/error_boundary_message.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn ErrorBoundaryMessage(children: Element, class: Option<String>) -> Element {
|
||||
rsx! {
|
||||
ErrorBoundary {
|
||||
handle_error: |_| {
|
||||
rsx! {
|
||||
div {
|
||||
class: "grow flex flex-col justify-center items-center",
|
||||
div {
|
||||
i {
|
||||
class: "text-3xl fa-solid fa-triangle-exclamation"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
div {
|
||||
class,
|
||||
{children}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ pub(crate) fn FormOpenButton(opened: Signal<bool>) -> Element {
|
||||
|
||||
rsx! {
|
||||
button {
|
||||
class: "pointer-events-auto m-4 py-3 px-5 self-end text-center bg-zinc-300/50 rounded-xl border-t-zinc-200 border-t backdrop-blur drop-shadow-[0_-5px_10px_rgba(0,0,0,0.2)] text-2xl text-zinc-200",
|
||||
class: "pointer-events-auto m-4 py-3 px-5 self-end text-center bg-zinc-300/50 rounded-xl border-t-zinc-200 border-t backdrop-blur drop-shadow-[0_-5px_10px_rgba(0,0,0,0.2)] text-2xl text-zinc-200 cursor-pointer",
|
||||
onclick: move |_| {
|
||||
if opened() {
|
||||
project_being_edited.set(None);
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn Home() -> Element {
|
||||
rsx! {}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
use crate::components::bottom_panel::BottomPanel;
|
||||
use crate::components::form_open_button::FormOpenButton;
|
||||
use crate::components::sticky_bottom::StickyBottom;
|
||||
use crate::models::project::Project;
|
||||
use crate::models::task::Task;
|
||||
use crate::route::Route;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn Layout() -> Element {
|
||||
let mut display_form = use_signal(|| false);
|
||||
let project_being_edited =
|
||||
use_context_provider::<Signal<Option<Project>>>(|| Signal::new(None));
|
||||
let task_being_edited = use_context_provider::<Signal<Option<Task>>>(|| Signal::new(None));
|
||||
|
||||
use_effect(move || {
|
||||
display_form.set(project_being_edited().is_some() || task_being_edited().is_some());
|
||||
});
|
||||
|
||||
rsx! {
|
||||
Outlet::<Route> {}
|
||||
StickyBottom {
|
||||
FormOpenButton {
|
||||
opened: display_form,
|
||||
}
|
||||
BottomPanel {
|
||||
display_form: display_form,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
pub(crate) mod app;
|
||||
pub(crate) mod bottom_panel;
|
||||
pub(crate) mod category_calendar_task_list;
|
||||
pub(crate) mod category_input;
|
||||
pub(crate) mod category_today_task_list;
|
||||
pub(crate) mod error_boundary_message;
|
||||
pub(crate) mod form_open_button;
|
||||
pub(crate) mod home;
|
||||
pub(crate) mod layout;
|
||||
pub(crate) mod navigation;
|
||||
pub(crate) mod navigation_item;
|
||||
pub(crate) mod pages;
|
||||
pub(crate) mod project_form;
|
||||
pub(crate) mod project_list;
|
||||
pub(crate) mod project_select;
|
||||
pub(crate) mod reoccurrence_input;
|
||||
pub(crate) mod sticky_bottom;
|
||||
pub(crate) mod subtasks_form;
|
||||
|
||||
@@ -9,7 +9,7 @@ pub(crate) fn Navigation(expanded: Signal<bool>) -> Element {
|
||||
class: "grid grid-cols-5 justify-stretch",
|
||||
button {
|
||||
class: format!(
|
||||
"py-4 text-center text-2xl {}",
|
||||
"py-4 text-center text-2xl {} cursor-pointer",
|
||||
if expanded() { "text-zinc-200" }
|
||||
else { "text-zinc-500" }
|
||||
),
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
use crate::components::task_list::TaskList;
|
||||
use crate::internationalization::LocaleFromLanguageIdentifier;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::task::TaskWithSubtasks;
|
||||
use crate::query::QueryValue;
|
||||
use crate::query::tasks::use_tasks_with_subtasks_in_category_query;
|
||||
use chrono::{Datelike, Local};
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::prelude::i18n;
|
||||
use dioxus_i18n::t;
|
||||
use dioxus_query::prelude::QueryResult;
|
||||
|
||||
const CALENDAR_LENGTH_DAYS: usize = 366 * 3;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryCalendarPage() -> Element {
|
||||
let tasks = use_tasks_with_subtasks_in_category_query(Category::Calendar {
|
||||
date: Local::now().date_naive(),
|
||||
reoccurrence: None,
|
||||
time: None,
|
||||
});
|
||||
let tasks_query_result = tasks.result();
|
||||
|
||||
rsx! {
|
||||
match tasks_query_result.value() {
|
||||
QueryResult::Ok(QueryValue::TasksWithSubtasks(tasks))
|
||||
| QueryResult::Loading(Some(QueryValue::TasksWithSubtasks(tasks))) => {
|
||||
let today_date = Local::now().date_naive();
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
class: "pt-4 flex flex-col gap-8",
|
||||
for date_current in today_date.iter_days().take(CALENDAR_LENGTH_DAYS) {
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
div {
|
||||
class: "pt-1",
|
||||
{
|
||||
date_current.format_localized(t!(
|
||||
if date_current.year() == Local::now().year() {
|
||||
"date-weekday-format"
|
||||
} else {
|
||||
"date-weekday-year-format"
|
||||
}
|
||||
).as_str(),
|
||||
LocaleFromLanguageIdentifier::from(
|
||||
&i18n().language()
|
||||
).into()
|
||||
)
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
TaskList {
|
||||
tasks: tasks.iter().filter(|task| {
|
||||
if let Category::Calendar { date, .. }
|
||||
= task.task().category() {
|
||||
*date == date_current
|
||||
} else {
|
||||
panic!("Unexpected category.");
|
||||
}
|
||||
}).cloned().collect::<Vec<TaskWithSubtasks>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryDonePage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::Done,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryInboxPage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::Inbox,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryLongTermPage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::LongTerm,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryNextStepsPage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::NextSteps,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
use crate::components::task_list::TaskList;
|
||||
use crate::models::category::Category;
|
||||
use crate::query::QueryValue;
|
||||
use crate::query::tasks::use_tasks_with_subtasks_in_category_query;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_query::prelude::QueryResult;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryPage(category: Category) -> Element {
|
||||
let tasks_query = use_tasks_with_subtasks_in_category_query(category);
|
||||
let tasks_query_result = tasks_query.result();
|
||||
|
||||
match tasks_query_result.value() {
|
||||
QueryResult::Ok(QueryValue::TasksWithSubtasks(tasks))
|
||||
| QueryResult::Loading(Some(QueryValue::TasksWithSubtasks(tasks))) => rsx! {
|
||||
TaskList {
|
||||
tasks: tasks.clone(),
|
||||
class: "pb-36"
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}"),
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategorySomedayMaybePage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::SomedayMaybe,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
use crate::components::task_list::TaskList;
|
||||
use crate::components::task_list_item::TaskListItem;
|
||||
use crate::internationalization::LocaleFromLanguageIdentifier;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::task::TaskWithSubtasks;
|
||||
use crate::query::QueryValue;
|
||||
use crate::query::tasks::use_tasks_with_subtasks_in_category_query;
|
||||
use chrono::Local;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::t;
|
||||
use dioxus_i18n::use_i18n::i18n;
|
||||
use dioxus_query::prelude::QueryResult;
|
||||
use voca_rs::Voca;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryTodayPage() -> Element {
|
||||
let today_date = Local::now().date_naive();
|
||||
|
||||
let calendar_tasks_query = use_tasks_with_subtasks_in_category_query(Category::Calendar {
|
||||
date: today_date,
|
||||
reoccurrence: None,
|
||||
time: None,
|
||||
});
|
||||
let calendar_tasks_query_result = calendar_tasks_query.result();
|
||||
|
||||
let long_term_tasks_query = use_tasks_with_subtasks_in_category_query(Category::LongTerm);
|
||||
let long_term_tasks_query_result = long_term_tasks_query.result();
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
class: "pt-4 flex flex-col gap-8",
|
||||
match long_term_tasks_query_result.value() {
|
||||
QueryResult::Ok(QueryValue::TasksWithSubtasks(tasks))
|
||||
| QueryResult::Loading(Some(QueryValue::TasksWithSubtasks(tasks))) => {
|
||||
let mut tasks = tasks.clone();
|
||||
tasks.sort();
|
||||
rsx! {
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
i {
|
||||
class: "fa-solid fa-water text-xl w-6 text-center"
|
||||
}
|
||||
div {
|
||||
class: "mt-1",
|
||||
{t!("long-term")._upper_first()}
|
||||
}
|
||||
}
|
||||
div {
|
||||
for task in tasks {
|
||||
div {
|
||||
key: "{task.task().id()}",
|
||||
class: format!(
|
||||
"px-8 pt-5 {} flex flex-row gap-4",
|
||||
if task.task().deadline().is_some() {
|
||||
"pb-0.5"
|
||||
} else {
|
||||
"pb-5"
|
||||
}
|
||||
),
|
||||
TaskListItem {
|
||||
task: task.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}")
|
||||
}
|
||||
match calendar_tasks_query_result.value() {
|
||||
QueryResult::Ok(QueryValue::TasksWithSubtasks(tasks))
|
||||
| QueryResult::Loading(Some(QueryValue::TasksWithSubtasks(tasks))) => {
|
||||
let today_tasks = tasks.iter().filter(|task| {
|
||||
if let Category::Calendar { date, .. } = task.task().category() {
|
||||
*date == today_date
|
||||
} else {
|
||||
panic!("Unexpected category.");
|
||||
}
|
||||
}).cloned().collect::<Vec<TaskWithSubtasks>>();
|
||||
let overdue_tasks = tasks.iter().filter(|task| {
|
||||
if let Category::Calendar { date, .. } = task.task().category() {
|
||||
*date < today_date
|
||||
} else {
|
||||
panic!("Unexpected category.");
|
||||
}
|
||||
}).cloned().collect::<Vec<TaskWithSubtasks>>();
|
||||
|
||||
rsx! {
|
||||
if !overdue_tasks.is_empty() {
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
i {
|
||||
class: "fa-solid fa-calendar-xmark text-xl w-6 text-center"
|
||||
}
|
||||
div {
|
||||
class: "mt-1",
|
||||
{t!("overdue")._upper_first()}
|
||||
}
|
||||
}
|
||||
TaskList {
|
||||
tasks: overdue_tasks,
|
||||
class: "pb-3"
|
||||
}
|
||||
}
|
||||
}
|
||||
div {
|
||||
class: "flex flex-col gap-4",
|
||||
div {
|
||||
class: "px-8 flex flex-row items-center gap-2 font-bold",
|
||||
i {
|
||||
class: "fa-solid fa-calendar-check text-xl w-6 text-center"
|
||||
}
|
||||
div {
|
||||
class: "mt-1",
|
||||
{
|
||||
let format = t!("date-weekday-format");
|
||||
let today_date = today_date.format_localized(
|
||||
format.as_str(),
|
||||
LocaleFromLanguageIdentifier::from(
|
||||
&i18n().language()
|
||||
).into()
|
||||
).to_string();
|
||||
format!(
|
||||
"{} – {}",
|
||||
t!("today")._upper_first(),
|
||||
if t!("weekday-lowercase-first").parse().unwrap() {
|
||||
today_date._lower_first()
|
||||
} else {
|
||||
today_date
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
TaskList {
|
||||
tasks: today_tasks
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryTrashPage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::Trash,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
use crate::components::pages::category_page::CategoryPage;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryWaitingForPage() -> Element {
|
||||
rsx! {
|
||||
CategoryPage {
|
||||
category: Category::WaitingFor(String::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
pub(crate) mod category_calendar_page;
|
||||
pub(crate) mod category_done_page;
|
||||
pub(crate) mod category_inbox_page;
|
||||
pub(crate) mod category_long_term_page;
|
||||
pub(crate) mod category_next_steps_page;
|
||||
pub(crate) mod category_page;
|
||||
pub(crate) mod category_someday_maybe_page;
|
||||
pub(crate) mod category_today_page;
|
||||
pub(crate) mod category_trash_page;
|
||||
pub(crate) mod category_waiting_for_page;
|
||||
pub(crate) mod not_found_page;
|
||||
pub(crate) mod projects_page;
|
||||
@@ -1,8 +0,0 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn NotFoundPage(route: Vec<String>) -> Element {
|
||||
rsx! {
|
||||
{"404"}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
use crate::models::project::Project;
|
||||
use crate::query::QueryValue;
|
||||
use crate::query::projects::use_projects_query;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_query::prelude::QueryResult;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn ProjectsPage() -> Element {
|
||||
let projects_query = use_projects_query();
|
||||
let mut project_being_edited = use_context::<Signal<Option<Project>>>();
|
||||
|
||||
rsx! {
|
||||
match projects_query.result().value() {
|
||||
QueryResult::Ok(QueryValue::Projects(projects))
|
||||
| QueryResult::Loading(Some(QueryValue::Projects(projects))) => {
|
||||
let mut projects = projects.clone();
|
||||
projects.sort();
|
||||
rsx! {
|
||||
div {
|
||||
class: "flex flex-col",
|
||||
for project in projects {
|
||||
div {
|
||||
key: "{project.id()}",
|
||||
class: format!(
|
||||
"px-8 py-4 select-none {}",
|
||||
if project_being_edited().is_some_and(|p| p.id() == project.id()) {
|
||||
"bg-zinc-700"
|
||||
} else { "" }
|
||||
),
|
||||
onclick: move |_| project_being_edited.set(Some(project.clone())),
|
||||
{project.title()}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,27 @@
|
||||
use crate::models::project::{NewProject, Project};
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::models::project::Project;
|
||||
use crate::server::projects::{create_project, delete_project, edit_project};
|
||||
use dioxus::core_macro::{component, rsx};
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_query::prelude::use_query_client;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn ProjectForm(
|
||||
project: Option<Project>,
|
||||
on_successful_submit: EventHandler<()>,
|
||||
) -> Element {
|
||||
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||
let project_for_submit = project.clone();
|
||||
|
||||
rsx! {
|
||||
form {
|
||||
onsubmit: move |event| {
|
||||
event.prevent_default();
|
||||
let project = project_for_submit.clone();
|
||||
async move {
|
||||
let new_project = NewProject::new(
|
||||
event.values().get("title").unwrap().as_value()
|
||||
);
|
||||
let new_project = event.parsed_values().unwrap();
|
||||
if let Some(project) = project {
|
||||
let _ = edit_project(project.id(), new_project).await;
|
||||
let _ = edit_project(project.id, new_project).await;
|
||||
} else {
|
||||
let _ = create_project(new_project).await;
|
||||
}
|
||||
query_client.invalidate_queries(&[QueryKey::Projects]);
|
||||
on_successful_submit.call(());
|
||||
}
|
||||
},
|
||||
@@ -44,7 +38,7 @@ pub(crate) fn ProjectForm(
|
||||
input {
|
||||
name: "title",
|
||||
required: true,
|
||||
initial_value: project.as_ref().map(|project| project.title().to_owned()),
|
||||
initial_value: project.as_ref().map(|project| project.title.to_owned()),
|
||||
r#type: "text",
|
||||
class: "py-2 px-3 grow bg-zinc-800/50 rounded-lg",
|
||||
id: "input_title"
|
||||
@@ -54,13 +48,12 @@ pub(crate) fn ProjectForm(
|
||||
class: "flex flex-row justify-between mt-auto",
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg cursor-pointer",
|
||||
onclick: move |_| {
|
||||
let project = project.clone();
|
||||
async move {
|
||||
if let Some(project) = project {
|
||||
let _ = delete_project(project.id()).await;
|
||||
query_client.invalidate_queries(&[QueryKey::Projects]);
|
||||
let _ = delete_project(project.id).await;
|
||||
}
|
||||
on_successful_submit.call(());
|
||||
}
|
||||
@@ -71,7 +64,7 @@ pub(crate) fn ProjectForm(
|
||||
}
|
||||
button {
|
||||
r#type: "submit",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg cursor-pointer",
|
||||
i {
|
||||
class: "fa-solid fa-floppy-disk"
|
||||
}
|
||||
|
||||
27
src/components/project_list.rs
Normal file
27
src/components/project_list.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use crate::{hooks::use_projects, models::project::Project};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn ProjectList() -> Element {
|
||||
let projects = use_projects()?();
|
||||
let mut project_being_edited = use_context::<Signal<Option<Project>>>();
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
class: "flex flex-col",
|
||||
for project in projects {
|
||||
div {
|
||||
key: "{project.id}",
|
||||
class: format!(
|
||||
"px-8 py-4 select-none {}",
|
||||
if project_being_edited().is_some_and(|p| p.id == project.id) {
|
||||
"bg-zinc-700"
|
||||
} else { "" }
|
||||
),
|
||||
onclick: move |_| project_being_edited.set(Some(project.clone())),
|
||||
{project.title.clone()}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/components/project_select.rs
Normal file
30
src/components/project_select.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use crate::hooks::use_projects;
|
||||
use dioxus::core_macro::{component, rsx};
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::t;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn ProjectSelect(initial_selected_id: Option<i32>) -> Element {
|
||||
let projects = use_projects()?();
|
||||
rsx! {
|
||||
select {
|
||||
name: "project_id",
|
||||
class: "px-3.5 py-2.5 bg-zinc-800/50 rounded-lg grow cursor-pointer",
|
||||
id: "input_project",
|
||||
option {
|
||||
value: 0,
|
||||
{t!("none")}
|
||||
},
|
||||
for project in projects {
|
||||
option {
|
||||
value: project.id.to_string(),
|
||||
initial_selected: initial_selected_id.is_some_and(
|
||||
|id| id == project.id
|
||||
),
|
||||
{project.title}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ pub(crate) fn ReoccurrenceIntervalInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg {} {}",
|
||||
"py-2 rounded-lg {} {} cursor-pointer",
|
||||
class_buttons.unwrap_or(""),
|
||||
if reoccurrence_interval().is_none() { "bg-zinc-500/50" }
|
||||
else { "bg-zinc-800/50" }
|
||||
@@ -27,7 +27,7 @@ pub(crate) fn ReoccurrenceIntervalInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg {} {}",
|
||||
"py-2 rounded-lg {} {} cursor-pointer",
|
||||
class_buttons.unwrap_or(""),
|
||||
if let Some(ReoccurrenceInterval::Day) = reoccurrence_interval()
|
||||
{ "bg-zinc-500/50" }
|
||||
@@ -43,7 +43,7 @@ pub(crate) fn ReoccurrenceIntervalInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg {} {}",
|
||||
"py-2 rounded-lg {} {} cursor-pointer",
|
||||
class_buttons.unwrap_or(""),
|
||||
if let Some(ReoccurrenceInterval::Month) = reoccurrence_interval()
|
||||
{ "bg-zinc-500/50" }
|
||||
@@ -59,7 +59,7 @@ pub(crate) fn ReoccurrenceIntervalInput(
|
||||
button {
|
||||
r#type: "button",
|
||||
class: format!(
|
||||
"py-2 rounded-lg {} {}",
|
||||
"py-2 rounded-lg {} {} cursor-pointer",
|
||||
class_buttons.unwrap_or(""),
|
||||
if let Some(ReoccurrenceInterval::Year) = reoccurrence_interval()
|
||||
{ "bg-zinc-500/50" }
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
use crate::hooks::use_subtasks_of_task;
|
||||
use crate::models::subtask::NewSubtask;
|
||||
use crate::models::task::Task;
|
||||
use crate::query::subtasks::use_subtasks_of_task_query;
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::server::subtasks::{create_subtask, delete_subtask, edit_subtask};
|
||||
use dioxus::core_macro::{component, rsx};
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_query::prelude::{QueryResult, use_query_client};
|
||||
|
||||
#[component]
|
||||
pub(crate) fn SubtasksForm(task: Task) -> Element {
|
||||
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||
let subtasks_query = use_subtasks_of_task_query(task.id());
|
||||
|
||||
let subtasks = use_subtasks_of_task(task.id)?();
|
||||
let mut new_title = use_signal(String::new);
|
||||
|
||||
rsx! {
|
||||
form {
|
||||
class: "flex flex-row items-center gap-3",
|
||||
onsubmit: move |event| {
|
||||
event.prevent_default();
|
||||
let task = task.clone();
|
||||
async move {
|
||||
let new_subtask = NewSubtask::new(
|
||||
task.id(),
|
||||
event.values().get("title").unwrap().as_value(),
|
||||
false
|
||||
);
|
||||
let new_subtask = NewSubtask {
|
||||
task_id: task.id,
|
||||
title: event.get("title").first().cloned().and_then(|value| match value {
|
||||
FormValue::Text(value) => Some(value),
|
||||
FormValue::File(_) => None
|
||||
}).unwrap(),
|
||||
is_completed: false
|
||||
};
|
||||
let _ = create_subtask(new_subtask).await;
|
||||
query_client.invalidate_queries(&[
|
||||
QueryKey::SubtasksOfTaskId(task.id()),
|
||||
QueryKey::TasksWithSubtasksInCategory(task.category().clone()),
|
||||
]);
|
||||
new_title.set(String::new());
|
||||
}
|
||||
},
|
||||
@@ -61,126 +56,84 @@ pub(crate) fn SubtasksForm(task: Task) -> Element {
|
||||
}
|
||||
}
|
||||
}
|
||||
match subtasks_query.result().value() {
|
||||
QueryResult::Ok(QueryValue::Subtasks(subtasks))
|
||||
| QueryResult::Loading(Some(QueryValue::Subtasks(subtasks))) => {
|
||||
let mut subtasks = subtasks.clone();
|
||||
subtasks.sort();
|
||||
rsx! {
|
||||
for subtask in subtasks {
|
||||
div {
|
||||
key: "{subtask.id()}",
|
||||
class: "flex flex-row items-center gap-3",
|
||||
i {
|
||||
class: format!(
|
||||
"{} min-w-6 text-center text-2xl text-zinc-400/50",
|
||||
if subtask.is_completed() {
|
||||
"fa solid fa-square-check"
|
||||
} else {
|
||||
"fa-regular fa-square"
|
||||
}
|
||||
),
|
||||
onclick: {
|
||||
let subtask = subtask.clone();
|
||||
let task = task.clone();
|
||||
move |_| {
|
||||
let subtask = subtask.clone();
|
||||
let task = task.clone();
|
||||
async move {
|
||||
let new_subtask = NewSubtask::new(
|
||||
subtask.task_id(),
|
||||
subtask.title().to_owned(),
|
||||
!subtask.is_completed()
|
||||
);
|
||||
let _ = edit_subtask(
|
||||
subtask.id(),
|
||||
new_subtask
|
||||
).await;
|
||||
query_client.invalidate_queries(&[
|
||||
QueryKey::SubtasksOfTaskId(task.id()),
|
||||
QueryKey::TasksWithSubtasksInCategory(
|
||||
task.category().clone()
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for subtask in subtasks {
|
||||
div {
|
||||
key: "{subtask.id}",
|
||||
class: "flex flex-row items-center gap-3",
|
||||
i {
|
||||
class: format!(
|
||||
"{} min-w-6 text-center text-2xl text-zinc-400/50",
|
||||
if subtask.is_completed {
|
||||
"fa solid fa-square-check"
|
||||
} else {
|
||||
"fa-regular fa-square"
|
||||
}
|
||||
),
|
||||
onclick: {
|
||||
let subtask = subtask.clone();
|
||||
move |_| {
|
||||
let subtask = subtask.clone();
|
||||
async move {
|
||||
let new_subtask = NewSubtask {
|
||||
task_id: subtask.task_id,
|
||||
title: subtask.title.clone(),
|
||||
is_completed: !subtask.is_completed
|
||||
};
|
||||
let _ = edit_subtask(
|
||||
subtask.id,
|
||||
new_subtask
|
||||
).await;
|
||||
}
|
||||
div {
|
||||
class: "grow grid grid-cols-6 gap-2",
|
||||
input {
|
||||
r#type: "text",
|
||||
class: "grow py-2 px-3 col-span-5 bg-zinc-800/50 rounded-lg",
|
||||
id: "input_title_{subtask.id()}",
|
||||
initial_value: subtask.title(),
|
||||
onchange: {
|
||||
let subtask = subtask.clone();
|
||||
let task = task.clone();
|
||||
move |event: Event<FormData>| {
|
||||
let subtask = subtask.clone();
|
||||
let task = task.clone();
|
||||
async move {
|
||||
let new_subtask = NewSubtask::new(
|
||||
subtask.task_id(),
|
||||
event.value(),
|
||||
subtask.is_completed()
|
||||
);
|
||||
if new_subtask.title.is_empty() {
|
||||
let _ = delete_subtask(subtask.id()).await;
|
||||
} else {
|
||||
let _ = edit_subtask(
|
||||
subtask.id(),
|
||||
new_subtask
|
||||
).await;
|
||||
}
|
||||
query_client.invalidate_queries(&[
|
||||
QueryKey::SubtasksOfTaskId(task.id()),
|
||||
QueryKey::TasksWithSubtasksInCategory(
|
||||
task.category().clone()
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "py-2 col-span-1 bg-zinc-800/50 rounded-lg",
|
||||
onclick: {
|
||||
let subtask = subtask.clone();
|
||||
let task = task.clone();
|
||||
move |_| {
|
||||
let subtask = subtask.clone();
|
||||
let task = task.clone();
|
||||
async move {
|
||||
let _ = delete_subtask(subtask.id()).await;
|
||||
query_client.invalidate_queries(&[
|
||||
QueryKey::SubtasksOfTaskId(task.id()),
|
||||
QueryKey::TasksWithSubtasksInCategory(
|
||||
task.category().clone()
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
},
|
||||
i {
|
||||
class: "fa-solid fa-trash-can"
|
||||
}
|
||||
}
|
||||
}
|
||||
div {
|
||||
class: "grow grid grid-cols-6 gap-2",
|
||||
input {
|
||||
r#type: "text",
|
||||
class: "grow py-2 px-3 col-span-5 bg-zinc-800/50 rounded-lg",
|
||||
id: "input_title_{subtask.id}",
|
||||
initial_value: subtask.title.clone(),
|
||||
onchange: {
|
||||
let subtask = subtask.clone();
|
||||
move |event: Event<FormData>| {
|
||||
let subtask = subtask.clone();
|
||||
async move {
|
||||
let new_subtask = NewSubtask {
|
||||
task_id: subtask.task_id,
|
||||
title: event.value(),
|
||||
is_completed: subtask.is_completed
|
||||
};
|
||||
if new_subtask.title.is_empty() {
|
||||
let _ = delete_subtask(subtask.id).await;
|
||||
} else {
|
||||
let _ = edit_subtask(
|
||||
subtask.id,
|
||||
new_subtask
|
||||
).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "py-2 col-span-1 bg-zinc-800/50 rounded-lg",
|
||||
onclick: {
|
||||
let subtask = subtask.clone();
|
||||
move |_| {
|
||||
let subtask = subtask.clone();
|
||||
async move {
|
||||
let _ = delete_subtask(subtask.id).await;
|
||||
}
|
||||
}
|
||||
},
|
||||
i {
|
||||
class: "fa-solid fa-trash-can"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use crate::components::category_input::CategoryInput;
|
||||
use crate::components::project_select::ProjectSelect;
|
||||
use crate::components::reoccurrence_input::ReoccurrenceIntervalInput;
|
||||
use crate::components::subtasks_form::SubtasksForm;
|
||||
use crate::models::category::{CalendarTime, Category, Reoccurrence};
|
||||
use crate::models::task::NewTask;
|
||||
use crate::models::task::Task;
|
||||
use crate::query::projects::use_projects_query;
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::route::Route;
|
||||
use crate::server::tasks::{create_task, delete_task, edit_task};
|
||||
use chrono::Duration;
|
||||
@@ -13,7 +12,7 @@ use dioxus::core_macro::{component, rsx};
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_i18n::t;
|
||||
use dioxus_query::prelude::{QueryResult, use_query_client};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const REMINDER_OFFSETS: [Option<Duration>; 17] = [
|
||||
None,
|
||||
@@ -35,14 +34,24 @@ const REMINDER_OFFSETS: [Option<Duration>; 17] = [
|
||||
Some(Duration::zero()),
|
||||
];
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct InputData {
|
||||
title: String,
|
||||
deadline: Option<String>,
|
||||
category_waiting_for: Option<String>,
|
||||
category_calendar_date: Option<String>,
|
||||
category_calendar_reoccurrence_length: Option<String>,
|
||||
category_calendar_time: Option<String>,
|
||||
category_calendar_reminder_offset_index: Option<String>,
|
||||
project_id: Option<String>,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()>) -> Element {
|
||||
let projects_query = use_projects_query();
|
||||
|
||||
let route = use_route::<Route>();
|
||||
let selected_category = use_signal(|| {
|
||||
if let Some(task) = &task {
|
||||
task.category().clone()
|
||||
task.category.clone()
|
||||
} else {
|
||||
match route {
|
||||
Route::CategorySomedayMaybePage => Category::SomedayMaybe,
|
||||
@@ -63,37 +72,34 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
if let Category::Calendar {
|
||||
reoccurrence: Some(reoccurrence),
|
||||
..
|
||||
} = task.category()
|
||||
} = &task.category
|
||||
{
|
||||
Some(reoccurrence.interval().clone())
|
||||
Some(reoccurrence.interval.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
});
|
||||
let mut category_calendar_has_time = use_signal(|| {
|
||||
task.as_ref().is_some_and(|task| {
|
||||
matches!(*task.category(), Category::Calendar { time: Some(_), .. })
|
||||
})
|
||||
task.as_ref()
|
||||
.is_some_and(|task| matches!(task.category, Category::Calendar { time: Some(_), .. }))
|
||||
});
|
||||
let mut category_calendar_reminder_offset_index = use_signal(|| {
|
||||
task.as_ref()
|
||||
.and_then(|task| {
|
||||
if let Category::Calendar {
|
||||
time: Some(time), ..
|
||||
} = task.category()
|
||||
} = &task.category
|
||||
{
|
||||
REMINDER_OFFSETS
|
||||
.iter()
|
||||
.position(|&reminder_offset| reminder_offset == time.reminder_offset())
|
||||
.position(|&reminder_offset| reminder_offset == time.reminder_offset)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or(REMINDER_OFFSETS.len() - 1)
|
||||
});
|
||||
|
||||
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||
let task_for_submit = task.clone();
|
||||
|
||||
rsx! {
|
||||
@@ -103,56 +109,50 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
class: "flex flex-col gap-4",
|
||||
id: "form_task",
|
||||
onsubmit: move |event| {
|
||||
event.prevent_default();
|
||||
let task = task_for_submit.clone();
|
||||
async move {
|
||||
let new_task = NewTask::new(
|
||||
event.values().get("title").unwrap().as_value(),
|
||||
event.values().get("deadline").unwrap().as_value().parse().ok(),
|
||||
match &selected_category() {
|
||||
let input_data = event.parsed_values::<InputData>().unwrap();
|
||||
let new_task = NewTask {
|
||||
title: input_data.title,
|
||||
deadline: input_data.deadline
|
||||
.and_then(|deadline| deadline.parse().ok()),
|
||||
category: match &selected_category() {
|
||||
Category::WaitingFor(_) => Category::WaitingFor(
|
||||
event.values().get("category_waiting_for").unwrap()
|
||||
.as_value()
|
||||
input_data.category_waiting_for.unwrap()
|
||||
),
|
||||
Category::Calendar { .. } => Category::Calendar {
|
||||
date: event.values().get("category_calendar_date").unwrap()
|
||||
.as_value().parse().unwrap(),
|
||||
date: input_data.category_calendar_date.clone().unwrap().parse()
|
||||
.unwrap(),
|
||||
reoccurrence: category_calendar_reoccurrence_interval().map(
|
||||
|reoccurrence_interval| Reoccurrence::new(
|
||||
event.values().get("category_calendar_date").unwrap()
|
||||
.as_value().parse().unwrap(),
|
||||
reoccurrence_interval,
|
||||
event.values()
|
||||
.get("category_calendar_reoccurrence_length")
|
||||
.unwrap().as_value().parse().unwrap()
|
||||
)
|
||||
|reoccurrence_interval| Reoccurrence {
|
||||
start_date: input_data.category_calendar_date.unwrap()
|
||||
.parse().unwrap(),
|
||||
interval: reoccurrence_interval,
|
||||
length: input_data.category_calendar_reoccurrence_length
|
||||
.unwrap().parse().unwrap()
|
||||
}
|
||||
),
|
||||
time: event.values().get("category_calendar_time").unwrap()
|
||||
.as_value().parse().ok().map(|time|
|
||||
CalendarTime::new(
|
||||
time: input_data.category_calendar_time.unwrap().parse().ok()
|
||||
.map(|time| CalendarTime {
|
||||
time,
|
||||
REMINDER_OFFSETS[
|
||||
event.values()
|
||||
.get("category_calendar_reminder_offset_index")
|
||||
.unwrap().as_value().parse::<usize>().unwrap()
|
||||
reminder_offset: REMINDER_OFFSETS[
|
||||
input_data.category_calendar_reminder_offset_index
|
||||
.unwrap().parse::<usize>().unwrap()
|
||||
]
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
category => category.clone()
|
||||
},
|
||||
event.values().get("project_id").unwrap()
|
||||
.as_value().parse::<i32>().ok().filter(|&id| id > 0),
|
||||
);
|
||||
project_id: input_data.project_id
|
||||
.and_then(|deadline| deadline.parse().ok()).filter(|&id| id > 0),
|
||||
};
|
||||
if let Some(task) = task {
|
||||
let _ = edit_task(task.id(), new_task).await;
|
||||
let _ = edit_task(task.id, new_task).await;
|
||||
} else {
|
||||
let _ = create_task(new_task).await;
|
||||
}
|
||||
query_client.invalidate_queries(&[
|
||||
QueryKey::Tasks,
|
||||
QueryKey::TasksInCategory(selected_category()),
|
||||
QueryKey::TasksWithSubtasksInCategory(selected_category()),
|
||||
]);
|
||||
on_successful_submit.call(());
|
||||
}
|
||||
},
|
||||
@@ -168,7 +168,7 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
input {
|
||||
name: "title",
|
||||
required: true,
|
||||
initial_value: task.as_ref().map(|task| task.title().to_owned()),
|
||||
initial_value: task.as_ref().map(|task| task.title.clone()),
|
||||
r#type: "text",
|
||||
class: "py-2 px-3 grow bg-zinc-800/50 rounded-lg",
|
||||
id: "input_title"
|
||||
@@ -183,42 +183,22 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
class: "fa-solid fa-list text-zinc-400/50"
|
||||
}
|
||||
},
|
||||
select {
|
||||
name: "project_id",
|
||||
class: "px-3.5 py-2.5 bg-zinc-800/50 rounded-lg grow",
|
||||
id: "input_project",
|
||||
option {
|
||||
value: 0,
|
||||
{t!("none")}
|
||||
SuspenseBoundary {
|
||||
fallback: |_| {
|
||||
rsx ! {
|
||||
select {
|
||||
class: "px-3.5 py-2.5 bg-zinc-800/50 rounded-lg grow cursor-pointer",
|
||||
option {
|
||||
value: 0,
|
||||
{t!("none")}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
match projects_query.result().value() {
|
||||
QueryResult::Ok(QueryValue::Projects(projects))
|
||||
| QueryResult::Loading(Some(QueryValue::Projects(projects))) => {
|
||||
let mut projects = projects.clone();
|
||||
projects.sort();
|
||||
rsx! {
|
||||
for project in projects {
|
||||
option {
|
||||
value: project.id().to_string(),
|
||||
initial_selected: task.as_ref().is_some_and(
|
||||
|task| task.project_id() == Some(project.id())
|
||||
),
|
||||
{project.title()}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
QueryResult::Loading(None) => rsx! {
|
||||
// TODO: Add a loading indicator.
|
||||
},
|
||||
QueryResult::Err(errors) => rsx! {
|
||||
div {
|
||||
"Errors occurred: {errors:?}"
|
||||
}
|
||||
},
|
||||
value => panic!("Unexpected query result: {value:?}")
|
||||
ProjectSelect {
|
||||
initial_selected_id: task.clone().and_then(|task| task.project_id)
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
div {
|
||||
class: "flex flex-row items-center gap-3",
|
||||
@@ -231,10 +211,10 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
},
|
||||
input {
|
||||
name: "deadline",
|
||||
initial_value: task.as_ref().and_then(|task| task.deadline())
|
||||
initial_value: task.as_ref().and_then(|task| task.deadline)
|
||||
.map(|deadline| deadline.format("%Y-%m-%d").to_string()),
|
||||
r#type: "date",
|
||||
class: "py-2 px-3 bg-zinc-800/50 rounded-lg grow basis-0",
|
||||
class: "py-2 px-3 bg-zinc-800/50 rounded-lg grow basis-0 cursor-pointer",
|
||||
id: "input_deadline"
|
||||
}
|
||||
},
|
||||
@@ -289,16 +269,17 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
name: "category_calendar_date",
|
||||
required: true,
|
||||
initial_value: date.format("%Y-%m-%d").to_string(),
|
||||
class: "py-2 px-3 bg-zinc-800/50 rounded-lg grow",
|
||||
class:
|
||||
"py-2 px-3 bg-zinc-800/50 rounded-lg grow cursor-pointer",
|
||||
id: "input_category_calendar_date"
|
||||
},
|
||||
input {
|
||||
r#type: "time",
|
||||
name: "category_calendar_time",
|
||||
initial_value: time.map(|calendar_time|
|
||||
calendar_time.time().format("%H:%M").to_string()
|
||||
calendar_time.time.format("%H:%M").to_string()
|
||||
),
|
||||
class: "py-2 px-3 bg-zinc-800/50 rounded-lg grow",
|
||||
class: "py-2 px-3 bg-zinc-800/50 rounded-lg grow cursor-pointer",
|
||||
id: "input_category_calendar_time",
|
||||
oninput: move |event| {
|
||||
category_calendar_has_time.set(!event.value().is_empty());
|
||||
@@ -330,7 +311,7 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
initial_value: category_calendar_reoccurrence_interval().map_or(
|
||||
String::new(),
|
||||
|_| reoccurrence.map_or(1, |reoccurrence|
|
||||
reoccurrence.length()).to_string()
|
||||
reoccurrence.length).to_string()
|
||||
),
|
||||
class: "py-2 px-3 bg-zinc-800/50 rounded-lg col-span-2 text-right",
|
||||
id: "category_calendar_reoccurrence_length"
|
||||
@@ -354,7 +335,7 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
max: REMINDER_OFFSETS.len() as i64 - 1,
|
||||
initial_value: category_calendar_reminder_offset_index()
|
||||
.to_string(),
|
||||
class: "grow input-range-reverse",
|
||||
class: "grow input-range-reverse cursor-pointer",
|
||||
id: "category_calendar_has_reminder",
|
||||
oninput: move |event| {
|
||||
category_calendar_reminder_offset_index.set(
|
||||
@@ -381,37 +362,35 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
}
|
||||
},
|
||||
if let Some(task) = task.as_ref() {
|
||||
SubtasksForm {
|
||||
task: task.clone()
|
||||
SuspenseBoundary {
|
||||
fallback: |_| {
|
||||
VNode::empty()
|
||||
},
|
||||
SubtasksForm {
|
||||
task: task.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
div {
|
||||
class: "flex flex-row justify-between mt-auto",
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg cursor-pointer",
|
||||
onclick: move |_| {
|
||||
let task = task.clone();
|
||||
async move {
|
||||
if let Some(task) = task {
|
||||
if *(task.category()) == Category::Trash {
|
||||
let _ = delete_task(task.id()).await;
|
||||
if let Category::Trash = task.category {
|
||||
let _ = delete_task(task.id).await;
|
||||
} else {
|
||||
let new_task = NewTask::new(
|
||||
task.title().to_owned(),
|
||||
task.deadline(),
|
||||
Category::Trash,
|
||||
task.project_id()
|
||||
);
|
||||
|
||||
let _ = edit_task(task.id(), new_task).await;
|
||||
let new_task = NewTask {
|
||||
title: task.title.to_owned(),
|
||||
deadline: task.deadline,
|
||||
category: Category::Trash,
|
||||
project_id: task.project_id
|
||||
};
|
||||
let _ = edit_task(task.id, new_task).await;
|
||||
}
|
||||
|
||||
query_client.invalidate_queries(&[
|
||||
QueryKey::Tasks,
|
||||
QueryKey::TasksInCategory(task.category().clone()),
|
||||
QueryKey::TasksWithSubtasksInCategory(selected_category()),
|
||||
]);
|
||||
}
|
||||
on_successful_submit.call(());
|
||||
}
|
||||
@@ -423,7 +402,7 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
||||
button {
|
||||
form: "form_task",
|
||||
r#type: "submit",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg",
|
||||
class: "py-2 px-4 bg-zinc-300/50 rounded-lg cursor-pointer",
|
||||
i {
|
||||
class: "fa-solid fa-floppy-disk"
|
||||
}
|
||||
|
||||
@@ -1,31 +1,24 @@
|
||||
use crate::components::task_list_item::TaskListItem;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::task::{Task, TaskWithSubtasks};
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::server::tasks::complete_task;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_query::prelude::use_query_client;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn TaskList(tasks: Vec<TaskWithSubtasks>, class: Option<&'static str>) -> Element {
|
||||
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||
let mut task_being_edited = use_context::<Signal<Option<Task>>>();
|
||||
|
||||
tasks.sort();
|
||||
|
||||
rsx! {
|
||||
div {
|
||||
class: format!("flex flex-col {}", class.unwrap_or("")),
|
||||
for task in tasks.clone() {
|
||||
div {
|
||||
key: "{task.task().id()}",
|
||||
key: "{task.task.id}",
|
||||
class: format!(
|
||||
"px-8 pt-4 {} flex flex-row gap-4 select-none {}",
|
||||
if task.task().deadline().is_some() || !task.subtasks().is_empty() {
|
||||
if task.task.deadline.is_some() || !task.subtasks.is_empty() {
|
||||
"pb-0.5"
|
||||
} else if let Category::Calendar { time, .. } = task.task().category() {
|
||||
} else if let Category::Calendar { time, .. } = &task.task.category {
|
||||
if time.is_some() {
|
||||
"pb-0.5"
|
||||
} else {
|
||||
@@ -34,47 +27,27 @@ pub(crate) fn TaskList(tasks: Vec<TaskWithSubtasks>, class: Option<&'static str>
|
||||
} else {
|
||||
"pb-4"
|
||||
},
|
||||
if task_being_edited().is_some_and(|t| t.id() == task.task().id()) {
|
||||
if task_being_edited().is_some_and(|t| t.id == task.task.id) {
|
||||
"bg-zinc-700"
|
||||
} else { "" }
|
||||
),
|
||||
onclick: {
|
||||
let task = task.clone();
|
||||
move |_| task_being_edited.set(Some(task.task().clone()))
|
||||
move |_| task_being_edited.set(Some(task.task.clone()))
|
||||
},
|
||||
i {
|
||||
class: format!(
|
||||
"{} text-3xl align-middle h-9 text-zinc-500",
|
||||
if *(task.task().category()) == Category::Done {
|
||||
if let Category::Done = task.task.category {
|
||||
"fa solid fa-square-check"
|
||||
} else {
|
||||
"fa-regular fa-square"
|
||||
"fa-regular fa-square cursor-pointer"
|
||||
}
|
||||
),
|
||||
onclick: {
|
||||
let task = task.clone();
|
||||
move |event: Event<MouseData>| {
|
||||
// To prevent editing the task.
|
||||
event.stop_propagation();
|
||||
let task = task.clone();
|
||||
async move {
|
||||
let completed_task = complete_task(task.task().id()).await
|
||||
.unwrap();
|
||||
let mut query_keys = vec![
|
||||
QueryKey::Tasks,
|
||||
QueryKey::TasksInCategory(
|
||||
completed_task.category().clone()
|
||||
),
|
||||
QueryKey::TasksWithSubtasksInCategory(completed_task.category().clone()),
|
||||
];
|
||||
if let Category::Calendar { reoccurrence: Some(_), .. }
|
||||
= task.task().category() {
|
||||
query_keys.push(
|
||||
QueryKey::SubtasksOfTaskId(task.task().id())
|
||||
);
|
||||
}
|
||||
query_client.invalidate_queries(&query_keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -11,23 +11,23 @@ use voca_rs::Voca;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn TaskListItem(task: TaskWithSubtasks) -> Element {
|
||||
let today_date = Local::now().date_naive();
|
||||
rsx! {
|
||||
div {
|
||||
class: "flex flex-col",
|
||||
div {
|
||||
class: "mt-1 grow font-medium",
|
||||
{task.task().title()}
|
||||
{task.task.title}
|
||||
},
|
||||
div {
|
||||
class: "flex flex-row gap-4",
|
||||
if let Some(deadline) = task.task().deadline() {
|
||||
if let Some(deadline) = task.task.deadline {
|
||||
div {
|
||||
class: "text-sm text-zinc-400",
|
||||
i {
|
||||
class: "fa-solid fa-bomb"
|
||||
},
|
||||
{
|
||||
let today_date = Local::now().date_naive();
|
||||
format!(
|
||||
" {}",
|
||||
if deadline == today_date - chrono::Days::new(1) {
|
||||
@@ -69,7 +69,7 @@ pub(crate) fn TaskListItem(task: TaskWithSubtasks) -> Element {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Category::Calendar { time, .. } = task.task().category() {
|
||||
if let Category::Calendar { time, .. } = task.task.category {
|
||||
if let Some(calendar_time) = time {
|
||||
div {
|
||||
class: "text-sm text-zinc-400",
|
||||
@@ -78,12 +78,12 @@ pub(crate) fn TaskListItem(task: TaskWithSubtasks) -> Element {
|
||||
},
|
||||
{
|
||||
let format = t!("time-format");
|
||||
format!(" {}", calendar_time.time().format(format.as_str()))
|
||||
format!(" {}", calendar_time.time.format(format.as_str()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !task.subtasks().is_empty() {
|
||||
if !task.subtasks.is_empty() {
|
||||
div {
|
||||
class: "text-sm text-zinc-400",
|
||||
i {
|
||||
@@ -91,10 +91,10 @@ pub(crate) fn TaskListItem(task: TaskWithSubtasks) -> Element {
|
||||
},
|
||||
{format!(
|
||||
" {}/{}",
|
||||
task.subtasks().iter()
|
||||
.filter(|subtask| subtask.is_completed())
|
||||
task.subtasks.iter()
|
||||
.filter(|subtask| subtask.is_completed)
|
||||
.count(),
|
||||
task.subtasks().len()
|
||||
task.subtasks.len()
|
||||
)}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user