style: fix the rustfmt linted files
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 5s
checkov check / checkov check (pull_request) Successful in 52s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 4s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 2s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 5s
GitLeaks check / GitLeaks check (pull_request) Successful in 6s
hadolint check / hadolint check (pull_request) Successful in 7s
htmlhint check / htmlhint check (pull_request) Successful in 9s
markdownlint check / markdownlint check (pull_request) Successful in 9s
Prettier check / Prettier check (pull_request) Successful in 10s
Rust check / Rust check (pull_request) Failing after 6m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 12s
Stylelint check / Stylelint check (pull_request) Successful in 11s
yamllint check / yamllint check (pull_request) Successful in 13s
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 5s
checkov check / checkov check (pull_request) Successful in 52s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 4s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 2s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 5s
GitLeaks check / GitLeaks check (pull_request) Successful in 6s
hadolint check / hadolint check (pull_request) Successful in 7s
htmlhint check / htmlhint check (pull_request) Successful in 9s
markdownlint check / markdownlint check (pull_request) Successful in 9s
Prettier check / Prettier check (pull_request) Successful in 10s
Rust check / Rust check (pull_request) Failing after 6m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 12s
Stylelint check / Stylelint check (pull_request) Successful in 11s
yamllint check / yamllint check (pull_request) Successful in 13s
This commit is contained in:
parent
149451cc77
commit
3646aa91c4
@ -4,7 +4,10 @@ use dioxus::dioxus_core::Element;
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryInput(selected_category: Signal<Category>, class: Option<&'static str>) -> Element {
|
pub(crate) fn CategoryInput(
|
||||||
|
selected_category: Signal<Category>,
|
||||||
|
class: Option<&'static str>,
|
||||||
|
) -> Element {
|
||||||
rsx! {
|
rsx! {
|
||||||
div {
|
div {
|
||||||
class: format!("flex flex-row gap-2 {}", class.unwrap_or("")),
|
class: format!("flex flex-row gap-2 {}", class.unwrap_or("")),
|
||||||
|
@ -4,6 +4,5 @@ use dioxus::prelude::*;
|
|||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn Home() -> Element {
|
pub(crate) fn Home() -> Element {
|
||||||
rsx! {
|
rsx! {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,9 @@ use dioxus::prelude::*;
|
|||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn Layout() -> Element {
|
pub(crate) fn Layout() -> Element {
|
||||||
let mut display_form = use_signal(|| false);
|
let mut display_form = use_signal(|| false);
|
||||||
let project_being_edited = use_context_provider::<Signal<Option<Project>>>(
|
let project_being_edited =
|
||||||
|| Signal::new(None)
|
use_context_provider::<Signal<Option<Project>>>(|| Signal::new(None));
|
||||||
);
|
let task_being_edited = use_context_provider::<Signal<Option<Task>>>(|| Signal::new(None));
|
||||||
let task_being_edited = use_context_provider::<Signal<Option<Task>>>(
|
|
||||||
|| Signal::new(None)
|
|
||||||
);
|
|
||||||
|
|
||||||
use_effect(move || {
|
use_effect(move || {
|
||||||
display_form.set(project_being_edited().is_some() || task_being_edited().is_some());
|
display_form.set(project_being_edited().is_some() || task_being_edited().is_some());
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
pub(crate) mod app;
|
pub(crate) mod app;
|
||||||
|
pub(crate) mod bottom_panel;
|
||||||
|
pub(crate) mod category_input;
|
||||||
|
pub(crate) mod form_open_button;
|
||||||
pub(crate) mod home;
|
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_form;
|
||||||
|
pub(crate) mod reoccurrence_input;
|
||||||
|
pub(crate) mod sticky_bottom;
|
||||||
|
pub(crate) mod subtasks_form;
|
||||||
pub(crate) mod task_form;
|
pub(crate) mod task_form;
|
||||||
pub(crate) mod task_list;
|
pub(crate) mod task_list;
|
||||||
pub(crate) mod pages;
|
|
||||||
pub(crate) mod navigation;
|
|
||||||
pub(crate) mod form_open_button;
|
|
||||||
pub(crate) mod bottom_panel;
|
|
||||||
pub(crate) mod sticky_bottom;
|
|
||||||
pub(crate) mod category_input;
|
|
||||||
pub(crate) mod reoccurrence_input;
|
|
||||||
pub(crate) mod layout;
|
|
||||||
pub(crate) mod navigation_item;
|
|
||||||
pub(crate) mod subtasks_form;
|
|
||||||
pub(crate) mod task_list_item;
|
pub(crate) mod task_list_item;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use dioxus::prelude::*;
|
|
||||||
use crate::route::Route;
|
use crate::route::Route;
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn NavigationItem(route: Route, children: Element) -> Element {
|
pub(crate) fn NavigationItem(route: Route, children: Element) -> Element {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryDonePage() -> Element {
|
pub(crate) fn CategoryDonePage() -> Element {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryInboxPage() -> Element {
|
pub(crate) fn CategoryInboxPage() -> Element {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryLongTermPage() -> Element {
|
pub(crate) fn CategoryLongTermPage() -> Element {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryNextStepsPage() -> Element {
|
pub(crate) fn CategoryNextStepsPage() -> Element {
|
||||||
|
@ -28,6 +28,6 @@ pub(crate) fn CategoryPage(category: Category) -> Element {
|
|||||||
"Errors occurred: {errors:?}"
|
"Errors occurred: {errors:?}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
value => panic!("Unexpected query result: {value:?}")
|
value => panic!("Unexpected query result: {value:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategorySomedayMaybePage() -> Element {
|
pub(crate) fn CategorySomedayMaybePage() -> Element {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryTrashPage() -> Element {
|
pub(crate) fn CategoryTrashPage() -> Element {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use crate::components::pages::category_page::CategoryPage;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use crate::components::pages::category_page::CategoryPage;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn CategoryWaitingForPage() -> Element {
|
pub(crate) fn CategoryWaitingForPage() -> Element {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
pub(crate) mod category_inbox_page;
|
|
||||||
pub(crate) mod category_calendar_page;
|
pub(crate) mod category_calendar_page;
|
||||||
pub(crate) mod category_today_page;
|
pub(crate) mod category_done_page;
|
||||||
pub(crate) mod category_waiting_for_page;
|
pub(crate) mod category_inbox_page;
|
||||||
pub(crate) mod category_long_term_page;
|
pub(crate) mod category_long_term_page;
|
||||||
pub(crate) mod category_next_steps_page;
|
pub(crate) mod category_next_steps_page;
|
||||||
|
pub(crate) mod category_page;
|
||||||
pub(crate) mod category_someday_maybe_page;
|
pub(crate) mod category_someday_maybe_page;
|
||||||
pub(crate) mod category_done_page;
|
pub(crate) mod category_today_page;
|
||||||
pub(crate) mod category_trash_page;
|
pub(crate) mod category_trash_page;
|
||||||
|
pub(crate) mod category_waiting_for_page;
|
||||||
pub(crate) mod not_found_page;
|
pub(crate) mod not_found_page;
|
||||||
pub(crate) mod projects_page;
|
pub(crate) mod projects_page;
|
||||||
pub(crate) mod category_page;
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use dioxus::prelude::*;
|
|
||||||
use dioxus_query::prelude::QueryResult;
|
|
||||||
use crate::models::project::Project;
|
use crate::models::project::Project;
|
||||||
use crate::query::projects::use_projects_query;
|
use crate::query::projects::use_projects_query;
|
||||||
use crate::query::QueryValue;
|
use crate::query::QueryValue;
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_query::prelude::QueryResult;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn ProjectsPage() -> Element {
|
pub(crate) fn ProjectsPage() -> Element {
|
||||||
|
@ -7,8 +7,10 @@ use dioxus::prelude::*;
|
|||||||
use dioxus_query::prelude::use_query_client;
|
use dioxus_query::prelude::use_query_client;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn ProjectForm(project: Option<Project>, on_successful_submit: EventHandler<()>)
|
pub(crate) fn ProjectForm(
|
||||||
-> Element {
|
project: Option<Project>,
|
||||||
|
on_successful_submit: EventHandler<()>,
|
||||||
|
) -> Element {
|
||||||
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||||
let project_for_submit = project.clone();
|
let project_for_submit = project.clone();
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use dioxus::prelude::*;
|
|||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn ReoccurrenceIntervalInput(
|
pub(crate) fn ReoccurrenceIntervalInput(
|
||||||
reoccurrence_interval: Signal<Option<ReoccurrenceInterval>>,
|
reoccurrence_interval: Signal<Option<ReoccurrenceInterval>>,
|
||||||
class_buttons: Option<&'static str>
|
class_buttons: Option<&'static str>,
|
||||||
) -> Element {
|
) -> Element {
|
||||||
rsx! {
|
rsx! {
|
||||||
button {
|
button {
|
||||||
|
@ -4,6 +4,7 @@ use crate::components::subtasks_form::SubtasksForm;
|
|||||||
use crate::models::category::{CalendarTime, Category, Reoccurrence};
|
use crate::models::category::{CalendarTime, Category, Reoccurrence};
|
||||||
use crate::models::task::NewTask;
|
use crate::models::task::NewTask;
|
||||||
use crate::models::task::Task;
|
use crate::models::task::Task;
|
||||||
|
use crate::query::projects::use_projects_query;
|
||||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||||
use crate::route::Route;
|
use crate::route::Route;
|
||||||
use crate::server::tasks::{create_task, delete_task, edit_task};
|
use crate::server::tasks::{create_task, delete_task, edit_task};
|
||||||
@ -13,7 +14,6 @@ use dioxus::dioxus_core::Element;
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use dioxus_i18n::t;
|
use dioxus_i18n::t;
|
||||||
use dioxus_query::prelude::{use_query_client, QueryResult};
|
use dioxus_query::prelude::{use_query_client, QueryResult};
|
||||||
use crate::query::projects::use_projects_query;
|
|
||||||
|
|
||||||
const REMINDER_OFFSETS: [Option<Duration>; 17] = [
|
const REMINDER_OFFSETS: [Option<Duration>; 17] = [
|
||||||
None,
|
None,
|
||||||
@ -40,7 +40,8 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
|||||||
let projects_query = use_projects_query();
|
let projects_query = use_projects_query();
|
||||||
|
|
||||||
let route = use_route::<Route>();
|
let route = use_route::<Route>();
|
||||||
let selected_category = use_signal(|| if let Some(task) = &task {
|
let selected_category = use_signal(|| {
|
||||||
|
if let Some(task) = &task {
|
||||||
task.category().clone()
|
task.category().clone()
|
||||||
} else {
|
} else {
|
||||||
match route {
|
match route {
|
||||||
@ -56,26 +57,41 @@ pub(crate) fn TaskForm(task: Option<Task>, on_successful_submit: EventHandler<()
|
|||||||
_ => Category::Inbox,
|
_ => Category::Inbox,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
let category_calendar_reoccurrence_interval = use_signal(|| task.as_ref().and_then(|task|
|
let category_calendar_reoccurrence_interval = use_signal(|| {
|
||||||
if let Category::Calendar { reoccurrence: Some(reoccurrence), .. } = task.category() {
|
task.as_ref().and_then(|task| {
|
||||||
|
if let Category::Calendar {
|
||||||
|
reoccurrence: Some(reoccurrence),
|
||||||
|
..
|
||||||
|
} = task.category()
|
||||||
|
{
|
||||||
Some(reoccurrence.interval().clone())
|
Some(reoccurrence.interval().clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
));
|
})
|
||||||
let mut category_calendar_has_time = use_signal(|| task.as_ref().is_some_and(
|
});
|
||||||
|task| matches!(*task.category(), Category::Calendar { time: Some(_), .. }))
|
let mut category_calendar_has_time = use_signal(|| {
|
||||||
);
|
task.as_ref().is_some_and(|task| {
|
||||||
let mut category_calendar_reminder_offset_index = use_signal(|| task.as_ref().and_then(|task|
|
matches!(*task.category(), Category::Calendar { time: Some(_), .. })
|
||||||
if let Category::Calendar { time: Some(time), .. } = task.category() {
|
})
|
||||||
REMINDER_OFFSETS.iter().position(|&reminder_offset|
|
});
|
||||||
reminder_offset == time.reminder_offset()
|
let mut category_calendar_reminder_offset_index = use_signal(|| {
|
||||||
)
|
task.as_ref()
|
||||||
|
.and_then(|task| {
|
||||||
|
if let Category::Calendar {
|
||||||
|
time: Some(time), ..
|
||||||
|
} = task.category()
|
||||||
|
{
|
||||||
|
REMINDER_OFFSETS
|
||||||
|
.iter()
|
||||||
|
.position(|&reminder_offset| reminder_offset == time.reminder_offset())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
).unwrap_or(REMINDER_OFFSETS.len() - 1));
|
})
|
||||||
|
.unwrap_or(REMINDER_OFFSETS.len() - 1)
|
||||||
|
});
|
||||||
|
|
||||||
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
let query_client = use_query_client::<QueryValue, QueryErrors, QueryKey>();
|
||||||
let task_for_submit = task.clone();
|
let task_for_submit = task.clone();
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
use crate::components::task_list_item::TaskListItem;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use crate::models::task::{Task, TaskWithSubtasks};
|
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::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use dioxus_query::prelude::use_query_client;
|
use dioxus_query::prelude::use_query_client;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use crate::components::task_list_item::TaskListItem;
|
|
||||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
|
||||||
use crate::server::tasks::complete_task;
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub(crate) fn TaskList(tasks: Vec<TaskWithSubtasks>, class: Option<&'static str>) -> Element {
|
pub(crate) fn TaskList(tasks: Vec<TaskWithSubtasks>, class: Option<&'static str>) -> Element {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use dioxus_i18n::prelude::i18n;
|
|
||||||
use crate::internationalization::LocaleFromLanguageIdentifier;
|
use crate::internationalization::LocaleFromLanguageIdentifier;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use crate::models::task::TaskWithSubtasks;
|
use crate::models::task::TaskWithSubtasks;
|
||||||
@ -6,6 +5,7 @@ use chrono::{Datelike, Local};
|
|||||||
use dioxus::core_macro::rsx;
|
use dioxus::core_macro::rsx;
|
||||||
use dioxus::dioxus_core::Element;
|
use dioxus::dioxus_core::Element;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
use dioxus_i18n::prelude::i18n;
|
||||||
use dioxus_i18n::t;
|
use dioxus_i18n::t;
|
||||||
use voca_rs::Voca;
|
use voca_rs::Voca;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::fmt::Display;
|
|
||||||
use std::str::FromStr;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_with::serde_derive::Serialize;
|
use serde_with::serde_derive::Serialize;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct ErrorVec<T> {
|
pub struct ErrorVec<T> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
pub(crate) mod error;
|
pub(crate) mod error;
|
||||||
pub(crate) mod error_vec;
|
pub(crate) mod error_vec;
|
||||||
pub(crate) mod project_error;
|
pub(crate) mod project_error;
|
||||||
pub(crate) mod task_error;
|
|
||||||
pub(crate) mod subtask_error;
|
pub(crate) mod subtask_error;
|
||||||
|
pub(crate) mod task_error;
|
||||||
|
@ -13,7 +13,8 @@ pub enum ProjectError {
|
|||||||
|
|
||||||
impl From<ValidationErrors> for ErrorVec<ProjectError> {
|
impl From<ValidationErrors> for ErrorVec<ProjectError> {
|
||||||
fn from(validation_errors: ValidationErrors) -> Self {
|
fn from(validation_errors: ValidationErrors) -> Self {
|
||||||
validation_errors.errors()
|
validation_errors
|
||||||
|
.errors()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(&field, error_kind)| match field {
|
.flat_map(|(&field, error_kind)| match field {
|
||||||
"title" => match error_kind {
|
"title" => match error_kind {
|
||||||
|
@ -14,7 +14,8 @@ pub enum SubtaskError {
|
|||||||
|
|
||||||
impl From<ValidationErrors> for ErrorVec<SubtaskError> {
|
impl From<ValidationErrors> for ErrorVec<SubtaskError> {
|
||||||
fn from(validation_errors: ValidationErrors) -> Self {
|
fn from(validation_errors: ValidationErrors) -> Self {
|
||||||
validation_errors.errors()
|
validation_errors
|
||||||
|
.errors()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(&field, error_kind)| match field {
|
.flat_map(|(&field, error_kind)| match field {
|
||||||
"title" => match error_kind {
|
"title" => match error_kind {
|
||||||
@ -39,24 +40,24 @@ impl From<diesel::result::Error> for SubtaskError {
|
|||||||
fn from(diesel_error: diesel::result::Error) -> Self {
|
fn from(diesel_error: diesel::result::Error) -> Self {
|
||||||
match diesel_error {
|
match diesel_error {
|
||||||
diesel::result::Error::DatabaseError(
|
diesel::result::Error::DatabaseError(
|
||||||
diesel::result::DatabaseErrorKind::ForeignKeyViolation, info
|
diesel::result::DatabaseErrorKind::ForeignKeyViolation,
|
||||||
) => {
|
info,
|
||||||
match info.constraint_name() {
|
) => match info.constraint_name() {
|
||||||
Some("subtasks_task_id_fkey") => Self::TaskNotFound,
|
Some("subtasks_task_id_fkey") => Self::TaskNotFound,
|
||||||
_ => Self::Error(Error::ServerInternal)
|
_ => Self::Error(Error::ServerInternal),
|
||||||
}
|
},
|
||||||
}
|
_ => Self::Error(Error::ServerInternal),
|
||||||
_ => {
|
|
||||||
Self::Error(Error::ServerInternal)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ErrorVec<Error>> for ErrorVec<SubtaskError> {
|
impl From<ErrorVec<Error>> for ErrorVec<SubtaskError> {
|
||||||
fn from(error_vec: ErrorVec<Error>) -> Self {
|
fn from(error_vec: ErrorVec<Error>) -> Self {
|
||||||
Vec::from(error_vec).into_iter()
|
Vec::from(error_vec)
|
||||||
.map(SubtaskError::Error).collect::<Vec<SubtaskError>>().into()
|
.into_iter()
|
||||||
|
.map(SubtaskError::Error)
|
||||||
|
.collect::<Vec<SubtaskError>>()
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ pub enum TaskError {
|
|||||||
|
|
||||||
impl From<ValidationErrors> for ErrorVec<TaskError> {
|
impl From<ValidationErrors> for ErrorVec<TaskError> {
|
||||||
fn from(validation_errors: ValidationErrors) -> Self {
|
fn from(validation_errors: ValidationErrors) -> Self {
|
||||||
validation_errors.errors()
|
validation_errors
|
||||||
|
.errors()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(&field, error_kind)| match field {
|
.flat_map(|(&field, error_kind)| match field {
|
||||||
"title" => match error_kind {
|
"title" => match error_kind {
|
||||||
@ -39,16 +40,13 @@ impl From<diesel::result::Error> for TaskError {
|
|||||||
fn from(diesel_error: diesel::result::Error) -> Self {
|
fn from(diesel_error: diesel::result::Error) -> Self {
|
||||||
match diesel_error {
|
match diesel_error {
|
||||||
diesel::result::Error::DatabaseError(
|
diesel::result::Error::DatabaseError(
|
||||||
diesel::result::DatabaseErrorKind::ForeignKeyViolation, info
|
diesel::result::DatabaseErrorKind::ForeignKeyViolation,
|
||||||
) => {
|
info,
|
||||||
match info.constraint_name() {
|
) => match info.constraint_name() {
|
||||||
Some("tasks_project_id_fkey") => Self::ProjectNotFound,
|
Some("tasks_project_id_fkey") => Self::ProjectNotFound,
|
||||||
_ => Self::Error(Error::ServerInternal)
|
_ => Self::Error(Error::ServerInternal),
|
||||||
}
|
},
|
||||||
}
|
_ => Self::Error(Error::ServerInternal),
|
||||||
_ => {
|
|
||||||
Self::Error(Error::ServerInternal)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::ops::Deref;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
use chrono::Locale;
|
use chrono::Locale;
|
||||||
use dioxus::fullstack::once_cell::sync::Lazy;
|
use dioxus::fullstack::once_cell::sync::Lazy;
|
||||||
use feruca::Collator;
|
use feruca::Collator;
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::sync::Mutex;
|
||||||
use unic_langid_impl::LanguageIdentifier;
|
use unic_langid_impl::LanguageIdentifier;
|
||||||
|
|
||||||
pub(crate) static COLLATOR: Lazy<Mutex<Collator>> = Lazy::new(|| Mutex::new(Collator::default()));
|
pub(crate) static COLLATOR: Lazy<Mutex<Collator>> = Lazy::new(|| Mutex::new(Collator::default()));
|
||||||
@ -19,7 +19,11 @@ impl<'a> Deref for LocaleFromLanguageIdentifier<'a> {
|
|||||||
|
|
||||||
impl<'a> From<LocaleFromLanguageIdentifier<'a>> for Locale {
|
impl<'a> From<LocaleFromLanguageIdentifier<'a>> for Locale {
|
||||||
fn from(language_identifier: LocaleFromLanguageIdentifier) -> Self {
|
fn from(language_identifier: LocaleFromLanguageIdentifier) -> Self {
|
||||||
language_identifier.to_string().replace("-", "_").parse().unwrap()
|
language_identifier
|
||||||
|
.to_string()
|
||||||
|
.replace("-", "_")
|
||||||
|
.parse()
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
mod components;
|
mod components;
|
||||||
mod errors;
|
mod errors;
|
||||||
|
mod internationalization;
|
||||||
|
mod migrations;
|
||||||
mod models;
|
mod models;
|
||||||
|
mod query;
|
||||||
mod route;
|
mod route;
|
||||||
mod schema;
|
mod schema;
|
||||||
mod server;
|
mod server;
|
||||||
mod query;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
mod internationalization;
|
|
||||||
mod migrations;
|
|
||||||
|
|
||||||
use components::app::App;
|
use components::app::App;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use std::hash::Hash;
|
|
||||||
use crate::schema::tasks;
|
use crate::schema::tasks;
|
||||||
use chrono::{Duration, NaiveDate, NaiveTime};
|
use chrono::{Duration, NaiveDate, NaiveTime};
|
||||||
use diesel::deserialize::FromSql;
|
use diesel::deserialize::FromSql;
|
||||||
@ -9,6 +8,7 @@ use diesel::{AsExpression, BoxableExpression, FromSqlRow, PgJsonbExpressionMetho
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use serde_with::DurationSeconds;
|
use serde_with::DurationSeconds;
|
||||||
|
use std::hash::Hash;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
#[serde_with::serde_as]
|
#[serde_with::serde_as]
|
||||||
@ -99,7 +99,11 @@ pub struct Reoccurrence {
|
|||||||
|
|
||||||
impl Reoccurrence {
|
impl Reoccurrence {
|
||||||
pub fn new(start_date: NaiveDate, interval: ReoccurrenceInterval, length: u32) -> Self {
|
pub fn new(start_date: NaiveDate, interval: ReoccurrenceInterval, length: u32) -> Self {
|
||||||
Self { start_date, interval, length }
|
Self {
|
||||||
|
start_date,
|
||||||
|
interval,
|
||||||
|
length,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_date(&self) -> NaiveDate {
|
pub fn start_date(&self) -> NaiveDate {
|
||||||
@ -125,7 +129,10 @@ pub struct CalendarTime {
|
|||||||
|
|
||||||
impl CalendarTime {
|
impl CalendarTime {
|
||||||
pub fn new(time: NaiveTime, reminder_offset: Option<Duration>) -> Self {
|
pub fn new(time: NaiveTime, reminder_offset: Option<Duration>) -> Self {
|
||||||
Self { time, reminder_offset }
|
Self {
|
||||||
|
time,
|
||||||
|
reminder_offset,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn time(&self) -> NaiveTime {
|
pub fn time(&self) -> NaiveTime {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub(crate) mod project;
|
|
||||||
pub(crate) mod category;
|
pub(crate) mod category;
|
||||||
pub(crate) mod task;
|
pub(crate) mod project;
|
||||||
pub(crate) mod subtask;
|
pub(crate) mod subtask;
|
||||||
|
pub(crate) mod task;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use std::cmp::Ordering;
|
use crate::internationalization::COLLATOR;
|
||||||
use chrono::NaiveDateTime;
|
|
||||||
use crate::schema::projects;
|
use crate::schema::projects;
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
use crate::internationalization::COLLATOR;
|
|
||||||
|
|
||||||
const TITLE_LENGTH_MIN: u64 = 1;
|
const TITLE_LENGTH_MIN: u64 = 1;
|
||||||
const TITLE_LENGTH_MAX: u64 = 255;
|
const TITLE_LENGTH_MAX: u64 = 255;
|
||||||
@ -47,14 +47,21 @@ impl PartialOrd<Self> for Project {
|
|||||||
|
|
||||||
impl Ord for Project {
|
impl Ord for Project {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
COLLATOR.lock().unwrap().collate(self.title(), other.title())
|
COLLATOR
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.collate(self.title(), other.title())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
||||||
#[diesel(table_name = projects)]
|
#[diesel(table_name = projects)]
|
||||||
pub struct NewProject {
|
pub struct NewProject {
|
||||||
#[validate(length(min = "TITLE_LENGTH_MIN", max = "TITLE_LENGTH_MAX", code = "title_length"))]
|
#[validate(length(
|
||||||
|
min = "TITLE_LENGTH_MIN",
|
||||||
|
max = "TITLE_LENGTH_MAX",
|
||||||
|
code = "title_length"
|
||||||
|
))]
|
||||||
pub title: String,
|
pub title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
use std::cmp::Ordering;
|
|
||||||
use crate::models::task::Task;
|
use crate::models::task::Task;
|
||||||
use crate::schema::subtasks;
|
use crate::schema::subtasks;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
const TITLE_LENGTH_MIN: u64 = 1;
|
const TITLE_LENGTH_MIN: u64 = 1;
|
||||||
const TITLE_LENGTH_MAX: u64 = 255;
|
const TITLE_LENGTH_MAX: u64 = 255;
|
||||||
|
|
||||||
#[derive(Queryable, Selectable, Identifiable, Associations, Serialize, Deserialize, PartialEq,
|
#[derive(
|
||||||
Clone, Debug)]
|
Queryable,
|
||||||
|
Selectable,
|
||||||
|
Identifiable,
|
||||||
|
Associations,
|
||||||
|
Serialize,
|
||||||
|
Deserialize,
|
||||||
|
PartialEq,
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
)]
|
||||||
#[diesel(belongs_to(Task, foreign_key = task_id))]
|
#[diesel(belongs_to(Task, foreign_key = task_id))]
|
||||||
#[diesel(table_name = subtasks)]
|
#[diesel(table_name = subtasks)]
|
||||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
#[diesel(check_for_backend(diesel::pg::Pg))]
|
||||||
@ -59,7 +68,8 @@ impl PartialOrd<Self> for Subtask {
|
|||||||
|
|
||||||
impl Ord for Subtask {
|
impl Ord for Subtask {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
self.is_completed().cmp(&other.is_completed())
|
self.is_completed()
|
||||||
|
.cmp(&other.is_completed())
|
||||||
.then(self.created_at().cmp(&other.created_at()))
|
.then(self.created_at().cmp(&other.created_at()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,14 +78,22 @@ impl Ord for Subtask {
|
|||||||
#[diesel(table_name = subtasks)]
|
#[diesel(table_name = subtasks)]
|
||||||
pub struct NewSubtask {
|
pub struct NewSubtask {
|
||||||
pub task_id: i32,
|
pub task_id: i32,
|
||||||
#[validate(length(min = "TITLE_LENGTH_MIN", max = "TITLE_LENGTH_MAX", code = "title_length"))]
|
#[validate(length(
|
||||||
|
min = "TITLE_LENGTH_MIN",
|
||||||
|
max = "TITLE_LENGTH_MAX",
|
||||||
|
code = "title_length"
|
||||||
|
))]
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub is_completed: bool,
|
pub is_completed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewSubtask {
|
impl NewSubtask {
|
||||||
pub fn new(task_id: i32, title: String, is_completed: bool) -> Self {
|
pub fn new(task_id: i32, title: String, is_completed: bool) -> Self {
|
||||||
Self { task_id, title, is_completed }
|
Self {
|
||||||
|
task_id,
|
||||||
|
title,
|
||||||
|
is_completed,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,23 +67,39 @@ impl Ord for Task {
|
|||||||
match (&self.category, &other.category) {
|
match (&self.category, &other.category) {
|
||||||
(Category::Inbox, Category::Inbox) => self.created_at.cmp(&other.created_at),
|
(Category::Inbox, Category::Inbox) => self.created_at.cmp(&other.created_at),
|
||||||
(
|
(
|
||||||
Category::Calendar { date: self_date, time: self_time, .. },
|
Category::Calendar {
|
||||||
Category::Calendar { date: other_date, time: other_time, .. }
|
date: self_date,
|
||||||
) => self_date.cmp(other_date)
|
time: self_time,
|
||||||
.then(ReverseOrdOption::from(
|
..
|
||||||
&self_time.as_ref().map(|calendar_time| calendar_time.time())
|
},
|
||||||
).cmp(&ReverseOrdOption::from(
|
Category::Calendar {
|
||||||
&other_time.as_ref().map(|calendar_time| calendar_time.time())
|
date: other_date,
|
||||||
)))
|
time: other_time,
|
||||||
.then(ReverseOrdOption::from(&self.deadline()).cmp(
|
..
|
||||||
&ReverseOrdOption::from(&other.deadline())
|
},
|
||||||
))
|
) => self_date
|
||||||
|
.cmp(other_date)
|
||||||
|
.then(
|
||||||
|
ReverseOrdOption::from(
|
||||||
|
&self_time.as_ref().map(|calendar_time| calendar_time.time()),
|
||||||
|
)
|
||||||
|
.cmp(&ReverseOrdOption::from(
|
||||||
|
&other_time
|
||||||
|
.as_ref()
|
||||||
|
.map(|calendar_time| calendar_time.time()),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
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()))
|
||||||
.then(self.created_at.cmp(&other.created_at)),
|
.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())
|
|
||||||
).then(self.created_at.cmp(&other.created_at)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +141,11 @@ impl Ord for TaskWithSubtasks {
|
|||||||
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
||||||
#[diesel(table_name = tasks)]
|
#[diesel(table_name = tasks)]
|
||||||
pub struct NewTask {
|
pub struct NewTask {
|
||||||
#[validate(length(min = "TITLE_LENGTH_MIN", max = "TITLE_LENGTH_MAX", code = "title_length"))]
|
#[validate(length(
|
||||||
|
min = "TITLE_LENGTH_MIN",
|
||||||
|
max = "TITLE_LENGTH_MAX",
|
||||||
|
code = "title_length"
|
||||||
|
))]
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub deadline: Option<chrono::NaiveDate>,
|
pub deadline: Option<chrono::NaiveDate>,
|
||||||
pub category: Category,
|
pub category: Category,
|
||||||
@ -139,7 +159,12 @@ impl NewTask {
|
|||||||
category: Category,
|
category: Category,
|
||||||
project_id: Option<i32>,
|
project_id: Option<i32>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { title, deadline, category, project_id }
|
Self {
|
||||||
|
title,
|
||||||
|
deadline,
|
||||||
|
category,
|
||||||
|
project_id,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ use crate::models::project::Project;
|
|||||||
use crate::models::subtask::Subtask;
|
use crate::models::subtask::Subtask;
|
||||||
use crate::models::task::{Task, TaskWithSubtasks};
|
use crate::models::task::{Task, TaskWithSubtasks};
|
||||||
|
|
||||||
pub(crate) mod tasks;
|
|
||||||
pub(crate) mod projects;
|
pub(crate) mod projects;
|
||||||
pub(crate) mod subtasks;
|
pub(crate) mod subtasks;
|
||||||
|
pub(crate) mod tasks;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub(crate) enum QueryValue {
|
pub(crate) enum QueryValue {
|
||||||
|
@ -12,8 +12,9 @@ async fn fetch_projects(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErr
|
|||||||
match get_projects().await {
|
match get_projects().await {
|
||||||
Ok(projects) => Ok(QueryValue::Projects(projects)),
|
Ok(projects) => Ok(QueryValue::Projects(projects)),
|
||||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||||
Err(error) => panic!("Unexpected error: {:?}", error)
|
Err(error) => panic!("Unexpected error: {:?}", error),
|
||||||
}.into()
|
}
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
panic!("Unexpected query keys: {:?}", keys);
|
panic!("Unexpected query keys: {:?}", keys);
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,13 @@ use crate::server::subtasks::get_subtasks_of_task;
|
|||||||
use dioxus::prelude::ServerFnError;
|
use dioxus::prelude::ServerFnError;
|
||||||
use dioxus_query::prelude::{use_get_query, QueryResult, UseQuery};
|
use dioxus_query::prelude::{use_get_query, QueryResult, UseQuery};
|
||||||
|
|
||||||
pub(crate) fn use_subtasks_of_task_query(task_id: i32)
|
pub(crate) fn use_subtasks_of_task_query(
|
||||||
-> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
task_id: i32,
|
||||||
use_get_query([QueryKey::SubtasksOfTaskId(task_id)], fetch_subtasks_of_task)
|
) -> 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> {
|
async fn fetch_subtasks_of_task(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
||||||
@ -13,8 +17,9 @@ async fn fetch_subtasks_of_task(keys: Vec<QueryKey>) -> QueryResult<QueryValue,
|
|||||||
match get_subtasks_of_task(*task_id).await {
|
match get_subtasks_of_task(*task_id).await {
|
||||||
Ok(subtasks) => Ok(QueryValue::Subtasks(subtasks)),
|
Ok(subtasks) => Ok(QueryValue::Subtasks(subtasks)),
|
||||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||||
Err(error) => panic!("Unexpected error: {:?}", error)
|
Err(error) => panic!("Unexpected error: {:?}", error),
|
||||||
}.into()
|
}
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
panic!("Unexpected query keys: {:?}", keys);
|
panic!("Unexpected query keys: {:?}", keys);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
use dioxus::prelude::ServerFnError;
|
|
||||||
use dioxus_query::prelude::{use_get_query, QueryResult, UseQuery};
|
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
use crate::query::{QueryErrors, QueryKey, QueryValue};
|
||||||
use crate::server::tasks::{get_tasks_in_category, get_tasks_with_subtasks_in_category};
|
use crate::server::tasks::{get_tasks_in_category, get_tasks_with_subtasks_in_category};
|
||||||
|
use dioxus::prelude::ServerFnError;
|
||||||
|
use dioxus_query::prelude::{use_get_query, QueryResult, UseQuery};
|
||||||
|
|
||||||
|
pub(crate) fn use_tasks_in_category_query(
|
||||||
|
category: Category,
|
||||||
pub(crate) fn use_tasks_in_category_query(category: Category)
|
) -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||||
-> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
use_get_query(
|
||||||
use_get_query([QueryKey::TasksInCategory(category), QueryKey::Tasks], fetch_tasks_in_category)
|
[QueryKey::TasksInCategory(category), QueryKey::Tasks],
|
||||||
|
fetch_tasks_in_category,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_tasks_in_category(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
async fn fetch_tasks_in_category(keys: Vec<QueryKey>) -> QueryResult<QueryValue, QueryErrors> {
|
||||||
@ -16,34 +18,37 @@ async fn fetch_tasks_in_category(keys: Vec<QueryKey>) -> QueryResult<QueryValue,
|
|||||||
match get_tasks_in_category(category.clone()).await {
|
match get_tasks_in_category(category.clone()).await {
|
||||||
Ok(tasks) => Ok(QueryValue::Tasks(tasks)),
|
Ok(tasks) => Ok(QueryValue::Tasks(tasks)),
|
||||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||||
Err(error) => panic!("Unexpected error: {:?}", error)
|
Err(error) => panic!("Unexpected error: {:?}", error),
|
||||||
}.into()
|
}
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
panic!("Unexpected query keys: {:?}", keys);
|
panic!("Unexpected query keys: {:?}", keys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn use_tasks_with_subtasks_in_category_query(category: Category)
|
pub(crate) fn use_tasks_with_subtasks_in_category_query(
|
||||||
-> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
category: Category,
|
||||||
|
) -> UseQuery<QueryValue, QueryErrors, QueryKey> {
|
||||||
use_get_query(
|
use_get_query(
|
||||||
[
|
[
|
||||||
QueryKey::TasksWithSubtasksInCategory(
|
QueryKey::TasksWithSubtasksInCategory(category.clone()),
|
||||||
category.clone()),
|
|
||||||
QueryKey::TasksInCategory(category),
|
QueryKey::TasksInCategory(category),
|
||||||
QueryKey::Tasks
|
QueryKey::Tasks,
|
||||||
],
|
],
|
||||||
fetch_tasks_with_subtasks_in_category
|
fetch_tasks_with_subtasks_in_category,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_tasks_with_subtasks_in_category(keys: Vec<QueryKey>)
|
async fn fetch_tasks_with_subtasks_in_category(
|
||||||
-> QueryResult<QueryValue, QueryErrors> {
|
keys: Vec<QueryKey>,
|
||||||
|
) -> QueryResult<QueryValue, QueryErrors> {
|
||||||
if let Some(QueryKey::TasksWithSubtasksInCategory(category)) = keys.first() {
|
if let Some(QueryKey::TasksWithSubtasksInCategory(category)) = keys.first() {
|
||||||
match get_tasks_with_subtasks_in_category(category.clone()).await {
|
match get_tasks_with_subtasks_in_category(category.clone()).await {
|
||||||
Ok(tasks) => Ok(QueryValue::TasksWithSubtasks(tasks)),
|
Ok(tasks) => Ok(QueryValue::TasksWithSubtasks(tasks)),
|
||||||
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
Err(ServerFnError::WrappedServerError(errors)) => Err(QueryErrors::Error(errors)),
|
||||||
Err(error) => panic!("Unexpected error: {:?}", error)
|
Err(error) => panic!("Unexpected error: {:?}", error),
|
||||||
}.into()
|
}
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
panic!("Unexpected query keys: {:?}", keys);
|
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_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_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_today_page::CategoryTodayPage;
|
||||||
use crate::components::pages::category_trash_page::CategoryTrashPage;
|
use crate::components::pages::category_trash_page::CategoryTrashPage;
|
||||||
use crate::components::pages::category_waiting_for_page::CategoryWaitingForPage;
|
use crate::components::pages::category_waiting_for_page::CategoryWaitingForPage;
|
||||||
use crate::components::pages::category_someday_maybe_page::CategorySomedayMaybePage;
|
|
||||||
use crate::components::pages::category_done_page::CategoryDonePage;
|
|
||||||
use crate::components::pages::category_calendar_page::CategoryCalendarPage;
|
|
||||||
use crate::components::pages::category_long_term_page::CategoryLongTermPage;
|
|
||||||
use crate::components::pages::projects_page::ProjectsPage;
|
|
||||||
use crate::components::pages::not_found_page::NotFoundPage;
|
use crate::components::pages::not_found_page::NotFoundPage;
|
||||||
use crate::components::layout::Layout;
|
use crate::components::pages::projects_page::ProjectsPage;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
// All variants have the same postfix because they have to match the component names.
|
// All variants have the same postfix because they have to match the component names.
|
||||||
|
@ -35,8 +35,4 @@ diesel::table! {
|
|||||||
diesel::joinable!(subtasks -> tasks (task_id));
|
diesel::joinable!(subtasks -> tasks (task_id));
|
||||||
diesel::joinable!(tasks -> projects (project_id));
|
diesel::joinable!(tasks -> projects (project_id));
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
diesel::allow_tables_to_appear_in_same_query!(projects, subtasks, tasks,);
|
||||||
projects,
|
|
||||||
subtasks,
|
|
||||||
tasks,
|
|
||||||
);
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::env;
|
|
||||||
use dioxus::prelude::ServerFnError;
|
use dioxus::prelude::ServerFnError;
|
||||||
use unic_langid_impl::LanguageIdentifier;
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
|
use std::env;
|
||||||
|
use unic_langid_impl::LanguageIdentifier;
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn get_language_identifier() -> Result<LanguageIdentifier, ServerFnError> {
|
pub(crate) async fn get_language_identifier() -> Result<LanguageIdentifier, ServerFnError> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
pub(crate) mod database_connection;
|
pub(crate) mod database_connection;
|
||||||
pub(crate) mod projects;
|
|
||||||
pub(crate) mod tasks;
|
|
||||||
pub(crate) mod subtasks;
|
|
||||||
pub(crate) mod internationalization;
|
pub(crate) mod internationalization;
|
||||||
|
pub(crate) mod projects;
|
||||||
|
pub(crate) mod subtasks;
|
||||||
|
pub(crate) mod tasks;
|
||||||
|
@ -8,21 +8,23 @@ use dioxus::prelude::*;
|
|||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn create_project(new_project: NewProject)
|
pub(crate) async fn create_project(
|
||||||
-> Result<Project, ServerFnError<ErrorVec<ProjectError>>> {
|
new_project: NewProject,
|
||||||
|
) -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> {
|
||||||
use crate::schema::projects;
|
use crate::schema::projects;
|
||||||
|
|
||||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||||
let mut new_project = new_project;
|
let mut new_project = new_project;
|
||||||
new_project.title = new_project.title.trim().to_owned();
|
new_project.title = new_project.title.trim().to_owned();
|
||||||
|
|
||||||
new_project.validate()
|
new_project
|
||||||
|
.validate()
|
||||||
.map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?;
|
.map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection =
|
||||||
.map_err::<ErrorVec<ProjectError>, _>(
|
establish_database_connection().map_err::<ErrorVec<ProjectError>, _>(|_| {
|
||||||
|_| vec![ProjectError::Error(Error::ServerInternal)].into()
|
vec![ProjectError::Error(Error::ServerInternal)].into()
|
||||||
)?;
|
})?;
|
||||||
|
|
||||||
let new_project = diesel::insert_into(projects::table)
|
let new_project = diesel::insert_into(projects::table)
|
||||||
.values(&new_project)
|
.values(&new_project)
|
||||||
@ -34,41 +36,39 @@ pub(crate) async fn create_project(new_project: NewProject)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn get_projects()
|
pub(crate) async fn get_projects() -> Result<Vec<Project>, ServerFnError<ErrorVec<Error>>> {
|
||||||
-> Result<Vec<Project>, ServerFnError<ErrorVec<Error>>> {
|
|
||||||
use crate::schema::projects::dsl::*;
|
use crate::schema::projects::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
.map_err::<ErrorVec<Error>, _>(
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|_| vec![Error::ServerInternal].into()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let results = projects
|
let results = projects
|
||||||
.select(Project::as_select())
|
.select(Project::as_select())
|
||||||
.load::<Project>(&mut connection)
|
.load::<Project>(&mut connection)
|
||||||
.map_err::<ErrorVec<Error>, _>(
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|_| vec![Error::ServerInternal].into()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn edit_project(project_id: i32, new_project: NewProject)
|
pub(crate) async fn edit_project(
|
||||||
-> Result<Project, ServerFnError<ErrorVec<ProjectError>>> {
|
project_id: i32,
|
||||||
|
new_project: NewProject,
|
||||||
|
) -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> {
|
||||||
use crate::schema::projects::dsl::*;
|
use crate::schema::projects::dsl::*;
|
||||||
|
|
||||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||||
let mut new_project = new_project;
|
let mut new_project = new_project;
|
||||||
new_project.title = new_project.title.trim().to_owned();
|
new_project.title = new_project.title.trim().to_owned();
|
||||||
|
|
||||||
new_project.validate()
|
new_project
|
||||||
|
.validate()
|
||||||
.map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?;
|
.map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection =
|
||||||
.map_err::<ErrorVec<ProjectError>, _>(
|
establish_database_connection().map_err::<ErrorVec<ProjectError>, _>(|_| {
|
||||||
|_| vec![ProjectError::Error(Error::ServerInternal)].into()
|
vec![ProjectError::Error(Error::ServerInternal)].into()
|
||||||
)?;
|
})?;
|
||||||
|
|
||||||
let updated_project = diesel::update(projects)
|
let updated_project = diesel::update(projects)
|
||||||
.filter(id.eq(project_id))
|
.filter(id.eq(project_id))
|
||||||
@ -83,15 +83,14 @@ pub(crate) async fn edit_project(project_id: i32, new_project: NewProject)
|
|||||||
// TODO: Get rid of this suppression.
|
// TODO: Get rid of this suppression.
|
||||||
//noinspection DuplicatedCode
|
//noinspection DuplicatedCode
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn delete_project(project_id: i32)
|
pub(crate) async fn delete_project(project_id: i32) -> Result<(), ServerFnError<ErrorVec<Error>>> {
|
||||||
-> Result<(), ServerFnError<ErrorVec<Error>>> {
|
|
||||||
use crate::schema::projects::dsl::*;
|
use crate::schema::projects::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|
|
||||||
|
diesel::delete(projects.filter(id.eq(project_id)))
|
||||||
diesel::delete(projects.filter(id.eq(project_id))).execute(&mut connection)
|
.execute(&mut connection)
|
||||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -3,27 +3,29 @@ use crate::errors::error_vec::ErrorVec;
|
|||||||
use crate::errors::subtask_error::SubtaskError;
|
use crate::errors::subtask_error::SubtaskError;
|
||||||
use crate::models::subtask::{NewSubtask, Subtask};
|
use crate::models::subtask::{NewSubtask, Subtask};
|
||||||
use crate::server::database_connection::establish_database_connection;
|
use crate::server::database_connection::establish_database_connection;
|
||||||
|
use crate::server::tasks::trigger_task_updated_at;
|
||||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl, SelectableHelper};
|
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl, SelectableHelper};
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
use crate::server::tasks::trigger_task_updated_at;
|
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn create_subtask(new_subtask: NewSubtask)
|
pub(crate) async fn create_subtask(
|
||||||
-> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> {
|
new_subtask: NewSubtask,
|
||||||
|
) -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> {
|
||||||
use crate::schema::subtasks;
|
use crate::schema::subtasks;
|
||||||
|
|
||||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||||
let mut new_subtask = new_subtask;
|
let mut new_subtask = new_subtask;
|
||||||
new_subtask.title = new_subtask.title.trim().to_owned();
|
new_subtask.title = new_subtask.title.trim().to_owned();
|
||||||
|
|
||||||
new_subtask.validate()
|
new_subtask
|
||||||
|
.validate()
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?;
|
.map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection =
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(
|
establish_database_connection().map_err::<ErrorVec<SubtaskError>, _>(|_| {
|
||||||
|_| vec![SubtaskError::Error(Error::ServerInternal)].into()
|
vec![SubtaskError::Error(Error::ServerInternal)].into()
|
||||||
)?;
|
})?;
|
||||||
|
|
||||||
let created_subtask = diesel::insert_into(subtasks::table)
|
let created_subtask = diesel::insert_into(subtasks::table)
|
||||||
.values(&new_subtask)
|
.values(&new_subtask)
|
||||||
@ -31,15 +33,17 @@ pub(crate) async fn create_subtask(new_subtask: NewSubtask)
|
|||||||
.get_result(&mut connection)
|
.get_result(&mut connection)
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(|error| vec![error.into()].into())?;
|
.map_err::<ErrorVec<SubtaskError>, _>(|error| vec![error.into()].into())?;
|
||||||
|
|
||||||
trigger_task_updated_at(new_subtask.task_id).await
|
trigger_task_updated_at(new_subtask.task_id)
|
||||||
|
.await
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(|error_vec| error_vec.into())?;
|
.map_err::<ErrorVec<SubtaskError>, _>(|error_vec| error_vec.into())?;
|
||||||
|
|
||||||
Ok(created_subtask)
|
Ok(created_subtask)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn get_subtasks_of_task(filtered_task_id: i32)
|
pub(crate) async fn get_subtasks_of_task(
|
||||||
-> Result<Vec<Subtask>, ServerFnError<ErrorVec<Error>>> {
|
filtered_task_id: i32,
|
||||||
|
) -> Result<Vec<Subtask>, ServerFnError<ErrorVec<Error>>> {
|
||||||
use crate::schema::subtasks::dsl::*;
|
use crate::schema::subtasks::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
@ -55,43 +59,46 @@ pub(crate) async fn get_subtasks_of_task(filtered_task_id: i32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn edit_subtask(subtask_id: i32, new_subtask: NewSubtask)
|
pub(crate) async fn edit_subtask(
|
||||||
-> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> {
|
subtask_id: i32,
|
||||||
|
new_subtask: NewSubtask,
|
||||||
|
) -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> {
|
||||||
use crate::schema::subtasks::dsl::*;
|
use crate::schema::subtasks::dsl::*;
|
||||||
|
|
||||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||||
let mut new_subtask = new_subtask;
|
let mut new_subtask = new_subtask;
|
||||||
new_subtask.title = new_subtask.title.trim().to_owned();
|
new_subtask.title = new_subtask.title.trim().to_owned();
|
||||||
|
|
||||||
new_subtask.validate()
|
new_subtask
|
||||||
|
.validate()
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?;
|
.map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection =
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(
|
establish_database_connection().map_err::<ErrorVec<SubtaskError>, _>(|_| {
|
||||||
|_| vec![SubtaskError::Error(Error::ServerInternal)].into()
|
vec![SubtaskError::Error(Error::ServerInternal)].into()
|
||||||
)?;
|
})?;
|
||||||
|
|
||||||
let updated_task = diesel::update(subtasks)
|
let updated_task = diesel::update(subtasks)
|
||||||
.filter(id.eq(subtask_id))
|
.filter(id.eq(subtask_id))
|
||||||
.set((
|
.set((
|
||||||
title.eq(new_subtask.title),
|
title.eq(new_subtask.title),
|
||||||
is_completed.eq(new_subtask.is_completed)
|
is_completed.eq(new_subtask.is_completed),
|
||||||
))
|
))
|
||||||
.returning(Subtask::as_returning())
|
.returning(Subtask::as_returning())
|
||||||
.get_result(&mut connection)
|
.get_result(&mut connection)
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(|error| vec![error.into()].into())?;
|
.map_err::<ErrorVec<SubtaskError>, _>(|error| vec![error.into()].into())?;
|
||||||
|
|
||||||
trigger_task_updated_at(new_subtask.task_id).await
|
trigger_task_updated_at(new_subtask.task_id)
|
||||||
|
.await
|
||||||
.map_err::<ErrorVec<SubtaskError>, _>(|error_vec| error_vec.into())?;
|
.map_err::<ErrorVec<SubtaskError>, _>(|error_vec| error_vec.into())?;
|
||||||
|
|
||||||
Ok(updated_task)
|
Ok(updated_task)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn restore_subtasks_of_task(filtered_task_id: i32) -> Result<
|
pub(crate) async fn restore_subtasks_of_task(
|
||||||
Vec<Subtask>,
|
filtered_task_id: i32,
|
||||||
ServerFnError<ErrorVec<Error>>
|
) -> Result<Vec<Subtask>, ServerFnError<ErrorVec<Error>>> {
|
||||||
> {
|
|
||||||
use crate::schema::subtasks::dsl::*;
|
use crate::schema::subtasks::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
@ -110,8 +117,7 @@ pub(crate) async fn restore_subtasks_of_task(filtered_task_id: i32) -> Result<
|
|||||||
// TODO: Get rid of this suppression.
|
// TODO: Get rid of this suppression.
|
||||||
//noinspection DuplicatedCode
|
//noinspection DuplicatedCode
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn delete_subtask(subtask_id: i32)
|
pub(crate) async fn delete_subtask(subtask_id: i32) -> Result<(), ServerFnError<ErrorVec<Error>>> {
|
||||||
-> Result<(), ServerFnError<ErrorVec<Error>>> {
|
|
||||||
use crate::schema::subtasks::dsl::*;
|
use crate::schema::subtasks::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
|
@ -1,34 +1,36 @@
|
|||||||
use chrono::{Datelike, Days, Local, Months, NaiveDate};
|
|
||||||
use crate::errors::error::Error;
|
use crate::errors::error::Error;
|
||||||
use crate::errors::error_vec::ErrorVec;
|
use crate::errors::error_vec::ErrorVec;
|
||||||
use crate::models::task::{NewTask, Task, TaskWithSubtasks};
|
|
||||||
use crate::server::database_connection::establish_database_connection;
|
|
||||||
use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl, SelectableHelper};
|
|
||||||
use dioxus::prelude::*;
|
|
||||||
use diesel::prelude::*;
|
|
||||||
use time::util::days_in_year_month;
|
|
||||||
use validator::Validate;
|
|
||||||
use crate::errors::task_error::TaskError;
|
use crate::errors::task_error::TaskError;
|
||||||
use crate::models::category::{Category, ReoccurrenceInterval};
|
use crate::models::category::{Category, ReoccurrenceInterval};
|
||||||
use crate::models::subtask::Subtask;
|
use crate::models::subtask::Subtask;
|
||||||
|
use crate::models::task::{NewTask, Task, TaskWithSubtasks};
|
||||||
|
use crate::server::database_connection::establish_database_connection;
|
||||||
use crate::server::subtasks::restore_subtasks_of_task;
|
use crate::server::subtasks::restore_subtasks_of_task;
|
||||||
|
use chrono::{Datelike, Days, Local, Months, NaiveDate};
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl, SelectableHelper};
|
||||||
|
use dioxus::prelude::*;
|
||||||
|
use time::util::days_in_year_month;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn create_task(new_task: NewTask)
|
pub(crate) async fn create_task(
|
||||||
-> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
|
new_task: NewTask,
|
||||||
|
) -> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
|
||||||
use crate::schema::tasks;
|
use crate::schema::tasks;
|
||||||
|
|
||||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||||
let mut new_task = new_task;
|
let mut new_task = new_task;
|
||||||
new_task.title = new_task.title.trim().to_owned();
|
new_task.title = new_task.title.trim().to_owned();
|
||||||
|
|
||||||
new_task.validate()
|
new_task
|
||||||
|
.validate()
|
||||||
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
|
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection =
|
||||||
.map_err::<ErrorVec<TaskError>, _>(
|
establish_database_connection().map_err::<ErrorVec<TaskError>, _>(|_| {
|
||||||
|_| vec![TaskError::Error(Error::ServerInternal)].into()
|
vec![TaskError::Error(Error::ServerInternal)].into()
|
||||||
)?;
|
})?;
|
||||||
|
|
||||||
let new_task = diesel::insert_into(tasks::table)
|
let new_task = diesel::insert_into(tasks::table)
|
||||||
.values(&new_task)
|
.values(&new_task)
|
||||||
@ -58,31 +60,27 @@ pub(crate) async fn get_task(task_id: i32) -> Result<Task, ServerFnError<ErrorVe
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn get_tasks_in_category(filtered_category: Category)
|
pub(crate) async fn get_tasks_in_category(
|
||||||
-> Result<Vec<Task>, ServerFnError<ErrorVec<Error>>> {
|
filtered_category: Category,
|
||||||
|
) -> Result<Vec<Task>, ServerFnError<ErrorVec<Error>>> {
|
||||||
use crate::schema::tasks::dsl::*;
|
use crate::schema::tasks::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
.map_err::<ErrorVec<Error>, _>(
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|_| vec![Error::ServerInternal].into()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let results = tasks
|
let results = tasks
|
||||||
.select(Task::as_select())
|
.select(Task::as_select())
|
||||||
.filter(filtered_category.eq_sql_predicate())
|
.filter(filtered_category.eq_sql_predicate())
|
||||||
.load::<Task>(&mut connection)
|
.load::<Task>(&mut connection)
|
||||||
.map_err::<ErrorVec<Error>, _>(
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|_| vec![Error::ServerInternal].into()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn get_tasks_with_subtasks_in_category(filtered_category: Category) -> Result<
|
pub(crate) async fn get_tasks_with_subtasks_in_category(
|
||||||
Vec<TaskWithSubtasks>,
|
filtered_category: Category,
|
||||||
ServerFnError<ErrorVec<Error>>
|
) -> Result<Vec<TaskWithSubtasks>, ServerFnError<ErrorVec<Error>>> {
|
||||||
> {
|
|
||||||
use crate::schema::tasks;
|
use crate::schema::tasks;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
@ -90,7 +88,8 @@ pub(crate) async fn get_tasks_with_subtasks_in_category(filtered_category: Categ
|
|||||||
|
|
||||||
let tasks_in_category = tasks::table
|
let tasks_in_category = tasks::table
|
||||||
.filter(filtered_category.eq_sql_predicate())
|
.filter(filtered_category.eq_sql_predicate())
|
||||||
.select(Task::as_select()).load(&mut connection)
|
.select(Task::as_select())
|
||||||
|
.load(&mut connection)
|
||||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|
|
||||||
let subtasks = Subtask::belonging_to(&tasks_in_category)
|
let subtasks = Subtask::belonging_to(&tasks_in_category)
|
||||||
@ -109,21 +108,24 @@ pub(crate) async fn get_tasks_with_subtasks_in_category(filtered_category: Categ
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn edit_task(task_id: i32, mut new_task: NewTask)
|
pub(crate) async fn edit_task(
|
||||||
-> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
|
task_id: i32,
|
||||||
|
mut new_task: NewTask,
|
||||||
|
) -> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
|
||||||
use crate::schema::tasks::dsl::*;
|
use crate::schema::tasks::dsl::*;
|
||||||
|
|
||||||
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
|
||||||
let mut new_task = new_task;
|
let mut new_task = new_task;
|
||||||
new_task.title = new_task.title.trim().to_owned();
|
new_task.title = new_task.title.trim().to_owned();
|
||||||
|
|
||||||
new_task.validate()
|
new_task
|
||||||
|
.validate()
|
||||||
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
|
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection =
|
||||||
.map_err::<ErrorVec<TaskError>, _>(
|
establish_database_connection().map_err::<ErrorVec<TaskError>, _>(|_| {
|
||||||
|_| vec![TaskError::Error(Error::ServerInternal)].into()
|
vec![TaskError::Error(Error::ServerInternal)].into()
|
||||||
)?;
|
})?;
|
||||||
|
|
||||||
let updated_task = diesel::update(tasks)
|
let updated_task = diesel::update(tasks)
|
||||||
.filter(id.eq(task_id))
|
.filter(id.eq(task_id))
|
||||||
@ -149,14 +151,19 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
|||||||
reoccurrence: Some(reoccurrence),
|
reoccurrence: Some(reoccurrence),
|
||||||
date,
|
date,
|
||||||
..
|
..
|
||||||
} = &mut new_task.category {
|
} = &mut new_task.category
|
||||||
|
{
|
||||||
match reoccurrence.interval() {
|
match reoccurrence.interval() {
|
||||||
ReoccurrenceInterval::Day => *date = *date + Days::new(reoccurrence.length() as u64),
|
ReoccurrenceInterval::Day => *date = *date + Days::new(reoccurrence.length() as u64),
|
||||||
ReoccurrenceInterval::Month | ReoccurrenceInterval::Year => {
|
ReoccurrenceInterval::Month | ReoccurrenceInterval::Year => {
|
||||||
*date = *date + Months::new(
|
*date = *date
|
||||||
reoccurrence.length() *
|
+ Months::new(
|
||||||
if *(reoccurrence.interval()) == ReoccurrenceInterval::Year
|
reoccurrence.length()
|
||||||
{ 12 } else { 1 }
|
* if *(reoccurrence.interval()) == ReoccurrenceInterval::Year {
|
||||||
|
12
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
},
|
||||||
);
|
);
|
||||||
*date = NaiveDate::from_ymd_opt(
|
*date = NaiveDate::from_ymd_opt(
|
||||||
date.year(),
|
date.year(),
|
||||||
@ -165,7 +172,8 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
|||||||
date.year(),
|
date.year(),
|
||||||
(date.month() as u8).try_into().unwrap(),
|
(date.month() as u8).try_into().unwrap(),
|
||||||
) as u32),
|
) as u32),
|
||||||
).unwrap()
|
)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
restore_subtasks_of_task(task_id).await?;
|
restore_subtasks_of_task(task_id).await?;
|
||||||
@ -173,7 +181,8 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
|||||||
new_task.category = Category::Done;
|
new_task.category = Category::Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
let updated_task = edit_task(task_id, new_task).await
|
let updated_task = edit_task(task_id, new_task)
|
||||||
|
.await
|
||||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|
|
||||||
Ok(updated_task)
|
Ok(updated_task)
|
||||||
@ -182,14 +191,14 @@ pub(crate) async fn complete_task(task_id: i32) -> Result<Task, ServerFnError<Er
|
|||||||
// TODO: Get rid of this suppression.
|
// TODO: Get rid of this suppression.
|
||||||
//noinspection DuplicatedCode
|
//noinspection DuplicatedCode
|
||||||
#[server]
|
#[server]
|
||||||
pub(crate) async fn delete_task(task_id: i32)
|
pub(crate) async fn delete_task(task_id: i32) -> Result<(), ServerFnError<ErrorVec<Error>>> {
|
||||||
-> Result<(), ServerFnError<ErrorVec<Error>>> {
|
|
||||||
use crate::schema::tasks::dsl::*;
|
use crate::schema::tasks::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|
|
||||||
diesel::delete(tasks.filter(id.eq(task_id))).execute(&mut connection)
|
diesel::delete(tasks.filter(id.eq(task_id)))
|
||||||
|
.execute(&mut connection)
|
||||||
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
.map_err::<ErrorVec<Error>, _>(|error| vec![error.into()].into())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -199,9 +208,7 @@ pub(crate) async fn trigger_task_updated_at(task_id: i32) -> Result<Task, ErrorV
|
|||||||
use crate::schema::tasks::dsl::*;
|
use crate::schema::tasks::dsl::*;
|
||||||
|
|
||||||
let mut connection = establish_database_connection()
|
let mut connection = establish_database_connection()
|
||||||
.map_err::<ErrorVec<Error>, _>(
|
.map_err::<ErrorVec<Error>, _>(|_| vec![Error::ServerInternal].into())?;
|
||||||
|_| vec![Error::ServerInternal].into()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let updated_task = diesel::update(tasks)
|
let updated_task = diesel::update(tasks)
|
||||||
.filter(id.eq(task_id))
|
.filter(id.eq(task_id))
|
||||||
|
@ -27,7 +27,7 @@ impl<'a, T: Ord> Ord for ReverseOrdOption<'a, T> {
|
|||||||
(None, None) => Ordering::Equal,
|
(None, None) => Ordering::Equal,
|
||||||
(None, Some(_)) => Ordering::Greater,
|
(None, Some(_)) => Ordering::Greater,
|
||||||
(Some(_), None) => Ordering::Less,
|
(Some(_), None) => Ordering::Less,
|
||||||
(Some(self_time), Some(other_time)) => self_time.cmp(other_time)
|
(Some(self_time), Some(other_time)) => self_time.cmp(other_time),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user