Skip to content

Commit

Permalink
Add refresh for year_photos
Browse files Browse the repository at this point in the history
  • Loading branch information
blissd committed Apr 3, 2024
1 parent a438ae2 commit 757e20c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use self::components::{
all_photos::{AllPhotos, AllPhotosInput, AllPhotosOutput},
month_photos::{MonthPhotos, MonthPhotosOutput, MonthPhotosInput},
one_photo::{OnePhoto, OnePhotoInput},
year_photos::{YearPhotos, YearPhotosOutput},
year_photos::{YearPhotos, YearPhotosInput, YearPhotosOutput},
selfie_photos::{SelfiePhotos, SelfiePhotosInput, SelfiePhotosOutput,},
};

Expand Down Expand Up @@ -465,6 +465,7 @@ impl SimpleComponent for App {
self.all_photos.emit(AllPhotosInput::Refresh);
self.selfie_photos.emit(SelfiePhotosInput::Refresh);
self.month_photos.emit(MonthPhotosInput::Refresh);
self.year_photos.emit(YearPhotosInput::Refresh);

self.generate_previews.emit(GeneratePreviewsInput::Generate);
},
Expand Down
41 changes: 25 additions & 16 deletions src/app/components/year_photos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ struct PhotoGridItem {
pub enum YearPhotosInput {
/// User has selected year in grid view
YearSelected(u32), // WARN this is an index into an Vec, not a year.

// Reload photos from database
Refresh,
}

#[derive(Debug)]
Expand Down Expand Up @@ -93,6 +96,7 @@ impl RelmGridItem for PhotoGridItem {
}

pub struct YearPhotos {
repo: Arc<Mutex<photos_core::Repository>>,
pictures_grid_view: TypedGridView<PhotoGridItem, gtk::NoSelection>,
}

Expand Down Expand Up @@ -132,36 +136,41 @@ impl SimpleComponent for YearPhotos {
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let all_pictures = repo
.lock().unwrap()
.all()
.unwrap()
.into_iter()
.dedup_by(|x, y| x.year() == y.year())
.map(|picture| PhotoGridItem {
picture,
});

let mut grid_view_wrapper: TypedGridView<PhotoGridItem, gtk::NoSelection> =
TypedGridView::new();

grid_view_wrapper.extend_from_iter(all_pictures.into_iter());
let mut grid_view_wrapper = TypedGridView::new();

let model = YearPhotos {
repo,
pictures_grid_view: grid_view_wrapper,
};

let pictures_box = &model.pictures_grid_view.view;
if !model.pictures_grid_view.is_empty(){
pictures_box.scroll_to(model.pictures_grid_view.len() - 1, gtk::ListScrollFlags::SELECT, None);
}

let widgets = view_output!();
ComponentParts { model, widgets }
}

fn update(&mut self, msg: Self::Input, sender: ComponentSender<Self>) {
match msg {
YearPhotosInput::Refresh => {
let all_pictures = self.repo
.lock().unwrap()
.all()
.unwrap()
.into_iter()
.dedup_by(|x, y| x.year() == y.year())
.map(|picture| PhotoGridItem {
picture,
});

self.pictures_grid_view.clear();
self.pictures_grid_view.extend_from_iter(all_pictures.into_iter());

if !self.pictures_grid_view.is_empty(){
self.pictures_grid_view.view
.scroll_to(self.pictures_grid_view.len() - 1, gtk::ListScrollFlags::SELECT, None);
}
},
YearPhotosInput::YearSelected(index) => {
if let Some(item) = self.pictures_grid_view.get(index) {
let date = item.borrow().picture.year_month();
Expand Down

0 comments on commit 757e20c

Please sign in to comment.