Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget enhancements and inspector panel addition #199

Merged
merged 8 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DLPrototype/Utils/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Navigation: Identifiable, ObservableObject {
@Published public var view: AnyView? = AnyView(Dashboard())
@Published public var parent: Page? = .dashboard
@Published public var sidebar: AnyView? = AnyView(DashboardSidebar())
@Published public var inspector: AnyView? = nil
@Published public var title: String? = ""
@Published public var pageId: UUID? = UUID()
@Published public var session: Session = Session()
Expand Down Expand Up @@ -123,12 +124,18 @@ public class Navigation: Identifiable, ObservableObject {
pageId = nil
pageId = UUID()
}

public func setInspector(_ newInspector: AnyView? = nil) -> Void {
inspector = nil
inspector = newInspector
}

public func reset() -> Void {
parent = .dashboard
view = nil
sidebar = nil
setId()
inspector = nil
session = Session()
}
}
Expand Down
124 changes: 61 additions & 63 deletions DLPrototype/Views/Find/FindDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
// Copyright © 2023 YegCollective. All rights reserved.
//

import Foundation
import SwiftUI

struct RecentSearch: Identifiable {
let id: UUID = UUID()
var term: String
}

struct FindDashboard: View {
@Binding public var searching: Bool
public var location: WidgetLocation = .content

@State private var searchText: String = ""
@State private var activeSearchText: String = ""
Expand All @@ -42,7 +37,7 @@ struct FindDashboard: View {
SearchBar(
text: $activeSearchText,
disabled: false,
placeholder: "Search \(counts.0) records, \(counts.1) jobs, \(counts.2) tasks and \(counts.3) projects",
placeholder: location == .content ? "Search \(counts.0) records, \(counts.1) jobs, \(counts.2) tasks and \(counts.3) projects" : "Search for anything",
onSubmit: onSubmit,
onReset: onReset
)
Expand All @@ -60,11 +55,36 @@ struct FindDashboard: View {
onReset()
}
}
.onChange(of: nav.session.search.inspectingEntity) { entity in
if location == .sidebar {
if entity != nil {
nav.setInspector(AnyView(Inspector()))
}
}
}
}

