Skip to content

Commit

Permalink
Merge pull request #319 from aapis/feature/1.15/more-inspectors
Browse files Browse the repository at this point in the history
Inspector improvements
  • Loading branch information
aapis authored Oct 29, 2024
2 parents e62bdc4 + e63afc2 commit ddde747
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 117 deletions.
101 changes: 98 additions & 3 deletions KWCore/Sources/UI/WidgetLibrary/WidgetLibrary.Blocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension WidgetLibrary.UI {
Spacer()
}
.padding(8)
.background(self.definition.job?.backgroundColor ?? Theme.rowColour)
.background(self.isHighlighted ? (self.definition.job?.backgroundColor ?? Theme.rowColour).opacity(1) : (self.definition.job?.backgroundColor ?? Theme.rowColour).opacity(0.8)) // @TODO: refactor, this sucks
.foregroundStyle((self.definition.job?.backgroundColor ?? Theme.rowColour).isBright() ? Theme.base : Theme.lightWhite)
}
.buttonStyle(.plain)
Expand All @@ -49,12 +49,11 @@ extension WidgetLibrary.UI {
var body: some View {
VStack(alignment: .center, spacing: 0) {
ZStack(alignment: .center) {
(self.viewModeIndex == 0 ? Color.gray.opacity(self.isHighlighted ? 1 : 0.7) : self.colour.opacity(self.isHighlighted ? 1 : 0.7))
(self.viewModeIndex == 0 ? Color.gray.opacity(self.isHighlighted ? 1 : 0.8) : self.colour.opacity(self.isHighlighted ? 1 : 0.8))
VStack(alignment: .center, spacing: 0) {
(self.isHighlighted ? self.type.selectedIcon : self.type.icon)
.symbolRenderingMode(.hierarchical)
.font(.largeTitle)
// .foregroundStyle(self.viewModeIndex == 0 ? self.colour : self.colour.isBright() ? Theme.base : .white)
.foregroundStyle(self.viewModeIndex == 0 ? self.colour : .white)
}
Spacer()
Expand All @@ -77,5 +76,101 @@ extension WidgetLibrary.UI {
.useDefaultHover({ hover in self.isHighlighted = hover })
}
}

struct GenericBlock: View {
@EnvironmentObject public var state: Navigation
public var item: NSManagedObject
@State private var bgColour: Color = .clear
@State private var name: String = ""
@State private var isHighlighted: Bool = false

var body: some View {
Button {
self.actionOnTap()
} label: {
HStack(alignment: .top, spacing: 10) {
Text(self.name)
.multilineTextAlignment(.leading)
Spacer()
Image(systemName: "chevron.right")
}
.padding(8)
.background(self.isHighlighted ? self.bgColour.opacity(1) : self.bgColour.opacity(0.8))
.foregroundStyle(self.bgColour.isBright() ? Theme.base : Theme.lightWhite)
.clipShape(.rect(cornerRadius: 5))
.help(self.name)
}
.contextMenu {
Button {
ClipboardHelper.copy(self.bgColour.description)
} label: {
Text("Copy colour HEX to clipboard")
}
}
.buttonStyle(.plain)
.useDefaultHover({ hover in self.isHighlighted = hover })
.onAppear(perform: self.actionOnAppear)
.onChange(of: self.item) { self.actionOnAppear() }
}
}
}
}

extension WidgetLibrary.UI.Blocks.GenericBlock {
/// Onload handler. Sets view state
/// - Returns: Void
private func actionOnAppear() -> Void {
if let job = self.item as? Job {
self.bgColour = job.backgroundColor
self.name = job.title ?? job.jid.string
} else if let project = self.item as? Project {
self.bgColour = project.backgroundColor
self.name = "\(project.name ?? "Error: Invalid project name") (\(project.abbreviation ?? "YYY"))"
} else if let company = self.item as? Company {
self.bgColour = company.backgroundColor
self.name = "\(company.name ?? "Error: Invalid company name") (\(company.abbreviation ?? "XXX"))"
} else if let note = self.item as? Note {
self.bgColour = note.mJob?.backgroundColor ?? Theme.rowColour
self.name = note.mJob?.title ?? note.mJob?.jid.string ?? "Error: Invalid job title"
} else if let task = self.item as? LogTask {
self.bgColour = task.owner?.backgroundColor ?? Theme.rowColour
self.name = "\(task.owner?.title ?? "Error: Invalid job title")"
} else if let record = self.item as? LogRecord {
self.bgColour = record.job?.backgroundColor ?? Theme.rowColour
self.name = record.job?.title ?? "Error: Invalid job title"
} else if let definition = self.item as? TaxonomyTermDefinitions {
self.bgColour = definition.job?.backgroundColor ?? Theme.rowColour
self.name = definition.job?.title ?? "Error: Invalid job title"
}
}

/// Fires when a block is tapped
/// - Returns: Void
private func actionOnTap() -> Void {
if let job = self.item as? Job {
self.state.session.job = job
self.state.session.project = job.project
self.state.session.company = job.project?.company
self.state.to(.jobs)
} else if let project = self.item as? Project {
self.state.session.project = project
self.state.session.company = project.company
self.state.to(.projectDetail)
} else if let company = self.item as? Company {
self.state.session.company = company
self.state.to(.companyDetail)
} else if let note = self.item as? Note {
self.state.session.note = note
self.state.to(.noteDetail)
} else if let task = self.item as? LogTask {
self.state.session.task = task
self.state.to(.taskDetail)
} else if let record = self.item as? LogRecord {
self.state.session.date = record.timestamp ?? Date()
self.state.to(.today)
} else if let definition = self.item as? TaxonomyTermDefinitions {
self.state.session.definition = definition
self.state.to(.definitionDetail)
}
}
}
66 changes: 66 additions & 0 deletions KWCore/Sources/UI/WidgetLibrary/WidgetLibrary.UI.Links.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// WidgetLibrary.UI.Links.swift
// KlockWork
//
// Created by Ryan Priebe on 2024-10-28.
// Copyright © 2024 YegCollective. All rights reserved.
//

import SwiftUI
import KWCore

extension WidgetLibrary.UI {
public struct Links {
struct ToProject: View {
@EnvironmentObject private var state: Navigation
public var entity: Project?
@State private var isHighlighted: Bool = false

var body: some View {
Button {
self.state.session.project = self.entity
self.state.to(.projectDetail)
} label: {
HStack(alignment: .top, spacing: 10) {
Image(systemName: self.isHighlighted ? "folder.fill" : "folder")
.symbolRenderingMode(.hierarchical)
.foregroundStyle(self.entity?.backgroundColor ?? Theme.lightWhite)

Text(self.entity?.name ?? "Error: Invalid project name")
Spacer()
}
.help("Go to \(self.entity?.name ?? "Error: Invalid project name")")
}
.buttonStyle(.plain)
.useDefaultHover({ hover in self.isHighlighted = hover})
.padding(.leading)
}
}

struct ToJob: View {
@EnvironmentObject private var state: Navigation
public var entity: Job?
@State private var isHighlighted: Bool = false

var body: some View {
Button {
self.state.session.job = self.entity
self.state.to(.jobs)
} label: {
HStack(alignment: .top, spacing: 10) {
Image(systemName: self.isHighlighted ? "folder.fill" : "folder")
.symbolRenderingMode(.hierarchical)
.foregroundStyle(self.entity?.backgroundColor ?? Theme.lightWhite)

Text(self.entity?.title ?? self.entity?.jid.string ?? "Error: Invalid job title and ID")
Spacer()
}
.help("Go to \(self.entity?.title ?? self.entity?.jid.string ?? "Error: Invalid job title and ID")")
}
.buttonStyle(.plain)
.useDefaultHover({ hover in self.isHighlighted = hover})
.padding(.leading)
}
}
}
}
4 changes: 2 additions & 2 deletions KWCore/Sources/UI/WidgetLibrary/WidgetLibrary.UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ extension WidgetLibrary {
}
}

