Add Start and Discuss buttons to lead suggestions

This commit is contained in:
Ian Gulliver
2026-10-17 08:10:55 -07:00
parent 62df39c5da
commit f5a495997f
16 changed files with 318 additions and 156 deletions
+25 -5
View File
@@ -21,6 +21,14 @@ enum AppLink {
c.queryItems = [URLQueryItem(name: "project", value: projectId), URLQueryItem(name: "title", value: title), URLQueryItem(name: "discuss", value: discuss ? "1" : "0")]
return c.url!
}
static func suggest(_ projectId: String, _ title: String, _ brief: String, discuss: Bool) -> URL {
var c = URLComponents()
c.scheme = "byre-app"
c.host = "suggest"
c.queryItems = [URLQueryItem(name: "project", value: projectId), URLQueryItem(name: "title", value: title), URLQueryItem(name: "brief", value: brief), URLQueryItem(name: "discuss", value: discuss ? "1" : "0")]
return c.url!
}
}
@MainActor
@@ -34,6 +42,12 @@ func openAppLink(_ url: URL, _ store: Store, _ overlays: Overlays) -> OpenURLAct
store.focusTask(q["id"] ?? "")
case "todo":
store.startTodo(q["project"] ?? "", q["title"] ?? "", discuss: q["discuss"] == "1", overlays)
case "suggest":
if q["discuss"] == "1" {
store.discussSuggestion(q["title"] ?? "", brief: q["brief"] ?? "", overlays)
} else {
store.startSuggestion(q["project"] ?? "", q["title"] ?? "", brief: q["brief"] ?? "", overlays)
}
default:
break
}
@@ -43,6 +57,7 @@ func openAppLink(_ url: URL, _ store: Store, _ overlays: Overlays) -> OpenURLAct
private let httpLink = Re(#"^https?://"#, caseless: true)
private let taskHref = Re(#"^#/task/(\w+)(/\w+)?$"#)
private let todoHref = Re(#"^#/todo/(\w+)/(.+)$"#)
private let suggestHref = Re(#"^#/suggest/(\w+)/([^/]+)/(.+)$"#)
@MainActor
struct InlineRenderer {
@@ -140,14 +155,18 @@ struct InlineRenderer {
return
}
if let m = todoHref.exec(href), let title = m[2]!.removingPercentEncoding {
todo(m[1]!, title, inner, style, &out)
todo(m[1]!, title, nil, inner, style, &out)
return
}
if let m = suggestHref.exec(href), let title = m[2]!.removingPercentEncoding, let brief = m[3]!.removingPercentEncoding {
todo(m[1]!, title, brief, inner, style, &out)
return
}
render(inner, style, &out)
}
private func todo(_ projectId: String, _ title: String, _ inner: [MDInline], _ style: Style, _ out: inout [MDSegment]) {
let task = (store.tasks[projectId] ?? []).first { $0.status == .active && $0.todoItem == title }
private func todo(_ projectId: String, _ title: String, _ brief: String?, _ inner: [MDInline], _ style: Style, _ out: inout [MDSegment]) {
let task = (store.tasks[projectId] ?? []).first { $0.status == .active && (brief == nil ? $0.todoItem == title : $0.title == title) }
var s = style
if let task {
s.color = taskPalette[task.color]
@@ -166,9 +185,10 @@ struct InlineRenderer {
append(run("starting…", Style(color: Palette.muted, small: true)), &out)
return
}
append(run("start", Style(link: AppLink.todo(projectId, title, discuss: false), color: Palette.accent, small: true)), &out)
let link = { (discuss: Bool) in brief.map { AppLink.suggest(projectId, title, $0, discuss: discuss) } ?? AppLink.todo(projectId, title, discuss: discuss) }
append(run("start", Style(link: link(false), color: Palette.accent, small: true)), &out)
append(run(" ", style), &out)
append(run("discuss", Style(link: AppLink.todo(projectId, title, discuss: true), color: Palette.accent, small: true)), &out)
append(run("discuss", Style(link: link(true), color: Palette.accent, small: true)), &out)
}
}