From 53a0993ab3476a3a4616151cb9f44fa40309ef8f Mon Sep 17 00:00:00 2001 From: dscyrescotti Date: Sun, 30 Jun 2024 01:25:27 +0700 Subject: [PATCH] feat: fine tune navigation title --- .../Views/Placeholder/Placeholder.swift | 12 +- .../Dashboard/Details/Memos/MemosView.swift | 137 +++++++++--------- .../Dashboard/Details/Trash/TrashView.swift | 75 +++++----- .../Features/Dashboard/Sidebar/Sidebar.swift | 23 ++- 4 files changed, 124 insertions(+), 123 deletions(-) diff --git a/Memola/Components/Views/Placeholder/Placeholder.swift b/Memola/Components/Views/Placeholder/Placeholder.swift index c7b55ae..c2d2828 100644 --- a/Memola/Components/Views/Placeholder/Placeholder.swift +++ b/Memola/Components/Views/Placeholder/Placeholder.swift @@ -8,23 +8,25 @@ import SwiftUI struct Placeholder: View { + @Environment(\.horizontalSizeClass) var horizontalSizeClass + let info: Info var body: some View { VStack(spacing: 15) { + let iconSize: CGFloat = horizontalSizeClass == .compact ? 40 : 50 Image(systemName: info.icon) - .font(.system(size: 50)) - .frame(width: 55, height: 55) + .font(.system(size: iconSize)) + .frame(width: iconSize * 1.1, height: iconSize * 1.1) VStack(spacing: 3) { Text(info.title) - .font(.title2) + .font(horizontalSizeClass == .compact ? .headline : .title2) .fontWeight(.bold) .foregroundStyle(.primary) Text(info.description) - .font(.callout) + .font(horizontalSizeClass == .compact ? .caption : .callout) .lineLimit(.none) .fontWeight(.regular) - .frame(minHeight: 50, alignment: .top) } } .foregroundStyle(.secondary) diff --git a/Memola/Features/Dashboard/Details/Memos/MemosView.swift b/Memola/Features/Dashboard/Details/Memos/MemosView.swift index d98119c..c931e3b 100644 --- a/Memola/Features/Dashboard/Details/Memos/MemosView.swift +++ b/Memola/Features/Dashboard/Details/Memos/MemosView.swift @@ -43,66 +43,37 @@ struct MemosView: View { var body: some View { MemoGrid(memoObjects: memoObjects, placeholder: placeholder) { memoObject in - memoCard(memoObject) - } - .navigationBarTitleDisplayMode(.inline) - .searchable(text: $query, placement: .toolbar, prompt: Text("Search")) - .toolbar { - if horizontalSizeClass == .compact { - ToolbarItem(placement: .principal) { - Text("Memos") - .font(.title3) - .fontWeight(.bold) - } - } else { - ToolbarItem(placement: .topBarLeading) { - Text("Memola") - .font(.title3) - .fontWeight(.bold) - } + memoCard(memoObject) + } + .navigationTitle(horizontalSizeClass == .compact ? "Memos" : "") + .navigationBarTitleDisplayMode(.inline) + .searchable(text: $query, placement: .toolbar, prompt: Text("Search")) + .toolbar { + if horizontalSizeClass == .regular { + ToolbarItem(placement: .topBarLeading) { + Text("Memola") + .font(.title3) + .fontWeight(.bold) } - ToolbarItemGroup(placement: .topBarTrailing) { - HStack(spacing: 5) { - Button { - createMemo(title: "Untitled") - } label: { - Image(systemName: "square.and.pencil") - } - .hoverEffect(.lift) - if horizontalSizeClass == .compact { - Menu { - VStack { - Picker("", selection: $sort) { - ForEach(Sort.all) { sort in - Text(sort.name) - .tag(sort) - } - } - .pickerStyle(.automatic) - Picker("", selection: $filter) { - ForEach(Filter.all) { filter in - Text(filter.name) - .tag(filter) - } - } - .pickerStyle(.automatic) - } - } label: { - Image(systemName: "ellipsis.circle") - } - } else { - Menu { + } + ToolbarItemGroup(placement: .topBarTrailing) { + HStack(spacing: 5) { + Button { + createMemo(title: "Untitled") + } label: { + Image(systemName: "square.and.pencil") + } + .hoverEffect(.lift) + if horizontalSizeClass == .compact { + Menu { + VStack { Picker("", selection: $sort) { ForEach(Sort.all) { sort in Text(sort.name) .tag(sort) } } - } label: { - Image(systemName: "arrow.up.arrow.down.circle") - } - .hoverEffect(.lift) - Menu { + .pickerStyle(.automatic) Picker("", selection: $filter) { ForEach(Filter.all) { filter in Text(filter.name) @@ -110,29 +81,53 @@ struct MemosView: View { } } .pickerStyle(.automatic) - } label: { - Image(systemName: "line.3.horizontal.decrease.circle") } + } label: { + Image(systemName: "ellipsis.circle") + } + } else { + Menu { + Picker("", selection: $sort) { + ForEach(Sort.all) { sort in + Text(sort.name) + .tag(sort) + } + } + } label: { + Image(systemName: "arrow.up.arrow.down.circle") + } + .hoverEffect(.lift) + Menu { + Picker("", selection: $filter) { + ForEach(Filter.all) { filter in + Text(filter.name) + .tag(filter) + } + } + .pickerStyle(.automatic) + } label: { + Image(systemName: "line.3.horizontal.decrease.circle") } } } } - .onChange(of: sort) { oldValue, newValue in - memoObjects.sortDescriptors = newValue.memoSortDescriptors - } - .onChange(of: query) { oldValue, newValue in - updatePredicate() - } - .onChange(of: filter) { oldValue, newValue in - updatePredicate() - } - .onReceive(timer) { date in - currentDate = date - } - .onAppear { - memoObjects.sortDescriptors = sort.memoSortDescriptors - updatePredicate() - } + } + .onChange(of: sort) { oldValue, newValue in + memoObjects.sortDescriptors = newValue.memoSortDescriptors + } + .onChange(of: query) { oldValue, newValue in + updatePredicate() + } + .onChange(of: filter) { oldValue, newValue in + updatePredicate() + } + .onReceive(timer) { date in + currentDate = date + } + .onAppear { + memoObjects.sortDescriptors = sort.memoSortDescriptors + updatePredicate() + } } func memoCard(_ memoObject: MemoObject) -> some View { diff --git a/Memola/Features/Dashboard/Details/Trash/TrashView.swift b/Memola/Features/Dashboard/Details/Trash/TrashView.swift index d161da7..5deff1a 100644 --- a/Memola/Features/Dashboard/Details/Trash/TrashView.swift +++ b/Memola/Features/Dashboard/Details/Trash/TrashView.swift @@ -45,51 +45,46 @@ struct TrashView: View { MemoGrid(memoObjects: memoObjects, placeholder: placeholder) { memoObject in memoCard(memoObject) } - .navigationBarTitleDisplayMode(.inline) - .searchable(text: $query, placement: .toolbar, prompt: Text("Search")) - .toolbar { - if horizontalSizeClass == .compact { - ToolbarItem(placement: .principal) { - Text("Trash") - .font(.title3) - .fontWeight(.bold) - } - } else { - ToolbarItem(placement: .topBarLeading) { - Text("Memola") - .font(.title3) - .fontWeight(.bold) - } + .navigationTitle(horizontalSizeClass == .compact ? "Trash" : "") + .navigationBarTitleDisplayMode(.inline) + .searchable(text: $query, placement: .toolbar, prompt: Text("Search")) + .toolbar { + if horizontalSizeClass == .regular { + ToolbarItem(placement: .topBarLeading) { + Text("Memola") + .font(.title3) + .fontWeight(.bold) } } - .onChange(of: query) { oldValue, newValue in - updatePredicate() + } + .onChange(of: query) { oldValue, newValue in + updatePredicate() + } + .alert("Restore Memo", isPresented: restoresMemo) { + Button { + restoreMemo(for: restoredMemo) + } label: { + Text("Restore") } - .alert("Restore Memo", isPresented: restoresMemo) { - Button { - restoreMemo(for: restoredMemo) - } label: { - Text("Restore") - } - Button { - restoreAndOpenMemo(for: restoredMemo) - } label: { - Text("Restore and Open") - } - Button("Cancel", role: .cancel) { } - } message: { - Text("Would you like to restore this memo or restore and open it?") + Button { + restoreAndOpenMemo(for: restoredMemo) + } label: { + Text("Restore and Open") } - .alert("Delete Memo Permanently", isPresented: deletesMemo) { - Button(role: .destructive) { - deleteMemo(for: deletedMemo) - } label: { - Text("Delete") - } - Button("Cancel", role: .cancel) { } - } message: { - Text("Are you sure you want to permanently delete this memo? This action cannot be undone.") + Button("Cancel", role: .cancel) { } + } message: { + Text("Would you like to restore this memo or restore and open it?") + } + .alert("Delete Memo Permanently", isPresented: deletesMemo) { + Button(role: .destructive) { + deleteMemo(for: deletedMemo) + } label: { + Text("Delete") } + Button("Cancel", role: .cancel) { } + } message: { + Text("Are you sure you want to permanently delete this memo? This action cannot be undone.") + } } func memoCard(_ memoObject: MemoObject) -> some View { diff --git a/Memola/Features/Dashboard/Sidebar/Sidebar.swift b/Memola/Features/Dashboard/Sidebar/Sidebar.swift index 716bef3..99ba758 100644 --- a/Memola/Features/Dashboard/Sidebar/Sidebar.swift +++ b/Memola/Features/Dashboard/Sidebar/Sidebar.swift @@ -16,14 +16,23 @@ struct Sidebar: View { var body: some View { List(selection: $sidebarItem) { ForEach(sidebarItems) { item in - Button { - sidebarItem = item - } label: { - Label(item.title, systemImage: item.icon) - .foregroundColor(.primary) + if horizontalSizeClass == .compact { + Button { + sidebarItem = item + } label: { + Label(item.title, systemImage: item.icon) + .foregroundColor(.primary) + } + } else { + Button { + sidebarItem = item + } label: { + Label(item.title, systemImage: item.icon) + .foregroundColor(.primary) + } + .buttonStyle(sidebarItem == item ? .selected : .unselected) + .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) } - .buttonStyle(sidebarItem == item ? .selected : .unselected) - .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) } } .listStyle(.sidebar)