struct Links: View {
struct LinkList: View {
@EnvironmentObject private var state: Navigation
@State private var links: Set<Link> = []
public var location: WidgetLocation
Expand Down Expand Up @@ -1390,7 +1390,7 @@ extension WidgetLibrary.UI.GroupHeaderContextMenu {
}
}

extension WidgetLibrary.UI.Links {
extension WidgetLibrary.UI.LinkList {
/// Onload handler. Starts monitoring keyboard for esc key
/// - Returns: Void
private func actionOnAppear() -> Void {
Expand Down
2 changes: 2 additions & 0 deletions KlockWork.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@
Sources/UI/WidgetLibrary/WidgetLibrary.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Buttons.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Individual.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Links.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Navigator.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Sidebar.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.swift,
Expand Down Expand Up @@ -592,6 +593,7 @@
Sources/UI/WidgetLibrary/WidgetLibrary.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Buttons.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Individual.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Links.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Navigator.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.Sidebar.swift,
Sources/UI/WidgetLibrary/WidgetLibrary.UI.swift,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct LogRow: View, Identifiable {
@State public var required: Set<RecordTableColumn> = [.message]
@State private var isDeleteAlertShowing: Bool = false
@State private var words: [CustomMessage] = []
@State private var isHighlighted: Bool = false

var body: some View {
if isEditing {
Expand All @@ -55,7 +56,7 @@ struct LogRow: View, Identifiable {
GridRow {
Column(
type: .index,
colour: (entry.jobObject != nil && entry.jobObject!.project != nil ? Color.fromStored(entry.jobObject!.project!.colour ?? Theme.rowColourAsDouble) : applyColour()),
colour: (entry.jobObject != nil && entry.jobObject!.project != nil ? Color.fromStored(entry.jobObject?.project?.colour ?? Theme.rowColourAsDouble).opacity(self.isHighlighted ? 1 : 0.8) : applyColour()),
textColour: self.colour.isBright() ? Theme.base : .white,
alignment: .center,
job: entry.jobObject,
Expand Down Expand Up @@ -112,6 +113,7 @@ struct LogRow: View, Identifiable {
)
}
.contextMenu { contextMenu }
.useDefaultHover({ hover in self.isHighlighted = hover })
}
.onAppear(perform: self.actionOnAppear)
.onChange(of: timestamp) {
Expand Down
4 changes: 2 additions & 2 deletions KlockWork/Views/Find/FindDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct FindDashboard: View {
LinearGradient(colors: [Theme.base, .clear], startPoint: .top, endPoint: .bottom)
.blendMode(.softLight)
.opacity(0.3)
UI.Links(location: self.location, isSearching: !searching && activeSearchText.count >= 2)
UI.LinkList(location: self.location, isSearching: !searching && activeSearchText.count >= 2)
}
.frame(height: 250)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ struct FindDashboard: View {
LinearGradient(colors: [Theme.base, .clear], startPoint: .top, endPoint: .bottom)
.blendMode(.softLight)
.opacity(0.3)
UI.Links(location: self.location, isSearching: !searching && activeSearchText.count >= 2)
UI.LinkList(location: self.location, isSearching: !searching && activeSearchText.count >= 2)
}
.frame(height: 300)
}
Expand Down
13 changes: 6 additions & 7 deletions KlockWork/Views/Find/Inspector/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extension Inspector {
noteReferences.insert(note as! Note)
}
}
default: print("DERPO failure")
default: print("[error] Inspector.Context Unable to inspect \(self.item)")
}
}
}
Expand All @@ -186,14 +186,13 @@ extension Inspector.Context {
}

private func actionShowPlan(_ day: Date) -> Void {
actionOnClick(day)
nav.to(.planning)
self.actionOnClick(day)
self.nav.to(.planning)
}

private func actionShowNote(_ note: Note) -> Void {
nav.session.search.cancel()
nav.setView(AnyView(NoteCreate(note: note)))
nav.setParent(.notes)
nav.setSidebar(AnyView(NoteCreateSidebar(note: note)))
self.nav.session.search.cancel()
self.nav.session.note = note
self.nav.to(.noteDetail)
}
}
Loading

0 comments on commit ddde747

Please sign in to comment.