Skip to content

Commit

Permalink
fix: Add name to folder and file without preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrdctr committed Nov 14, 2024
1 parent ad87bf0 commit e322900
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions SwissTransferCoreUI/Components/Thumbnail/SmallThumbnailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public struct SmallThumbnailView: View {
private let url: URL?
private let removeAction: (() -> Void)?

@State private var name: String?
@State private var icon: Image
@State private var thumbnail: Image?
private var cornerRadius: CGFloat = IKRadius.medium
Expand All @@ -37,6 +38,7 @@ public struct SmallThumbnailView: View {
self.removeAction = removeAction

if removeAction != nil {
name = url?.lastPathComponent
_size = ScaledMetric(wrappedValue: 80, relativeTo: .body)
cornerRadius = IKRadius.large
}
Expand All @@ -45,11 +47,12 @@ public struct SmallThumbnailView: View {
}

/// Folder init
public init(removeAction: (() -> Void)? = nil) {
public init(name: String? = nil, removeAction: (() -> Void)? = nil) {
url = nil
self.removeAction = removeAction

if removeAction != nil {
self.name = name
_size = ScaledMetric(wrappedValue: 80, relativeTo: .body)
cornerRadius = IKRadius.large
}
Expand All @@ -66,12 +69,23 @@ public struct SmallThumbnailView: View {
.frame(width: size, height: size)
.clipShape(.rect(cornerRadius: cornerRadius))
} else {
FileIconView(icon: icon, type: .small)
.frame(width: size, height: size)
.background(Color.ST.background, in: .rect(cornerRadius: cornerRadius))
.task {
thumbnail = await ThumbnailGenerator.generate(for: url, cgSize: CGSize(width: size, height: size))
VStack(spacing: IKPadding.small) {
FileIconView(icon: icon, type: .small)

if let name {
Text(name)
.font(.ST.caption)
.foregroundStyle(Color.ST.textSecondary)
.lineLimit(1)
.truncationMode(.tail)
}
}
.padding(value: .small)
.frame(width: size, height: size)
.background(Color.ST.background, in: .rect(cornerRadius: cornerRadius))
.task {
thumbnail = await ThumbnailGenerator.generate(for: url, cgSize: CGSize(width: size, height: size))
}
}

if let removeAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct NewTransferFilesCellView: View {
ForEach(files) { file in
if file.isFolder {
NavigationLink(value: file) {
SmallThumbnailView {
SmallThumbnailView(name: file.name) {
newTransferManager.remove(file: file) {
files = newTransferManager.filesAt(folderURL: nil)
}
Expand Down

0 comments on commit e322900

Please sign in to comment.