Skip to content

Commit

Permalink
Add month photos view
Browse files Browse the repository at this point in the history
  • Loading branch information
blissd committed Mar 26, 2024
1 parent 6142fd1 commit 6e76295
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
32 changes: 32 additions & 0 deletions core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ impl Display for PictureId {
}
}

#[derive(Debug, PartialOrd, PartialEq)]
pub struct YearMonth(i32, chrono::Month);

impl Display for YearMonth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} {}", self.1.name(), self.0)
}
}

impl YearMonth {
pub fn year(&self) -> i32 {
self.0
}

pub fn month(&self) -> chrono::Month {
self.1
}
}

/// A picture in the repository
#[derive(Debug)]
pub struct Picture {
Expand All @@ -54,6 +73,19 @@ impl Picture {
.map(|ts| ts.date_naive().year_ce().1)
.unwrap_or(0)
}

pub fn year_month(&self) -> YearMonth {
self.order_by_ts
.map(|ts| {
let y = ts.date_naive().year();
let m = ts.date_naive().month();
YearMonth(
y,
chrono::Month::try_from(u8::try_from(m).unwrap()).unwrap(),
)
})
.unwrap_or(YearMonth(0, chrono::Month::January))
}
}

/// Repository of picture metadata.
Expand Down
10 changes: 5 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ use relm4::adw::prelude::AdwApplicationWindowExt;
use crate::all_photos::AllPhotos;
use crate::config::{APP_ID, PROFILE};
use crate::modals::about::AboutDialog;
use crate::month_photos::MonthPhotos;
use crate::year_photos::YearPhotos;

pub(super) struct App {
about_dialog: Controller<AboutDialog>,
all_photos: Controller<AllPhotos>,
month_photos: Controller<MonthPhotos>,
year_photos: Controller<YearPhotos>,
}

Expand Down Expand Up @@ -108,11 +110,7 @@ impl SimpleComponent for App {

add_titled_with_icon[None, "Year", "year-symbolic"] = model.year_photos.widget(),

add_titled_with_icon[None, "Month", "month-symbolic"] = &gtk::Box {
gtk::Label {
set_label: "Hello",
}
},
add_titled_with_icon[None, "Month", "month-symbolic"] = model.month_photos.widget(),

add_titled_with_icon[None, "All", "today-symbolic"] = model.all_photos.widget(),
},
Expand All @@ -138,11 +136,13 @@ impl SimpleComponent for App {
.detach();

let all_photos = AllPhotos::builder().launch(()).detach();
let month_photos = MonthPhotos::builder().launch(()).detach();
let year_photos = YearPhotos::builder().launch(()).detach();

let model = Self {
about_dialog,
all_photos,
month_photos,
year_photos,
};

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod config;
mod all_photos;
mod app;
mod modals;
mod month_photos;
mod year_photos;

use app::App;
Expand Down
19 changes: 9 additions & 10 deletions src/year_photos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use photos_core;

use itertools::Itertools;
use relm4::gtk;
use relm4::gtk::prelude::FrameExt;
use relm4::gtk::prelude::WidgetExt;
use relm4::typed_view::grid::{RelmGridItem, TypedGridView};
use relm4::*;
Expand Down Expand Up @@ -41,19 +40,19 @@ impl RelmGridItem for PicturePreview {
gtk::Label {},

adw::Clamp {
set_maximum_size: 200,
set_maximum_size: 200,

gtk::Frame {
gtk::Frame {

#[name(picture)]
gtk::Picture {
set_can_shrink: true,
set_valign: gtk::Align::Center,
set_width_request: 200,
set_height_request: 200,
#[name(picture)]
gtk::Picture {
set_can_shrink: true,
set_valign: gtk::Align::Center,
set_width_request: 200,
set_height_request: 200,
}
}
}
}
}
}

Expand Down

0 comments on commit 6e76295

Please sign in to comment.