Files
todo-baggins/src/components/task_list_item.rs
Matouš Volf 3646aa91c4
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
style: fix the rustfmt linted files
2024-12-29 19:30:35 +01:00

105 lines
4.4 KiB
Rust

use crate::internationalization::LocaleFromLanguageIdentifier;
use crate::models::category::Category;
use crate::models::task::TaskWithSubtasks;
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 voca_rs::Voca;
#[component]
pub(crate) fn TaskListItem(task: TaskWithSubtasks) -> Element {
rsx! {
div {
class: "flex flex-col",
div {
class: "mt-2 grow font-medium",
{task.task().title()}
},
div {
class: "flex flex-row gap-4",
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) {
t!("yesterday")
} else if deadline == today_date {
t!("today")
} else if deadline == today_date + chrono::Days::new(1) {
t!("tomorrow")
} else if deadline > today_date
&& deadline <= today_date + chrono::Days::new(7) {
let deadline = deadline.format_localized(
"%A",
LocaleFromLanguageIdentifier::from(
&i18n().language()
).into()
).to_string();
if t!("weekday-lowercase-first")
.parse().unwrap() {
deadline._lower_first()
} else {
deadline
}
} else {
let format = t!(
if deadline.year() == today_date.year() {
"date-format"
} else {
"date-year-format"
}
);
deadline.format_localized(
format.as_str(),
LocaleFromLanguageIdentifier::from(
&i18n().language()
).into()
).to_string()
}
)
}
}
}
if let Category::Calendar { time, .. } = task.task().category() {
if let Some(calendar_time) = time {
div {
class: "text-sm text-zinc-400",
i {
class: "fa-solid fa-clock"
},
{
let format = t!("time-format");
format!(" {}", calendar_time.time().format(format.as_str()))
}
}
}
}
if !task.subtasks().is_empty() {
div {
class: "text-sm text-zinc-400",
i {
class: "fa-solid fa-list-check"
},
{format!(
" {}/{}",
task.subtasks().iter()
.filter(|subtask| subtask.is_completed())
.count(),
task.subtasks().len()
)}
}
}
}
}
}
}