Skip to content

Commit

Permalink
ui: Add media removal functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin42 committed Jan 18, 2025
1 parent cb179e2 commit 2136b7e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion osx/PhotoBook/PhotoBook/MediaItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import SwiftUI

struct MediaItem: Hashable
struct MediaItem: Hashable, Identifiable
{
let id = UUID()
var path: String;
var displayName: String;
}
1 change: 1 addition & 0 deletions osx/PhotoBook/PhotoBook/Photobook.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- (NSArray<ProjectMetadataEntry*>*) projectsList;
- (ProjectManagementServiceWrapper*) projectManagementService;
- (void) addImportFolder:(NSString*)root;
- (void) removeImportFolder:(NSString*)root;
@end

#endif /* Photobook_h */
9 changes: 9 additions & 0 deletions osx/PhotoBook/PhotoBook/Photobook.mm
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,13 @@ - (void) addImportFolder:(NSString*)root
mPhotobook->addImportFolder(nativeRoot);
}

- (void) removeImportFolder:(NSString*)root
{
NSURL *url = [NSURL URLWithString:root];
NSString *filePath = [url path];

std::string nativeRoot = [filePath UTF8String];
mPhotobook->removeImportFolder(nativeRoot);
}

@end
11 changes: 10 additions & 1 deletion osx/PhotoBook/PhotoBook/TableContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct TableContentView: View, PhotobookUIListener {
@State var selectedTab: Int = 0

@State private var showImportMediaPicker = false

@State private var selectedMediaItem: MediaItem? = nil

init(navigationPath:Binding<[String]>, photobook: Photobook)
{
Expand Down Expand Up @@ -46,8 +48,14 @@ struct TableContentView: View, PhotobookUIListener {
.background(Color.PrimaryColor)
.buttonStyle(PlainButtonStyle())

// Remove media button
Button(action: {
print("Remove media tapped")
if let index = mediaList.firstIndex(where: {$0.path == selectedMediaItem?.path})
{
mediaList.remove(at: index)
self.photobook.removeImportFolder(selectedMediaItem?.path)
}
}) {
Image(systemName: "trash")
.scaledToFit()
Expand Down Expand Up @@ -164,8 +172,9 @@ struct TableContentView: View, PhotobookUIListener {
.padding()
.background(Color.PrimaryColor)
TabView(selection: $selectedTab) {
// Media list
VStack{
List(mediaList, id: \.self) { item in
List(mediaList, id: \.self, selection: $selectedMediaItem) { item in
Text("\(item.displayName)")
.listRowBackground(Color.PrimaryColor)
}
Expand Down

0 comments on commit 2136b7e

Please sign in to comment.