chore: upgrade to Dioxus 0.7
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 6s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 8s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 7s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 9s
GitLeaks check / GitLeaks check (pull_request) Successful in 14s
hadolint check / hadolint check (pull_request) Successful in 16s
htmlhint check / htmlhint check (pull_request) Successful in 37s
Prettier check / Prettier check (pull_request) Successful in 26s
markdownlint check / markdownlint check (pull_request) Successful in 29s
checkov check / checkov check (pull_request) Successful in 1m22s
ShellCheck check / ShellCheck check (pull_request) Successful in 31s
Stylelint check / Stylelint check (pull_request) Successful in 31s
yamllint check / yamllint check (pull_request) Successful in 1m30s
Rust check / Rust check (pull_request) Failing after 5m44s
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 6s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 8s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 7s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 9s
GitLeaks check / GitLeaks check (pull_request) Successful in 14s
hadolint check / hadolint check (pull_request) Successful in 16s
htmlhint check / htmlhint check (pull_request) Successful in 37s
Prettier check / Prettier check (pull_request) Successful in 26s
markdownlint check / markdownlint check (pull_request) Successful in 29s
checkov check / checkov check (pull_request) Successful in 1m22s
ShellCheck check / ShellCheck check (pull_request) Successful in 31s
Stylelint check / Stylelint check (pull_request) Successful in 31s
yamllint check / yamllint check (pull_request) Successful in 1m30s
Rust check / Rust check (pull_request) Failing after 5m44s
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,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,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()
|
||||
)}
|
||||
}
|
||||
}
|
||||
|
||||
5
src/dotenv/mod.rs
Normal file
5
src/dotenv/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
load_dotenv::load_dotenv!();
|
||||
|
||||
pub(crate) const LANGUAGE_CODE: &str = env!("LANGUAGE_CODE");
|
||||
#[cfg(feature = "mobile")]
|
||||
pub(crate) const MOBILE_SERVER_URL: &str = env!("MOBILE_SERVER_URL");
|
||||
@@ -1,36 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum Error {
|
||||
ServerInternal,
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
impl From<diesel::result::Error> for Error {
|
||||
fn from(_: diesel::result::Error) -> Self {
|
||||
Self::ServerInternal
|
||||
}
|
||||
}
|
||||
|
||||
// has to be implemented for Dioxus server functions
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::ServerInternal => write!(f, "internal server error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// has to be implemented for Dioxus server functions
|
||||
impl FromStr for Error {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"internal server error" => Self::ServerInternal,
|
||||
_ => return Err(()),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
use serde::Deserialize;
|
||||
use serde_with::serde_derive::Serialize;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ErrorVec<T> {
|
||||
errors: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T> From<ErrorVec<T>> for Vec<T> {
|
||||
fn from(e: ErrorVec<T>) -> Self {
|
||||
e.errors
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Vec<T>> for ErrorVec<T> {
|
||||
fn from(e: Vec<T>) -> Self {
|
||||
ErrorVec { errors: e }
|
||||
}
|
||||
}
|
||||
|
||||
// has to be implemented for Dioxus server functions
|
||||
impl<T: Display> Display for ErrorVec<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
self.errors
|
||||
.iter()
|
||||
.map(|e| e.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// has to be implemented for Dioxus server functions
|
||||
impl<T> FromStr for ErrorVec<T> {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||
Ok(ErrorVec { errors: Vec::new() })
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
pub(crate) mod error;
|
||||
pub(crate) mod error_vec;
|
||||
pub(crate) mod project_error;
|
||||
pub(crate) mod subtask_error;
|
||||
pub(crate) mod task_error;
|
||||
@@ -1,59 +0,0 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use validator::{ValidationErrors, ValidationErrorsKind};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum ProjectError {
|
||||
TitleLengthInvalid,
|
||||
Error(Error),
|
||||
}
|
||||
|
||||
impl From<ValidationErrors> for ErrorVec<ProjectError> {
|
||||
fn from(validation_errors: ValidationErrors) -> Self {
|
||||
validation_errors
|
||||
.errors()
|
||||
.iter()
|
||||
.flat_map(|(field, error_kind)| match field.as_ref() {
|
||||
"title" => match error_kind {
|
||||
ValidationErrorsKind::Field(validation_errors) => validation_errors
|
||||
.iter()
|
||||
.map(|validation_error| validation_error.code.as_ref())
|
||||
.map(|code| match code {
|
||||
"title_length" => ProjectError::TitleLengthInvalid,
|
||||
_ => panic!("Unexpected validation error code: `{code}`."),
|
||||
})
|
||||
.collect::<Vec<ProjectError>>(),
|
||||
_ => panic!("Unexpected validation error kind."),
|
||||
},
|
||||
_ => panic!("Unexpected validation field name: `{field}`."),
|
||||
})
|
||||
.collect::<Vec<ProjectError>>()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
impl From<diesel::result::Error> for ProjectError {
|
||||
fn from(_: diesel::result::Error) -> Self {
|
||||
Self::Error(Error::ServerInternal)
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be implemented for Dioxus server functions.
|
||||
impl Display for ProjectError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be implemented for Dioxus server functions.
|
||||
impl FromStr for ProjectError {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||
Ok(Self::Error(Error::ServerInternal))
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use validator::{ValidationErrors, ValidationErrorsKind};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum SubtaskError {
|
||||
TitleLengthInvalid,
|
||||
TaskNotFound,
|
||||
Error(Error),
|
||||
}
|
||||
|
||||
impl From<ValidationErrors> for ErrorVec<SubtaskError> {
|
||||
fn from(validation_errors: ValidationErrors) -> Self {
|
||||
validation_errors
|
||||
.errors()
|
||||
.iter()
|
||||
.flat_map(|(field, error_kind)| match field.as_ref() {
|
||||
"title" => match error_kind {
|
||||
ValidationErrorsKind::Field(validation_errors) => validation_errors
|
||||
.iter()
|
||||
.map(|validation_error| validation_error.code.as_ref())
|
||||
.map(|code| match code {
|
||||
"title_length" => SubtaskError::TitleLengthInvalid,
|
||||
_ => panic!("Unexpected validation error code: `{code}`."),
|
||||
})
|
||||
.collect::<Vec<SubtaskError>>(),
|
||||
_ => panic!("Unexpected validation error kind."),
|
||||
},
|
||||
_ => panic!("Unexpected validation field name: `{field}`."),
|
||||
})
|
||||
.collect::<Vec<SubtaskError>>()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
impl From<diesel::result::Error> for SubtaskError {
|
||||
fn from(diesel_error: diesel::result::Error) -> Self {
|
||||
match diesel_error {
|
||||
diesel::result::Error::DatabaseError(
|
||||
diesel::result::DatabaseErrorKind::ForeignKeyViolation,
|
||||
info,
|
||||
) => match info.constraint_name() {
|
||||
Some("subtasks_task_id_fkey") => Self::TaskNotFound,
|
||||
_ => Self::Error(Error::ServerInternal),
|
||||
},
|
||||
_ => Self::Error(Error::ServerInternal),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorVec<Error>> for ErrorVec<SubtaskError> {
|
||||
fn from(error_vec: ErrorVec<Error>) -> Self {
|
||||
Vec::from(error_vec)
|
||||
.into_iter()
|
||||
.map(SubtaskError::Error)
|
||||
.collect::<Vec<SubtaskError>>()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be implemented for Dioxus server functions.
|
||||
impl Display for SubtaskError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be implemented for Dioxus server functions.
|
||||
impl FromStr for SubtaskError {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||
Ok(Self::Error(Error::ServerInternal))
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
use validator::{ValidationErrors, ValidationErrorsKind};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum TaskError {
|
||||
TitleLengthInvalid,
|
||||
ProjectNotFound,
|
||||
Error(Error),
|
||||
}
|
||||
|
||||
impl From<ValidationErrors> for ErrorVec<TaskError> {
|
||||
fn from(validation_errors: ValidationErrors) -> Self {
|
||||
validation_errors
|
||||
.errors()
|
||||
.iter()
|
||||
.flat_map(|(field, error_kind)| match field.as_ref() {
|
||||
"title" => match error_kind {
|
||||
ValidationErrorsKind::Field(validation_errors) => validation_errors
|
||||
.iter()
|
||||
.map(|validation_error| validation_error.code.as_ref())
|
||||
.map(|code| match code {
|
||||
"title_length" => TaskError::TitleLengthInvalid,
|
||||
_ => panic!("Unexpected validation error code: `{code}`."),
|
||||
})
|
||||
.collect::<Vec<TaskError>>(),
|
||||
_ => panic!("Unexpected validation error kind."),
|
||||
},
|
||||
_ => panic!("Unexpected validation field name: `{field}`."),
|
||||
})
|
||||
.collect::<Vec<TaskError>>()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
impl From<diesel::result::Error> for TaskError {
|
||||
fn from(diesel_error: diesel::result::Error) -> Self {
|
||||
match diesel_error {
|
||||
diesel::result::Error::DatabaseError(
|
||||
diesel::result::DatabaseErrorKind::ForeignKeyViolation,
|
||||
info,
|
||||
) => match info.constraint_name() {
|
||||
Some("tasks_project_id_fkey") => Self::ProjectNotFound,
|
||||
_ => Self::Error(Error::ServerInternal),
|
||||
},
|
||||
_ => Self::Error(Error::ServerInternal),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be implemented for Dioxus server functions.
|
||||
impl Display for TaskError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
// Has to be implemented for Dioxus server functions.
|
||||
impl FromStr for TaskError {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||
Ok(Self::Error(Error::ServerInternal))
|
||||
}
|
||||
}
|
||||
61
src/hooks/mod.rs
Normal file
61
src/hooks/mod.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use dioxus::{
|
||||
CapturedError,
|
||||
fullstack::{Loader, Loading, WebSocketOptions, use_websocket},
|
||||
prelude::*,
|
||||
};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
|
||||
use crate::{
|
||||
models::{category::Category, project::Project, subtask::Subtask, task::TaskWithSubtasks},
|
||||
server::{
|
||||
projects::get_projects, subtasks::get_subtasks_of_task,
|
||||
tasks::get_tasks_with_subtasks_in_category, updates::subscribe_to_updates,
|
||||
},
|
||||
};
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
fn use_loader_with_update_subscription<F, T, E>(
|
||||
mut future: impl FnMut() -> F + 'static,
|
||||
) -> Result<Loader<T>, Loading>
|
||||
where
|
||||
F: Future<Output = Result<T, E>> + 'static,
|
||||
T: 'static + PartialEq + Serialize + DeserializeOwned,
|
||||
E: Into<CapturedError> + 'static,
|
||||
{
|
||||
let mut refresh_tick = use_signal(|| 0u64);
|
||||
|
||||
let loader = use_loader(move || {
|
||||
let _ = refresh_tick(); // Read => dependency.
|
||||
future()
|
||||
});
|
||||
|
||||
let mut socket = use_websocket(|| subscribe_to_updates(WebSocketOptions::default()));
|
||||
use_future(move || async move {
|
||||
while socket.recv().await.is_ok() {
|
||||
refresh_tick += 1;
|
||||
}
|
||||
});
|
||||
|
||||
loader
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub(crate) fn use_projects() -> Result<Loader<Vec<Project>>, Loading> {
|
||||
use_loader_with_update_subscription(get_projects).inspect(|projects| projects().sort())
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub(crate) fn use_tasks_with_subtasks_in_category(
|
||||
filtered_category: Category,
|
||||
) -> Result<Loader<Vec<TaskWithSubtasks>>, Loading> {
|
||||
use_loader_with_update_subscription(move || {
|
||||
get_tasks_with_subtasks_in_category(filtered_category.clone())
|
||||
})
|
||||
.inspect(|tasks| tasks().sort())
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
pub(crate) fn use_subtasks_of_task(task_id: i32) -> Result<Loader<Vec<Subtask>>, Loading> {
|
||||
use_loader_with_update_subscription(move || get_subtasks_of_task(task_id))
|
||||
.inspect(|subtasks| subtasks().sort())
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
use crate::dotenv;
|
||||
use chrono::Locale;
|
||||
use dioxus::fullstack::once_cell::sync::Lazy;
|
||||
use feruca::Collator;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
use unic_langid_impl::LanguageIdentifier;
|
||||
|
||||
pub(crate) static COLLATOR: Lazy<Mutex<Collator>> = Lazy::new(|| Mutex::new(Collator::default()));
|
||||
pub(crate) fn get_language_identifier() -> LanguageIdentifier {
|
||||
dotenv::LANGUAGE_CODE
|
||||
.parse::<LanguageIdentifier>()
|
||||
.expect("The LANGUAGE_CODE environment variable is not a valid language code.")
|
||||
}
|
||||
|
||||
pub(crate) static COLLATOR: LazyLock<Mutex<Collator>> =
|
||||
LazyLock::new(|| Mutex::new(Collator::default()));
|
||||
|
||||
pub(crate) struct LocaleFromLanguageIdentifier<'a>(&'a LanguageIdentifier);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn Layout() -> Element {
|
||||
pub(crate) fn Main() -> Element {
|
||||
let mut display_form = use_signal(|| false);
|
||||
let project_being_edited =
|
||||
use_context_provider::<Signal<Option<Project>>>(|| Signal::new(None));
|
||||
@@ -20,7 +20,21 @@ pub(crate) fn Layout() -> Element {
|
||||
});
|
||||
|
||||
rsx! {
|
||||
Outlet::<Route> {}
|
||||
SuspenseBoundary {
|
||||
fallback: |_| {
|
||||
rsx! {
|
||||
div {
|
||||
class: "grow flex flex-col justify-center items-center",
|
||||
div {
|
||||
i {
|
||||
class: "text-3xl fa-solid fa-cog fa-spin"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Outlet::<Route> {}
|
||||
}
|
||||
StickyBottom {
|
||||
FormOpenButton {
|
||||
opened: display_form,
|
||||
2
src/layouts/mod.rs
Normal file
2
src/layouts/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod main;
|
||||
pub(crate) use main::Main;
|
||||
11
src/main.rs
11
src/main.rs
@@ -1,15 +1,17 @@
|
||||
mod components;
|
||||
mod errors;
|
||||
mod dotenv;
|
||||
mod hooks;
|
||||
mod internationalization;
|
||||
mod layouts;
|
||||
#[cfg(feature = "server")]
|
||||
mod migrations;
|
||||
mod models;
|
||||
mod query;
|
||||
mod route;
|
||||
#[cfg(feature = "server")]
|
||||
mod schema;
|
||||
mod server;
|
||||
mod utils;
|
||||
mod views;
|
||||
|
||||
use components::app::App;
|
||||
use dioxus::prelude::*;
|
||||
@@ -21,6 +23,9 @@ fn main() {
|
||||
migrations::run_migrations().expect("Failed to run migrations.");
|
||||
);
|
||||
|
||||
info!("Starting app.");
|
||||
#[cfg(feature = "mobile")]
|
||||
dioxus::fullstack::set_server_url(crate::dotenv::MOBILE_SERVER_URL);
|
||||
|
||||
info!("Starting the app.");
|
||||
launch(App);
|
||||
}
|
||||
|
||||
@@ -104,54 +104,15 @@ pub enum ReoccurrenceInterval {
|
||||
|
||||
#[derive(Serialize, Deserialize, Hash, Clone, Debug)]
|
||||
pub struct Reoccurrence {
|
||||
start_date: NaiveDate,
|
||||
interval: ReoccurrenceInterval,
|
||||
length: u32,
|
||||
}
|
||||
|
||||
impl Reoccurrence {
|
||||
pub fn new(start_date: NaiveDate, interval: ReoccurrenceInterval, length: u32) -> Self {
|
||||
Self {
|
||||
start_date,
|
||||
interval,
|
||||
length,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_date(&self) -> NaiveDate {
|
||||
self.start_date
|
||||
}
|
||||
|
||||
pub fn interval(&self) -> &ReoccurrenceInterval {
|
||||
&self.interval
|
||||
}
|
||||
|
||||
pub fn length(&self) -> u32 {
|
||||
self.length
|
||||
}
|
||||
pub start_date: NaiveDate,
|
||||
pub interval: ReoccurrenceInterval,
|
||||
pub length: u32,
|
||||
}
|
||||
|
||||
#[serde_with::serde_as]
|
||||
#[derive(Serialize, Deserialize, Hash, Clone, Debug)]
|
||||
pub struct CalendarTime {
|
||||
time: NaiveTime,
|
||||
pub time: NaiveTime,
|
||||
#[serde_as(as = "Option<DurationSeconds<i64>>")]
|
||||
reminder_offset: Option<Duration>,
|
||||
}
|
||||
|
||||
impl CalendarTime {
|
||||
pub fn new(time: NaiveTime, reminder_offset: Option<Duration>) -> Self {
|
||||
Self {
|
||||
time,
|
||||
reminder_offset,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn time(&self) -> NaiveTime {
|
||||
self.time
|
||||
}
|
||||
|
||||
pub fn reminder_offset(&self) -> Option<Duration> {
|
||||
self.reminder_offset
|
||||
}
|
||||
pub reminder_offset: Option<Duration>,
|
||||
}
|
||||
|
||||
@@ -18,29 +18,10 @@ const TITLE_LENGTH_MAX: u64 = 255;
|
||||
diesel(table_name = crate::schema::projects, check_for_backend(diesel::pg::Pg))
|
||||
)]
|
||||
pub struct Project {
|
||||
id: i32,
|
||||
title: String,
|
||||
created_at: NaiveDateTime,
|
||||
updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Project {
|
||||
pub fn id(&self) -> i32 {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn title(&self) -> &str {
|
||||
&self.title
|
||||
}
|
||||
|
||||
pub fn created_at(&self) -> NaiveDateTime {
|
||||
self.created_at
|
||||
}
|
||||
|
||||
pub fn updated_at(&self) -> NaiveDateTime {
|
||||
self.updated_at
|
||||
}
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Eq for Project {}
|
||||
@@ -56,7 +37,7 @@ impl Ord for Project {
|
||||
COLLATOR
|
||||
.lock()
|
||||
.unwrap()
|
||||
.collate(self.title(), other.title())
|
||||
.collate(self.title.as_str(), other.title.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +52,3 @@ pub struct NewProject {
|
||||
))]
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
impl NewProject {
|
||||
pub fn new(title: String) -> Self {
|
||||
Self { title }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const TITLE_LENGTH_MAX: u64 = 255;
|
||||
derive(Queryable, Selectable, Identifiable, Associations)
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "server",
|
||||
feature = "server",
|
||||
diesel(
|
||||
table_name = subtasks,
|
||||
belongs_to(Task, foreign_key = task_id),
|
||||
@@ -26,38 +26,12 @@ const TITLE_LENGTH_MAX: u64 = 255;
|
||||
)
|
||||
)]
|
||||
pub struct Subtask {
|
||||
id: i32,
|
||||
task_id: i32,
|
||||
title: String,
|
||||
is_completed: bool,
|
||||
created_at: NaiveDateTime,
|
||||
updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Subtask {
|
||||
pub fn id(&self) -> i32 {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn task_id(&self) -> i32 {
|
||||
self.task_id
|
||||
}
|
||||
|
||||
pub fn title(&self) -> &str {
|
||||
&self.title
|
||||
}
|
||||
|
||||
pub fn is_completed(&self) -> bool {
|
||||
self.is_completed
|
||||
}
|
||||
|
||||
pub fn created_at(&self) -> NaiveDateTime {
|
||||
self.created_at
|
||||
}
|
||||
|
||||
pub fn updated_at(&self) -> NaiveDateTime {
|
||||
self.updated_at
|
||||
}
|
||||
pub id: i32,
|
||||
pub task_id: i32,
|
||||
pub title: String,
|
||||
pub is_completed: bool,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Eq for Subtask {}
|
||||
@@ -70,9 +44,9 @@ impl PartialOrd<Self> for Subtask {
|
||||
|
||||
impl Ord for Subtask {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.is_completed()
|
||||
.cmp(&other.is_completed())
|
||||
.then(self.created_at().cmp(&other.created_at()))
|
||||
self.is_completed
|
||||
.cmp(&other.is_completed)
|
||||
.then(self.created_at.cmp(&other.created_at))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,18 +64,12 @@ pub struct NewSubtask {
|
||||
pub is_completed: bool,
|
||||
}
|
||||
|
||||
impl NewSubtask {
|
||||
pub fn new(task_id: i32, title: String, is_completed: bool) -> Self {
|
||||
impl From<Subtask> for NewSubtask {
|
||||
fn from(subtask: Subtask) -> Self {
|
||||
Self {
|
||||
task_id,
|
||||
title,
|
||||
is_completed,
|
||||
task_id: subtask.task_id,
|
||||
title: subtask.title,
|
||||
is_completed: subtask.is_completed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Subtask> for NewSubtask {
|
||||
fn from(subtask: Subtask) -> Self {
|
||||
Self::new(subtask.task_id, subtask.title, subtask.is_completed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,43 +17,13 @@ const TITLE_LENGTH_MAX: u64 = 255;
|
||||
#[cfg_attr(feature = "server", derive(Queryable, Selectable, Identifiable))]
|
||||
#[cfg_attr(feature = "server", diesel(table_name = tasks, check_for_backend(diesel::pg::Pg)))]
|
||||
pub struct Task {
|
||||
id: i32,
|
||||
title: String,
|
||||
deadline: Option<chrono::NaiveDate>,
|
||||
category: Category,
|
||||
project_id: Option<i32>,
|
||||
created_at: NaiveDateTime,
|
||||
updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub fn id(&self) -> i32 {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn title(&self) -> &str {
|
||||
&self.title
|
||||
}
|
||||
|
||||
pub fn deadline(&self) -> Option<chrono::NaiveDate> {
|
||||
self.deadline
|
||||
}
|
||||
|
||||
pub fn category(&self) -> &Category {
|
||||
&self.category
|
||||
}
|
||||
|
||||
pub fn project_id(&self) -> Option<i32> {
|
||||
self.project_id
|
||||
}
|
||||
|
||||
pub fn created_at(&self) -> NaiveDateTime {
|
||||
self.created_at
|
||||
}
|
||||
|
||||
pub fn updated_at(&self) -> NaiveDateTime {
|
||||
self.updated_at
|
||||
}
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub deadline: Option<chrono::NaiveDate>,
|
||||
pub category: Category,
|
||||
pub project_id: Option<i32>,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Eq for Task {}
|
||||
@@ -83,24 +53,22 @@ impl Ord for Task {
|
||||
.cmp(other_date)
|
||||
.then(
|
||||
ReverseOrdOption::from(
|
||||
&self_time.as_ref().map(|calendar_time| calendar_time.time()),
|
||||
&self_time.as_ref().map(|calendar_time| calendar_time.time),
|
||||
)
|
||||
.cmp(&ReverseOrdOption::from(
|
||||
&other_time
|
||||
.as_ref()
|
||||
.map(|calendar_time| calendar_time.time()),
|
||||
&other_time.as_ref().map(|calendar_time| calendar_time.time),
|
||||
)),
|
||||
)
|
||||
.then(
|
||||
ReverseOrdOption::from(&self.deadline())
|
||||
.cmp(&ReverseOrdOption::from(&other.deadline())),
|
||||
ReverseOrdOption::from(&self.deadline)
|
||||
.cmp(&ReverseOrdOption::from(&other.deadline)),
|
||||
)
|
||||
.then(self.created_at.cmp(&other.created_at)),
|
||||
(Category::Done, Category::Done) | (Category::Trash, Category::Trash) => {
|
||||
self.updated_at.cmp(&other.updated_at).reverse()
|
||||
}
|
||||
(_, _) => ReverseOrdOption::from(&self.deadline())
|
||||
.cmp(&ReverseOrdOption::from(&other.deadline()))
|
||||
(_, _) => ReverseOrdOption::from(&self.deadline)
|
||||
.cmp(&ReverseOrdOption::from(&other.deadline))
|
||||
.then(self.created_at.cmp(&other.created_at)),
|
||||
}
|
||||
}
|
||||
@@ -108,22 +76,8 @@ impl Ord for Task {
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
|
||||
pub struct TaskWithSubtasks {
|
||||
task: Task,
|
||||
subtasks: Vec<Subtask>,
|
||||
}
|
||||
|
||||
impl TaskWithSubtasks {
|
||||
pub fn new(task: Task, subtasks: Vec<Subtask>) -> Self {
|
||||
Self { task, subtasks }
|
||||
}
|
||||
|
||||
pub fn task(&self) -> &Task {
|
||||
&self.task
|
||||
}
|
||||
|
||||
pub fn subtasks(&self) -> &Vec<Subtask> {
|
||||
&self.subtasks
|
||||
}
|
||||
pub task: Task,
|
||||
pub subtasks: Vec<Subtask>,
|
||||
}
|
||||
|
||||
impl Eq for TaskWithSubtasks {}
|
||||
@@ -136,7 +90,7 @@ impl PartialOrd<Self> for TaskWithSubtasks {
|
||||
|
||||
impl Ord for TaskWithSubtasks {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.task().cmp(other.task())
|
||||
self.task.cmp(&other.task)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,24 +109,13 @@ pub struct NewTask {
|
||||
pub project_id: Option<i32>,
|
||||
}
|
||||
|
||||
impl NewTask {
|
||||
pub fn new(
|
||||
title: String,
|
||||
deadline: Option<chrono::NaiveDate>,
|
||||
category: Category,
|
||||
project_id: Option<i32>,
|
||||
) -> Self {
|
||||
impl From<Task> for NewTask {
|
||||
fn from(task: Task) -> Self {
|
||||
Self {
|
||||
title,
|
||||
deadline,
|
||||
category,
|
||||
project_id,
|
||||
title: task.title,
|
||||
deadline: task.deadline,
|
||||
category: task.category,
|
||||
project_id: task.project_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Task> for NewTask {
|
||||
fn from(task: Task) -> Self {
|
||||
Self::new(task.title, task.deadline, task.category, task.project_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use crate::models::category::Category;
|
||||
use crate::models::project::Project;
|
||||
use crate::models::subtask::Subtask;
|
||||
use crate::models::task::{Task, TaskWithSubtasks};
|
||||
|
||||
pub(crate) mod projects;
|
||||
pub(crate) mod subtasks;
|
||||
pub(crate) mod tasks;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub(crate) enum QueryValue {
|
||||
Projects(Vec<Project>),
|
||||
Tasks(Vec<Task>),
|
||||
TasksWithSubtasks(Vec<TaskWithSubtasks>),
|
||||
Subtasks(Vec<Subtask>),
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum QueryErrors {
|
||||
Error(ErrorVec<Error>),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||
pub(crate) enum QueryKey {
|
||||
Projects,
|
||||
Tasks,
|
||||
TasksInCategory(Category),
|
||||
TasksWithSubtasksInCategory(Category),
|
||||
SubtasksOfTaskId(i32),
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::server::projects::get_projects;
|
||||
use dioxus::prelude::ServerFnError;
|
||||
use dioxus_query::prelude::{QueryResult, UseQuery, use_get_query};
|
||||
|
||||
pub(crate) fn use_projects_query() -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||
use_get_query([QueryKey::Projects, QueryKey::Tasks], fetch_projects)
|
||||
}
|
||||
|
||||
async fn fetch_projects(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
||||
if let Some(QueryKey::Projects) = keys.first() {
|
||||
match get_projects().await {
|
||||
Ok(projects) => Ok(QueryValue::Projects(projects)),
|
||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||
Err(error) => panic!("Unexpected error: {error:?}"),
|
||||
}
|
||||
.into()
|
||||
} else {
|
||||
panic!("Unexpected query keys: {keys:?}");
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::server::subtasks::get_subtasks_of_task;
|
||||
use dioxus::prelude::ServerFnError;
|
||||
use dioxus_query::prelude::{QueryResult, UseQuery, use_get_query};
|
||||
|
||||
pub(crate) fn use_subtasks_of_task_query(
|
||||
task_id: i32,
|
||||
) -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||
use_get_query(
|
||||
[QueryKey::SubtasksOfTaskId(task_id)],
|
||||
fetch_subtasks_of_task,
|
||||
)
|
||||
}
|
||||
|
||||
async fn fetch_subtasks_of_task(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
||||
if let Some(QueryKey::SubtasksOfTaskId(task_id)) = keys.first() {
|
||||
match get_subtasks_of_task(*task_id).await {
|
||||
Ok(subtasks) => Ok(QueryValue::Subtasks(subtasks)),
|
||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||
Err(error) => panic!("Unexpected error: {error:?}"),
|
||||
}
|
||||
.into()
|
||||
} else {
|
||||
panic!("Unexpected query keys: {keys:?}");
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
use crate::models::category::Category;
|
||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||
use crate::server::tasks::{get_tasks_in_category, get_tasks_with_subtasks_in_category};
|
||||
use dioxus::prelude::ServerFnError;
|
||||
use dioxus_query::prelude::{QueryResult, UseQuery, use_get_query};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn use_tasks_in_category_query(
|
||||
category: Category,
|
||||
) -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||
use_get_query(
|
||||
[QueryKey::TasksInCategory(category), QueryKey::Tasks],
|
||||
fetch_tasks_in_category,
|
||||
)
|
||||
}
|
||||
|
||||
async fn fetch_tasks_in_category(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
||||
if let Some(QueryKey::TasksInCategory(category)) = keys.first() {
|
||||
match get_tasks_in_category(category.clone()).await {
|
||||
Ok(tasks) => Ok(QueryValue::Tasks(tasks)),
|
||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||
Err(error) => panic!("Unexpected error: {error:?}"),
|
||||
}
|
||||
.into()
|
||||
} else {
|
||||
panic!("Unexpected query keys: {keys:?}");
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn use_tasks_with_subtasks_in_category_query(
|
||||
category: Category,
|
||||
) -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||
use_get_query(
|
||||
[
|
||||
QueryKey::TasksWithSubtasksInCategory(category.clone()),
|
||||
QueryKey::TasksInCategory(category),
|
||||
QueryKey::Tasks,
|
||||
],
|
||||
fetch_tasks_with_subtasks_in_category,
|
||||
)
|
||||
}
|
||||
|
||||
async fn fetch_tasks_with_subtasks_in_category(
|
||||
keys: Vec<QueryKey>,
|
||||
) -> QueryResult<QueryValue, QueryErrors> {
|
||||
if let Some(QueryKey::TasksWithSubtasksInCategory(category)) = keys.first() {
|
||||
match get_tasks_with_subtasks_in_category(category.clone()).await {
|
||||
Ok(tasks) => Ok(QueryValue::TasksWithSubtasks(tasks)),
|
||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||
Err(error) => panic!("Unexpected error: {error:?}"),
|
||||
}
|
||||
.into()
|
||||
} else {
|
||||
panic!("Unexpected query keys: {keys:?}");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
use crate::components::layout::Layout;
|
||||
use crate::components::pages::category_calendar_page::CategoryCalendarPage;
|
||||
use crate::components::pages::category_done_page::CategoryDonePage;
|
||||
use crate::components::pages::category_inbox_page::CategoryInboxPage;
|
||||
use crate::components::pages::category_long_term_page::CategoryLongTermPage;
|
||||
use crate::components::pages::category_next_steps_page::CategoryNextStepsPage;
|
||||
use crate::components::pages::category_someday_maybe_page::CategorySomedayMaybePage;
|
||||
use crate::components::pages::category_today_page::CategoryTodayPage;
|
||||
use crate::components::pages::category_trash_page::CategoryTrashPage;
|
||||
use crate::components::pages::category_waiting_for_page::CategoryWaitingForPage;
|
||||
use crate::components::pages::not_found_page::NotFoundPage;
|
||||
use crate::components::pages::projects_page::ProjectsPage;
|
||||
use crate::layouts;
|
||||
use crate::views::category_calendar_page::CategoryCalendarPage;
|
||||
use crate::views::category_done_page::CategoryDonePage;
|
||||
use crate::views::category_inbox_page::CategoryInboxPage;
|
||||
use crate::views::category_long_term_page::CategoryLongTermPage;
|
||||
use crate::views::category_next_steps_page::CategoryNextStepsPage;
|
||||
use crate::views::category_someday_maybe_page::CategorySomedayMaybePage;
|
||||
use crate::views::category_today_page::CategoryTodayPage;
|
||||
use crate::views::category_trash_page::CategoryTrashPage;
|
||||
use crate::views::category_waiting_for_page::CategoryWaitingForPage;
|
||||
use crate::views::not_found_page::NotFoundPage;
|
||||
use crate::views::projects_page::ProjectsPage;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
// All variants have the same postfix because they have to match the component names.
|
||||
@@ -17,7 +17,7 @@ use dioxus::prelude::*;
|
||||
#[derive(Clone, Routable, Debug, PartialEq)]
|
||||
#[rustfmt::skip]
|
||||
pub(crate) enum Route {
|
||||
#[layout(Layout)]
|
||||
#[layout(layouts::Main)]
|
||||
#[redirect("/", || Route::CategoryTodayPage {})]
|
||||
#[route("/today")]
|
||||
CategoryTodayPage,
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::prelude::*;
|
||||
use dotenvy::dotenv;
|
||||
use std::env;
|
||||
|
||||
const DATABASE_URL: &str = "postgres://app:app@db/todo_baggins";
|
||||
|
||||
pub(crate) fn establish_database_connection() -> ConnectionResult<PgConnection> {
|
||||
dotenv().expect("Could not load environment variables.");
|
||||
|
||||
let database_url =
|
||||
env::var("DATABASE_URL").expect("The environment variable DATABASE_URL has to be set.");
|
||||
PgConnection::establish(&database_url)
|
||||
PgConnection::establish(DATABASE_URL)
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
use dioxus::prelude::ServerFnError;
|
||||
use dioxus::prelude::*;
|
||||
#[cfg(feature = "server")]
|
||||
use dotenvy::dotenv;
|
||||
use std::env;
|
||||
use unic_langid_impl::LanguageIdentifier;
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn get_language_identifier() -> Result<LanguageIdentifier, ServerFnError> {
|
||||
dotenv().expect("Could not load environment variables from the .env file.");
|
||||
|
||||
Ok(env::var("LANGUAGE_CODE")
|
||||
.expect("The environment variable LANGUAGE_CODE must be set.")
|
||||
.parse::<LanguageIdentifier>()?)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) mod database_connection;
|
||||
pub(crate) mod internationalization;
|
||||
pub(crate) mod projects;
|
||||
pub(crate) mod subtasks;
|
||||
pub(crate) mod tasks;
|
||||
pub(crate) mod updates;
|
||||
|
||||
@@ -1,100 +1,75 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use crate::errors::project_error::ProjectError;
|
||||
use crate::models::project::{NewProject, Project};
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::database_connection::establish_database_connection;
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::updates::publish_update;
|
||||
#[cfg(feature = "server")]
|
||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl, SelectableHelper};
|
||||
use dioxus::prelude::*;
|
||||
#[cfg(feature = "server")]
|
||||
use validator::Validate;
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn create_project(
|
||||
new_project: NewProject,
|
||||
) -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> {
|
||||
pub(crate) async fn create_project(new_project: NewProject) -> Result<Project> {
|
||||
use crate::schema::projects;
|
||||
|
||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||
let mut new_project = new_project;
|
||||
new_project.title = new_project.title.trim().to_owned();
|
||||
|
||||
new_project
|
||||
.validate()
|
||||
.map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?;
|
||||
|
||||
let mut connection =
|
||||
establish_database_connection().map_err::<ErrorVec<ProjectError>, _>(|_| {
|
||||
vec![ProjectError::Error(Error::ServerInternal)].into()
|
||||
})?;
|
||||
new_project.validate()?;
|
||||
|
||||
let mut connection = establish_database_connection()?;
|
||||
let new_project = diesel::insert_into(projects::table)
|
||||
.values(&new_project)
|
||||
.returning(Project::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<ProjectError>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
publish_update().await;
|
||||
|
||||
Ok(new_project)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn get_projects() -> Result<Vec<Project>, ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn get_projects() -> Result<Vec<Project>> {
|
||||
use crate::schema::projects::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
|
||||
let mut connection = establish_database_connection()?;
|
||||
let results = projects
|
||||
.select(Project::as_select())
|
||||
.load::<Project>(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
.load::<Project>(&mut connection)?;
|
||||
|
||||
Ok(results)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn edit_project(
|
||||
project_id: i32,
|
||||
new_project: NewProject,
|
||||
) -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> {
|
||||
pub(crate) async fn edit_project(project_id: i32, new_project: NewProject) -> Result<Project> {
|
||||
use crate::schema::projects::dsl::*;
|
||||
|
||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||
let mut new_project = new_project;
|
||||
new_project.title = new_project.title.trim().to_owned();
|
||||
|
||||
new_project
|
||||
.validate()
|
||||
.map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?;
|
||||
|
||||
let mut connection =
|
||||
establish_database_connection().map_err::<ErrorVec<ProjectError>, _>(|_| {
|
||||
vec![ProjectError::Error(Error::ServerInternal)].into()
|
||||
})?;
|
||||
new_project.validate()?;
|
||||
|
||||
let mut connection = establish_database_connection()?;
|
||||
let updated_project = diesel::update(projects)
|
||||
.filter(id.eq(project_id))
|
||||
.set(title.eq(new_project.title))
|
||||
.returning(Project::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<ProjectError>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(updated_project)
|
||||
}
|
||||
|
||||
// TODO: Get rid of this suppression.
|
||||
//noinspection DuplicatedCode
|
||||
#[server]
|
||||
pub(crate) async fn delete_project(project_id: i32) -> Result<(), ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn delete_project(project_id: i32) -> Result<()> {
|
||||
use crate::schema::projects::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
|
||||
diesel::delete(projects.filter(id.eq(project_id)))
|
||||
.execute(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
diesel::delete(projects.filter(id.eq(project_id))).execute(&mut connection)?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,86 +1,64 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use crate::errors::subtask_error::SubtaskError;
|
||||
use crate::models::subtask::{NewSubtask, Subtask};
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::database_connection::establish_database_connection;
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::tasks::trigger_task_updated_at;
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::updates::publish_update;
|
||||
#[cfg(feature = "server")]
|
||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl, SelectableHelper};
|
||||
use dioxus::prelude::*;
|
||||
#[cfg(feature = "server")]
|
||||
use validator::Validate;
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn create_subtask(
|
||||
new_subtask: NewSubtask,
|
||||
) -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> {
|
||||
pub(crate) async fn create_subtask(new_subtask: NewSubtask) -> Result<Subtask> {
|
||||
use crate::schema::subtasks;
|
||||
|
||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||
let mut new_subtask = new_subtask;
|
||||
new_subtask.title = new_subtask.title.trim().to_owned();
|
||||
|
||||
new_subtask
|
||||
.validate()
|
||||
.map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?;
|
||||
new_subtask.validate()?;
|
||||
|
||||
let mut connection =
|
||||
establish_database_connection().map_err::<ErrorVec<SubtaskError>, _>(|_| {
|
||||
vec![SubtaskError::Error(Error::ServerInternal)].into()
|
||||
})?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let created_subtask = diesel::insert_into(subtasks::table)
|
||||
.values(&new_subtask)
|
||||
.returning(Subtask::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<SubtaskError>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
trigger_task_updated_at(new_subtask.task_id)
|
||||
.await
|
||||
.map_err::<ErrorVec<SubtaskError>, _>(|error_vec| error_vec.into())?;
|
||||
trigger_task_updated_at(new_subtask.task_id).await?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(created_subtask)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn get_subtasks_of_task(
|
||||
filtered_task_id: i32,
|
||||
) -> Result<Vec<Subtask>, ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn get_subtasks_of_task(filtered_task_id: i32) -> Result<Vec<Subtask>> {
|
||||
use crate::schema::subtasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let results = subtasks
|
||||
.select(Subtask::as_select())
|
||||
.filter(task_id.eq(filtered_task_id))
|
||||
.load::<Subtask>(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
.load::<Subtask>(&mut connection)?;
|
||||
|
||||
Ok(results)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn edit_subtask(
|
||||
subtask_id: i32,
|
||||
new_subtask: NewSubtask,
|
||||
) -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> {
|
||||
pub(crate) async fn edit_subtask(subtask_id: i32, new_subtask: NewSubtask) -> Result<Subtask> {
|
||||
use crate::schema::subtasks::dsl::*;
|
||||
|
||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||
let mut new_subtask = new_subtask;
|
||||
new_subtask.title = new_subtask.title.trim().to_owned();
|
||||
|
||||
new_subtask
|
||||
.validate()
|
||||
.map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?;
|
||||
new_subtask.validate()?;
|
||||
|
||||
let mut connection =
|
||||
establish_database_connection().map_err::<ErrorVec<SubtaskError>, _>(|_| {
|
||||
vec![SubtaskError::Error(Error::ServerInternal)].into()
|
||||
})?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let updated_task = diesel::update(subtasks)
|
||||
.filter(id.eq(subtask_id))
|
||||
@@ -89,50 +67,41 @@ pub(crate) async fn edit_subtask(
|
||||
is_completed.eq(new_subtask.is_completed),
|
||||
))
|
||||
.returning(Subtask::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<SubtaskError>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
trigger_task_updated_at(new_subtask.task_id)
|
||||
.await
|
||||
.map_err::<ErrorVec<SubtaskError>, _>(|error_vec| error_vec.into())?;
|
||||
trigger_task_updated_at(new_subtask.task_id).await?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(updated_task)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn restore_subtasks_of_task(
|
||||
filtered_task_id: i32,
|
||||
) -> Result<Vec<Subtask>, ServerFnError<ErrorVec<Error>>> {
|
||||
#[cfg(feature = "server")]
|
||||
pub(super) async fn restore_subtasks_of_task(filtered_task_id: i32) -> Result<Vec<Subtask>> {
|
||||
use crate::schema::subtasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let updated_subtasks = diesel::update(subtasks)
|
||||
.filter(task_id.eq(filtered_task_id))
|
||||
.set(is_completed.eq(false))
|
||||
.returning(Subtask::as_returning())
|
||||
.get_results(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||
.get_results(&mut connection)?;
|
||||
|
||||
Ok(updated_subtasks)
|
||||
}
|
||||
|
||||
// TODO: Get rid of this suppression.
|
||||
//noinspection DuplicatedCode
|
||||
#[server]
|
||||
pub(crate) async fn delete_subtask(subtask_id: i32) -> Result<(), ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn delete_subtask(subtask_id: i32) -> Result<()> {
|
||||
use crate::schema::subtasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let deleted_subtask = diesel::delete(subtasks.filter(id.eq(subtask_id)))
|
||||
.returning(Subtask::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
trigger_task_updated_at(deleted_subtask.task_id()).await?;
|
||||
trigger_task_updated_at(deleted_subtask.task_id).await?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use crate::errors::error::Error;
|
||||
use crate::errors::error_vec::ErrorVec;
|
||||
use crate::errors::task_error::TaskError;
|
||||
use crate::models::category::Category;
|
||||
#[cfg(feature = "server")]
|
||||
use crate::models::category::ReoccurrenceInterval;
|
||||
@@ -12,6 +9,8 @@ use crate::server::database_connection::establish_database_connection;
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::subtasks::restore_subtasks_of_task;
|
||||
#[cfg(feature = "server")]
|
||||
use crate::server::updates::publish_update;
|
||||
#[cfg(feature = "server")]
|
||||
use chrono::{Datelike, Days, Local, Months, NaiveDate};
|
||||
#[cfg(feature = "server")]
|
||||
use diesel::prelude::*;
|
||||
@@ -24,65 +23,52 @@ use time::Month;
|
||||
use validator::Validate;
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn create_task(
|
||||
new_task: NewTask,
|
||||
) -> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
|
||||
pub(crate) async fn create_task(new_task: NewTask) -> Result<Task> {
|
||||
use crate::schema::tasks;
|
||||
|
||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||
let mut new_task = new_task;
|
||||
new_task.title = new_task.title.trim().to_owned();
|
||||
|
||||
new_task
|
||||
.validate()
|
||||
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
|
||||
new_task.validate()?;
|
||||
|
||||
let mut connection =
|
||||
establish_database_connection().map_err::<ErrorVec<TaskError>, _>(|_| {
|
||||
vec![TaskError::Error(Error::ServerInternal)].into()
|
||||
})?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let new_task = diesel::insert_into(tasks::table)
|
||||
.values(&new_task)
|
||||
.returning(Task::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<TaskError>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(new_task)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn get_task(task_id: i32) -> Result<Task, ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn get_task(task_id: i32) -> Result<Task> {
|
||||
use crate::schema::tasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let task = tasks
|
||||
.find(task_id)
|
||||
.select(Task::as_select())
|
||||
.first(&mut connection)
|
||||
.optional()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
.optional()?;
|
||||
|
||||
// TODO: Handle not finding the task.
|
||||
Ok(task.unwrap())
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn get_tasks_in_category(
|
||||
filtered_category: Category,
|
||||
) -> Result<Vec<Task>, ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn get_tasks_in_category(filtered_category: Category) -> Result<Vec<Task>> {
|
||||
use crate::schema::tasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let results = tasks
|
||||
.select(Task::as_select())
|
||||
.filter(filtered_category.eq_sql_predicate())
|
||||
.load::<Task>(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
.load::<Task>(&mut connection)?;
|
||||
|
||||
Ok(results)
|
||||
}
|
||||
@@ -90,52 +76,40 @@ pub(crate) async fn get_tasks_in_category(
|
||||
#[server]
|
||||
pub(crate) async fn get_tasks_with_subtasks_in_category(
|
||||
filtered_category: Category,
|
||||
) -> Result<Vec<TaskWithSubtasks>, ServerFnError<ErrorVec<Error>>> {
|
||||
) -> Result<Vec<TaskWithSubtasks>> {
|
||||
use crate::schema::tasks;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let tasks_in_category = tasks::table
|
||||
.filter(filtered_category.eq_sql_predicate())
|
||||
.select(Task::as_select())
|
||||
.load(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
.load(&mut connection)?;
|
||||
|
||||
let subtasks = Subtask::belonging_to(&tasks_in_category)
|
||||
.select(Subtask::as_select())
|
||||
.load(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
.load(&mut connection)?;
|
||||
|
||||
let tasks_with_subtasks = subtasks
|
||||
.grouped_by(&tasks_in_category)
|
||||
.into_iter()
|
||||
.zip(tasks_in_category)
|
||||
.map(|(pages, book)| TaskWithSubtasks::new(book, pages))
|
||||
.map(|(subtasks, task)| TaskWithSubtasks { task, subtasks })
|
||||
.collect();
|
||||
|
||||
Ok(tasks_with_subtasks)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn edit_task(
|
||||
task_id: i32,
|
||||
mut new_task: NewTask,
|
||||
) -> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
|
||||
pub(crate) async fn edit_task(task_id: i32, mut new_task: NewTask) -> Result<Task> {
|
||||
use crate::schema::tasks::dsl::*;
|
||||
|
||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||
let mut new_task = new_task;
|
||||
new_task.title = new_task.title.trim().to_owned();
|
||||
|
||||
new_task
|
||||
.validate()
|
||||
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
|
||||
new_task.validate()?;
|
||||
|
||||
let mut connection =
|
||||
establish_database_connection().map_err::<ErrorVec<TaskError>, _>(|_| {
|
||||
vec![TaskError::Error(Error::ServerInternal)].into()
|
||||
})?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let updated_task = diesel::update(tasks)
|
||||
.filter(id.eq(task_id))
|
||||
@@ -146,14 +120,14 @@ pub(crate) async fn edit_task(
|
||||
project_id.eq(new_task.project_id),
|
||||
))
|
||||
.returning(Task::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<TaskError>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(updated_task)
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn complete_task(task_id: i32) -> Result<Task> {
|
||||
let task = get_task(task_id).await?;
|
||||
let mut new_task = NewTask::from(task);
|
||||
|
||||
@@ -163,13 +137,13 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
||||
..
|
||||
} = &mut new_task.category
|
||||
{
|
||||
match reoccurrence.interval() {
|
||||
ReoccurrenceInterval::Day => *date = *date + Days::new(reoccurrence.length() as u64),
|
||||
match reoccurrence.interval {
|
||||
ReoccurrenceInterval::Day => *date = *date + Days::new(reoccurrence.length as u64),
|
||||
ReoccurrenceInterval::Month | ReoccurrenceInterval::Year => {
|
||||
*date = *date
|
||||
+ Months::new(
|
||||
reoccurrence.length()
|
||||
* if *(reoccurrence.interval()) == ReoccurrenceInterval::Year {
|
||||
reoccurrence.length
|
||||
* if reoccurrence.interval == ReoccurrenceInterval::Year {
|
||||
12
|
||||
} else {
|
||||
1
|
||||
@@ -178,7 +152,7 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
||||
*date = NaiveDate::from_ymd_opt(
|
||||
date.year(),
|
||||
date.month(),
|
||||
reoccurrence.start_date().day().min(
|
||||
reoccurrence.start_date.day().min(
|
||||
Month::try_from(date.month() as u8)
|
||||
.unwrap()
|
||||
.length(date.year()) as u32,
|
||||
@@ -192,42 +166,35 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
||||
new_task.category = Category::Done;
|
||||
}
|
||||
|
||||
let updated_task = edit_task(task_id, new_task)
|
||||
.await
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let updated_task = edit_task(task_id, new_task).await?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(updated_task)
|
||||
}
|
||||
|
||||
// TODO: Get rid of this suppression.
|
||||
//noinspection DuplicatedCode
|
||||
#[server]
|
||||
pub(crate) async fn delete_task(task_id: i32) -> Result<(), ServerFnError<ErrorVec<Error>>> {
|
||||
pub(crate) async fn delete_task(task_id: i32) -> Result<()> {
|
||||
use crate::schema::tasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
diesel::delete(tasks.filter(id.eq(task_id)))
|
||||
.execute(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||
diesel::delete(tasks.filter(id.eq(task_id))).execute(&mut connection)?;
|
||||
|
||||
publish_update().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) async fn trigger_task_updated_at(task_id: i32) -> Result<Task, ErrorVec<Error>> {
|
||||
pub(crate) async fn trigger_task_updated_at(task_id: i32) -> Result<Task> {
|
||||
use crate::schema::tasks::dsl::*;
|
||||
|
||||
let mut connection = establish_database_connection()
|
||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||
let mut connection = establish_database_connection()?;
|
||||
|
||||
let updated_task = diesel::update(tasks)
|
||||
.filter(id.eq(task_id))
|
||||
.set(updated_at.eq(Local::now().naive_local()))
|
||||
.returning(Task::as_returning())
|
||||
.get_result(&mut connection)
|
||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||
.get_result(&mut connection)?;
|
||||
|
||||
Ok(updated_task)
|
||||
}
|
||||
|
||||
76
src/server/updates.rs
Normal file
76
src/server/updates.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
use dioxus::{
|
||||
fullstack::{WebSocketOptions, Websocket},
|
||||
prelude::*,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
use rand::random;
|
||||
#[cfg(feature = "server")]
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct UpdateEvent;
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
mod server_only {
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
ops::Deref,
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use dioxus::fullstack::TypedWebsocket;
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
|
||||
use crate::server::updates::UpdateEvent;
|
||||
|
||||
pub(super) struct SubscribedClient {
|
||||
pub(super) websocket: Mutex<TypedWebsocket<UpdateEvent, UpdateEvent>>,
|
||||
}
|
||||
|
||||
pub(super) struct SubscribedClients(RwLock<HashMap<u64, SubscribedClient>>);
|
||||
|
||||
impl Deref for SubscribedClients {
|
||||
type Target = RwLock<HashMap<u64, SubscribedClient>>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) static SUBSCRIBED_CLIENTS: LazyLock<SubscribedClients> =
|
||||
LazyLock::new(|| SubscribedClients(RwLock::new(HashMap::new())));
|
||||
|
||||
pub(crate) async fn publish_update() {
|
||||
let mut disconnected_client_ids = HashSet::new();
|
||||
let subscribed_clients = SUBSCRIBED_CLIENTS.read().await;
|
||||
for (id, client) in subscribed_clients.iter() {
|
||||
if let Err(_) = client.websocket.lock().await.send(UpdateEvent).await {
|
||||
disconnected_client_ids.insert(id.clone());
|
||||
}
|
||||
}
|
||||
drop(subscribed_clients);
|
||||
if !disconnected_client_ids.is_empty() {
|
||||
let mut subscribed_clients = SUBSCRIBED_CLIENTS.write().await;
|
||||
subscribed_clients.retain(|id, _| !disconnected_client_ids.contains(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
pub(super) use server_only::*;
|
||||
|
||||
#[get("/api/subscribe_to_updates")]
|
||||
pub(crate) async fn subscribe_to_updates(
|
||||
websocket_options: WebSocketOptions,
|
||||
) -> Result<Websocket<UpdateEvent, UpdateEvent>> {
|
||||
Ok(websocket_options.on_upgrade(move |socket| async move {
|
||||
SUBSCRIBED_CLIENTS.write().await.insert(
|
||||
random(),
|
||||
SubscribedClient {
|
||||
websocket: Mutex::new(socket),
|
||||
},
|
||||
);
|
||||
}))
|
||||
}
|
||||
14
src/views/category_calendar_page.rs
Normal file
14
src/views/category_calendar_page.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use crate::components::category_calendar_task_list::CategoryCalendarTaskList;
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryCalendarPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryCalendarTaskList {}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_done_page.rs
Normal file
17
src/views/category_done_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryDonePage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::Done,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_inbox_page.rs
Normal file
17
src/views/category_inbox_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryInboxPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::Inbox,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_long_term_page.rs
Normal file
17
src/views/category_long_term_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryLongTermPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::LongTerm,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_next_steps_page.rs
Normal file
17
src/views/category_next_steps_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryNextStepsPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::NextSteps,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/views/category_page.rs
Normal file
18
src/views/category_page.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use crate::components::task_list::TaskList;
|
||||
use crate::hooks::use_tasks_with_subtasks_in_category;
|
||||
use crate::models::category::Category;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryPage(category: Category) -> Element {
|
||||
let tasks = use_tasks_with_subtasks_in_category(category)?();
|
||||
|
||||
rsx! {
|
||||
TaskList {
|
||||
tasks: tasks.clone(),
|
||||
class: "pb-36"
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_someday_maybe_page.rs
Normal file
17
src/views/category_someday_maybe_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategorySomedayMaybePage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::SomedayMaybe,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/views/category_today_page.rs
Normal file
12
src/views/category_today_page.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use crate::components::category_today_task_list::CategoryTodayTaskList;
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryTodayPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryTodayTaskList {}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_trash_page.rs
Normal file
17
src/views/category_trash_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryTrashPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::Trash,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/views/category_waiting_for_page.rs
Normal file
17
src/views/category_waiting_for_page.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::components::error_boundary_message::ErrorBoundaryMessage;
|
||||
use crate::models::category::Category;
|
||||
use crate::views::category_page::CategoryPage;
|
||||
use dioxus::core_macro::rsx;
|
||||
use dioxus::dioxus_core::Element;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn CategoryWaitingForPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
CategoryPage {
|
||||
category: Category::WaitingFor(String::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@ use dioxus::prelude::*;
|
||||
#[component]
|
||||
pub(crate) fn NotFoundPage(route: Vec<String>) -> Element {
|
||||
rsx! {
|
||||
{"404"}
|
||||
"404"
|
||||
}
|
||||
}
|
||||
11
src/views/projects_page.rs
Normal file
11
src/views/projects_page.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use crate::components::{error_boundary_message::ErrorBoundaryMessage, project_list::ProjectList};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub(crate) fn ProjectsPage() -> Element {
|
||||
rsx! {
|
||||
ErrorBoundaryMessage {
|
||||
ProjectList {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user