From 9c0dbd66af4b6ef2014a101ddb7b14a00f26ad61 Mon Sep 17 00:00:00 2001
From: hannes <hannes@gfzdfuz.de>
Date: Mon, 25 Jan 2021 11:34:11 +0100
Subject: [PATCH] files multiple overflow fix?

---
 .../Files/Children/FilesPreviewer.swift       | 49 +++++++++++--------
 .../Categories/Files/FilesCategoryModel.swift |  6 +++
 .../Helpers/UI/CategoryViewInner.swift        |  1 +
 .../Helpers/ViewModels/HomeModel.swift        |  5 +-
 4 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/Children/FilesPreviewer.swift b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/Children/FilesPreviewer.swift
index 403e63f7..87ff539c 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/Children/FilesPreviewer.swift	
+++ b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/Children/FilesPreviewer.swift	
@@ -18,28 +18,37 @@ struct FilesPreviewer: View {
     var body: some View {
         ScrollView(.horizontal,showsIndicators:false){HStack{ForEach(0..<filesCategoryVM.mailsAttachments.count){ mailIndex -> AnyView in
             guard let mailAttachments = filesCategoryVM.mailsAttachments[safe: mailIndex] else {return AnyView(EmptyView())}
-            return AnyView(VStack{
-                Text(filesCategoryVM.mails[mailIndex].subject)
-                ForEach(0..<mailAttachments.count){ attachmentIndex in let attachment = mailAttachments[attachmentIndex]
-                    AttPrev(
-                        attachment: attachment,
-                        additionalActions:[
-                            AttPrev.Action(
-                                icon: AnyView(Image(systemName: "mail")),
-                                description: NSLocalizedString("open mail in standard view", comment: ""),
-                                onClick: {
-                                    openOrigView(filesCategoryVM.mails[mailIndex])
-                                }
-                            )
-                        ],
-                        preload: false
-                    ) //TODO: make this have the exact aspect ratio ?
-                        .frame(width: 200)
-                    .padding(.horizontal, 40).padding(.bottom, -25).padding(.top, -7)
-                }
-            })
+            return
+                filesCategoryVM.isFullscreen ?
+                AnyView(ScrollView(.vertical, showsIndicators:false){attachmentColumn(filesCategoryVM.mails[mailIndex],attachments:mailAttachments)}) :
+                AnyView(attachmentColumn(filesCategoryVM.mails[mailIndex],attachments:mailAttachments))
         }}.padding(.horizontal)}
     }
+    
+    func attachmentColumn(_ mail: eMail, attachments:[DisplayAttachment])->some View{
+        let height = filesCategoryVM.attachmentsize(attachments.count)
+        return VStack{
+            Text(mail.subject)
+            ForEach(0..<attachments.count){ attachmentIndex in let attachment = attachments[attachmentIndex]
+                AttPrev(
+                    attachment: attachment,
+                    additionalActions:[
+                        AttPrev.Action(
+                            icon: AnyView(Image(systemName: "mail")),
+                            description: NSLocalizedString("open mail in standard view", comment: ""),
+                            onClick: {
+                                openOrigView(mail)
+                            }
+                        )
+                    ],
+                    preload: false
+                ) //TODO: make this have the exact aspect ratio ?
+                .frame(width: 200).frame(height: height)
+                .padding(.horizontal, 40).padding(.bottom, -25).padding(.top, -7)
+            }
+        }
+    }
+    
     func openOrigView(_ mail: eMail){
         //TODO : open the readView
         //navigate(to: ReadMainView(mail: mail), when: $openEmail)
diff --git a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/FilesCategoryModel.swift b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/FilesCategoryModel.swift
index c9a674e6..8ebc5914 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/FilesCategoryModel.swift	
+++ b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Categories/Files/FilesCategoryModel.swift	
@@ -30,4 +30,10 @@ class FilesCategoryVM: ObservableObject {
         mails.map{$0.displayAttachments}
     }
     
+    
+    var isFullscreen : Bool {categoryBaseModel.size == nil}
+    func attachmentsize(_ attachmentCount:Int)->CGFloat {
+        return isFullscreen ? 250 : ((categoryBaseModel.size! - 50) / CGFloat(attachmentCount))
+    }
+    
 }
diff --git a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/UI/CategoryViewInner.swift b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/UI/CategoryViewInner.swift
index b0a49e2d..3002871b 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/UI/CategoryViewInner.swift	
+++ b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/UI/CategoryViewInner.swift	
@@ -78,6 +78,7 @@ struct CategoryCardAlike<Content: View> : View {
             Divider()
             content()
                 .frame(height:_size)
+                //.clipped()
             Spacer()
         }//TODO disable scrolling
         .gesture(DragGesture())
diff --git a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/ViewModels/HomeModel.swift b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/ViewModels/HomeModel.swift
index e9182037..2930e115 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/ViewModels/HomeModel.swift	
+++ b/enzevalos_iphone/SwiftUI/Inbox/Thesis Inbox/Helpers/ViewModels/HomeModel.swift	
@@ -62,7 +62,10 @@ class HomeModel : ObservableObject{
     
     @Published var scrollAmount:CGFloat = 0
     
-    private var allCats : [CategoryViewModel] {allCategorieModels.array}
+    private var allCats : [CategoryViewModel] {
+        //allCategorieModels.array.sort{($0.lastMailTimestamp ?? Date.distantPast) > ($1.lastMailTimestamp ?? Date.distantPast)}
+        return allCategorieModels.array
+    }
     
     private func updateSearch(){
         allCats.forEach{category in
-- 
GitLab