Skip to content

Commit

Permalink
Merge pull request #284 from aapis/feature/1.10/universal-header-ux
Browse files Browse the repository at this point in the history
Universal header UX improvements
  • Loading branch information
aapis authored Oct 9, 2024
2 parents 11de5fe + 6b73b8d commit c36cbaa
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 55 deletions.
34 changes: 2 additions & 32 deletions KlockWork/Views/Entities/Jobs/JobDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,6 @@ struct JobDashboardRedux: View {
var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 1) {
// HStack {
// Title(text: eType.label, imageAsImage: eType.icon)
// Spacer()
// FancyButtonv2(
// text: "Create",
// action: {
// editorVisible = true
// explorerVisible = false
//
// // Creates a new job entity so the user can customize it
// // @TODO: move to new method CoreDataJobs.create
// let newJob = Job(context: moc)
// newJob.id = UUID()
// newJob.jid = 1.0
// newJob.colour = Color.randomStorable()
// newJob.alive = true
// newJob.project = CoreDataProjects(moc: moc).alive().first(where: {$0.company?.isDefault == true})
// newJob.created = Date()
// newJob.lastUpdate = newJob.created
// newJob.overview = ""
// newJob.title = ""
// nav.session.job = newJob
// nav.forms.tp.editor.job = newJob
// },
// icon: "plus",
// showLabel: false
// )
// }
//
// FancyDivider()

UniversalHeader.Widget(
type: self.eType,
buttons: AnyView(
Expand Down Expand Up @@ -296,7 +265,7 @@ struct JobExplorer: View {
FancyDivider()
HStack(alignment: .bottom) {
FancySimpleButton(text: "Delete", action: {isDeletePresented = true}, icon: "trash", showLabel: false, showIcon: true, type: .destructive)
.alert("Are you sure you want to delete job ID \(job!.jid.string)? This is irreversible.", isPresented: $isDeletePresented) {
.alert("Are you sure you want to delete this job? This is irreversible.", isPresented: $isDeletePresented) {
Button("Yes", role: .destructive) {
self.triggerDelete()
}
Expand All @@ -315,6 +284,7 @@ struct JobExplorer: View {
}
}
.onAppear(perform: self.actionOnAppear)
.onChange(of: self.nav.session.job) { self.actionOnAppear() }
}

struct SaveMessage: View {
Expand Down
2 changes: 1 addition & 1 deletion KlockWork/Views/Find/FindDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct FindDashboard: View {
private var columns: [GridItem] {
Array(repeating: .init(.flexible(minimum: 100)), count: 2)
}
private let eType: PageConfiguration.EntityType = .notes
private let eType: PageConfiguration.EntityType = .BruceWillis

var body: some View {
Grid(alignment: .topLeading, horizontalSpacing: 0, verticalSpacing: 0) {
Expand Down
2 changes: 1 addition & 1 deletion KlockWork/Views/Planning/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Planning: View {
private let maxItems: Int = 6
private let title: String = "Planning"
private let page: PageConfiguration.AppPage = .planning
private let eType: PageConfiguration.EntityType = .tasks
private let eType: PageConfiguration.EntityType = .BruceWillis
private let description: String = "Use the daily plan to organize your day, Upcoming to find out what's next, and Overdue to see what you've missed."
private let buttons: [ToolbarButton] = [
ToolbarButton(
Expand Down
89 changes: 68 additions & 21 deletions KlockWork/Views/Shared/UniversalHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct UniversalHeader: View {
Item(text: "...")
]
public var title: String? = ""
public var entityType: PageConfiguration.EntityType

var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
Expand All @@ -42,28 +43,37 @@ struct UniversalHeader: View {
@EnvironmentObject public var state: Navigation
public var id: UUID = UUID()
public var text: String
public var target: Page = .today
public var helpText: String = ""
public var target: Page?
@State private var isHighlighted: Bool = false

var body: some View {
HStack(alignment: .center) {
Button {
self.state.to(self.target)
} label: {
Text(self.text)
.underline(self.isHighlighted && self.target != .today) // using .today as "default"
.foregroundStyle((self.state.session.job?.backgroundColor ?? Theme.rowColour).isBright() ? Theme.base.opacity(0.55) : .white.opacity(0.55))
.multilineTextAlignment(.leading)
}
.buttonStyle(.plain)
.disabled(self.target == .today)
if self.target == nil {
self.ItemText
.opacity(0.5)
} else {
Button {
self.state.to(self.target!)
} label: {
self.ItemText
}
.useDefaultHover({ hover in self.isHighlighted = hover})
.help(self.helpText)
.buttonStyle(.plain)
.disabled(self.target! == .today)

if [.companyDetail, .projectDetail, .today, .jobs].contains(where: {$0 == self.target}) {
Image(systemName: "chevron.right")
.foregroundStyle((self.state.session.job?.backgroundColor ?? Theme.rowColour).isBright() ? Theme.base.opacity(0.3) : .white.opacity(0.3))
}
}
.useDefaultHover({ hover in self.isHighlighted = hover})
}

@ViewBuilder var ItemText: some View {
Text(self.text)
.underline(self.isHighlighted && self.target != .today) // using .today as "default"
.foregroundStyle(self.isHighlighted ? (self.state.session.job?.backgroundColor ?? Theme.rowColour).isBright() ? Theme.base : .white : (self.state.session.job?.backgroundColor ?? Theme.rowColour).isBright() ? Theme.base.opacity(0.55) : .white.opacity(0.55))
.multilineTextAlignment(.leading)
}
}

Expand All @@ -84,7 +94,7 @@ struct UniversalHeader: View {

VStack(alignment: .leading) {
HStack(alignment: .top) {
UniversalHeader(title: self.title)
UniversalHeader(title: self.title, entityType: self.type)

HStack(alignment: .center) {
Spacer()
Expand All @@ -102,7 +112,7 @@ struct UniversalHeader: View {
TypedListRowBackground(colour: self.state.session.job?.backgroundColor ?? Theme.rowColour, type: self.type)
.frame(height: 60)
.clipShape(.rect(topLeadingRadius: 5, topTrailingRadius: 5))
UniversalHeader(title: self.title)
UniversalHeader(title: self.title, entityType: self.type)
.padding(.leading)
HStack(alignment: .center) {
Spacer()
Expand All @@ -123,21 +133,58 @@ extension UniversalHeader {
private func actionSetViewState() -> Void {
self.parts = []
if let job = self.state.session.job {
self.parts.append(Item(text: job.project?.company?.abbreviation ?? job.project?.company?.name ?? "", target: self.state.session.company?.pageDetailType ?? .dashboard))
self.parts.append(Item(text: job.project?.abbreviation ?? job.project?.name ?? "", target: self.state.session.project?.pageDetailType ?? .dashboard))
self.parts.append(Item(text: job.title ?? job.jid.string, target: job.pageDetailType))
self.parts.append(contentsOf: [
Item(
text: job.project?.company?.abbreviation ?? job.project?.company?.name ?? "",
helpText: job.project?.company?.name ?? "",
target: self.state.session.company?.pageDetailType ?? .dashboard
),
Item(
text: job.project?.abbreviation ?? job.project?.name ?? "",
helpText: job.project?.name ?? "",
target: self.state.session.project?.pageDetailType ?? .dashboard
),
Item(
text: job.title ?? job.jid.string,
helpText: job.title ?? job.jid.string,
target: job.pageDetailType
),
Item(
// Sets last breadcrumb item text to page title (instead of entity type label) when Bruce says "It's time to DIE HARD"
text: self.entityType == .BruceWillis ? self.state.parent?.defaultTitle ?? "" : self.entityType.label
)
]
)
} else {
if let company = self.state.session.company {
self.parts = []
if company.name != nil {
self.parts.append(Item(text: company.abbreviation ?? company.name ?? "", target: company.pageDetailType))
self.parts.append(
Item(
text: company.abbreviation ?? company.name ?? "",
helpText: company.name ?? "",
target: company.pageDetailType
)
)
}
}
if let project = self.state.session.project {
self.parts = []
if project.name != nil && project.company != nil {
self.parts.append(Item(text: project.company!.abbreviation ?? project.company!.name ?? "", target: project.company!.pageDetailType))
self.parts.append(Item(text: project.abbreviation ?? project.name ?? "", target: project.pageDetailType))
self.parts.append(
Item(
text: project.company!.abbreviation ?? project.company!.name ?? "",
helpText: project.company?.name ?? "",
target: project.company!.pageDetailType
)
)
self.parts.append(
Item(
text: project.abbreviation ?? project.name ?? "",
helpText: project.name ?? "",
target: project.pageDetailType
)
)
}
}
}
Expand Down

0 comments on commit c36cbaa

Please sign in to comment.