if !searching && activeSearchText.count >= 2 {
GridRow {
HStack(alignment: .top, spacing: 1) {
if location == .content {
HStack(alignment: .top, spacing: 1) {
Suggestions(
searchText: $activeSearchText,
publishedOnly: $allowAlive,
showRecords: $showRecords,
showNotes: $showJobs,
showTasks: $showNotes,
showProjects: $showProjects,
showJobs: $showJobs,
showCompanies: $showCompanies,
showPeople: $showPeople
)

if nav.session.search.inspectingEntity != nil {
Inspector()
}
}
} else if location == .sidebar {
Suggestions(
searchText: $activeSearchText,
publishedOnly: $allowAlive,
Expand All @@ -76,33 +96,31 @@ struct FindDashboard: View {
showCompanies: $showCompanies,
showPeople: $showPeople
)

if nav.session.search.inspectingEntity != nil {
Inspector()
}
}
}
}

GridRow {
ZStack(alignment: .leading) {
Theme.subHeaderColour

HStack {
Toggle("Records", isOn: $showRecords)
Toggle("Notes", isOn: $showNotes)
Toggle("Tasks", isOn: $showTasks)
Toggle("Projects", isOn: $showProjects)
Toggle("Jobs", isOn: $showJobs)
Toggle("Companies", isOn: $showCompanies)
Toggle("People", isOn: $showPeople)
Spacer()
Toggle("Published Only", isOn: $allowAlive)
if location == .content {
GridRow {
ZStack(alignment: .leading) {
Theme.subHeaderColour

HStack {
Toggle("Records", isOn: $showRecords)
Toggle("Notes", isOn: $showNotes)
Toggle("Tasks", isOn: $showTasks)
Toggle("Projects", isOn: $showProjects)
Toggle("Jobs", isOn: $showJobs)
Toggle("Companies", isOn: $showCompanies)
Toggle("People", isOn: $showPeople)
Spacer()
Toggle("Published Only", isOn: $allowAlive)
}
.padding([.leading, .trailing], 10)
}
.padding([.leading, .trailing], 10)
}
.frame(height: 40)
}
.frame(height: 40)

if searching {
if loading {
Expand Down Expand Up @@ -148,16 +166,20 @@ extension FindDashboard {
private func onReset() -> Void {
searching = false
nav.session.search.reset()
nav.session.search.inspectingEntity = nil
nav.setInspector()
loading = false
}

private func actionOnAppear() -> Void {
counts = (
CoreDataRecords(moc: moc).countAll(),
CoreDataJob(moc: moc).countAll(),
CoreDataTasks(moc: moc).countAll(),
CoreDataProjects(moc: moc).countAll()
)
if location == .content {
counts = (
CoreDataRecords(moc: moc).countAll(),
CoreDataJob(moc: moc).countAll(),
CoreDataTasks(moc: moc).countAll(),
CoreDataProjects(moc: moc).countAll()
)
}
}

private func createTabs() -> Void {
Expand Down Expand Up @@ -288,7 +310,7 @@ extension FindDashboard {
Spacer()
FancyButtonv2(
text: "Close",
action: {nav.session.search.inspectingEntity = nil},
action: actionChangeEntity,
icon: "xmark",
showLabel: false,
size: .tiny,
Expand Down Expand Up @@ -1497,70 +1519,42 @@ extension FindDashboard {

extension FindDashboard.Suggestions.SuggestedJobs {
private func choose(_ item: Job) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}

extension FindDashboard.Suggestions.SuggestedProjects {
private func choose(_ item: Project) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}

extension FindDashboard.Suggestions.SuggestedNotes {
private func choose(_ item: Note) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}

extension FindDashboard.Suggestions.SuggestedTasks {
private func choose(_ item: LogTask) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}

extension FindDashboard.Suggestions.SuggestedCompanies {
private func choose(_ item: Company) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}

extension FindDashboard.Suggestions.SuggestedPeople {
private func choose(_ item: Person) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}

extension FindDashboard.Suggestions.SuggestedRecords {
private func choose(_ item: LogRecord) -> Void {
if nav.session.search.inspectingEntity != nil {
nav.session.search.inspectingEntity = nil
}

nav.session.search.inspectingEntity = item
}
}
Expand All @@ -1582,6 +1576,10 @@ extension FindDashboard.Inspector {
}
}
}

private func actionChangeEntity() -> Void {
nav.session.search.inspectingEntity = nil
}
}

extension FindDashboard.RecordsMatchingString {
Expand Down
15 changes: 15 additions & 0 deletions DLPrototype/Views/Home/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ struct Home: View {
} else {
HorizontalSeparator // TODO: maybe remove?
}

if nav.inspector != nil {
ZStack(alignment: .topLeading) {
LinearGradient(gradient: Gradient(colors: [Color.clear, Color.black]), startPoint: .topTrailing, endPoint: .topLeading)
.opacity(0.25)
.frame(width: 20)

nav.inspector
.environmentObject(nav)
}
.background(Theme.subHeaderColour)
.frame(width: 340)
}

if isDatePickerPresented{
ZStack {
Expand Down Expand Up @@ -179,6 +192,8 @@ struct Home: View {
NSEvent.addLocalMonitorForEvents(matching: .keyDown) {
if self.isEscapeKey(with: $0) {
isDatePickerPresented = false
nav.session.search.inspectingEntity = nil
nav.setInspector()
return nil
} else {
return $0
Expand Down
26 changes: 12 additions & 14 deletions DLPrototype/Views/Shared/AppSidebar/SidebarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ struct SidebarItem: View, Identifiable {

@ViewBuilder private var ItemIcon: some View {
if let ic = icon {
ZStack(alignment: .center) {
if ![.important, .action].contains(role) {
role.colour.opacity(highlighted ? 0.15 : 0.08)
} else {
role.colour
}

VStack {
Button(action: doAction) {
Button(action: doAction) {
ZStack(alignment: .center) {
if ![.important, .action].contains(role) {
role.colour.opacity(highlighted ? 0.15 : 0.08)
} else {
role.colour
}
VStack {
if let alt = altIcon {
if highlighted {
Image(systemName: alt)
Expand All @@ -128,13 +128,11 @@ struct SidebarItem: View, Identifiable {
.frame(maxWidth: 30, maxHeight: 30)
}
}
.buttonStyle(.plain)
.useDefaultHover({ inside in highlighted = inside})
.padding(.top, 5)
Spacer()
}
.frame(width: type.iconFrameSize)
}
.frame(width: type.iconFrameSize)
.buttonStyle(.plain)
.useDefaultHover({ inside in highlighted = inside})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ extension TodayInHistoryWidget {
minimized.toggle()
}

private func actionSettings() -> Void {
// isSettingsPresented.toggle()
}

private func findHistoricalDataForToday() async -> Void {
let calendar = Calendar.autoupdatingCurrent
let current = calendar.dateComponents([.year, .month, .day], from: currentDate)
Expand Down
3 changes: 2 additions & 1 deletion DLPrototype/Views/Shared/Fancy/FancyButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public struct FancyButtonv2: View {
button
}
.buttonStyle(.plain)
.useDefaultHover({ inside in highlighted = inside})
} else {
Button(action: {
if let ac = action {
Expand All @@ -118,6 +119,7 @@ public struct FancyButtonv2: View {
button
}
.buttonStyle(.plain)
.useDefaultHover({ inside in highlighted = inside})
}
}

Expand Down Expand Up @@ -164,7 +166,6 @@ public struct FancyButtonv2: View {
.font(size.font)
.help(text)
.underline((size == .link || size == .titleLink) && highlighted)
.useDefaultHover({ inside in highlighted = inside})
}

private var Background: some View {
Expand Down
2 changes: 1 addition & 1 deletion DLPrototype/Views/Shared/Fancy/FancyGenericToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct FancyGenericToolbar: View {
.buttonStyle(.borderless)
.foregroundColor(Color.white)
.help(button.helpText)
.frame(width: 60)
.frame(width: location == .sidebar ? 40 : 60)
.useDefaultHover({_ in})
}
}
Expand Down
Loading