gemenon

[ACTIVE] The Safari of the Gemini ecosystem
git clone git://git.figbert.com/gemenon.git
Log | Files | Refs

commit bc2ce27073cf4185cd4c344e84043f0c630e82f3
parent 1422f267fe33e0811b7351817278d94a88ac1921
Author: FIGBERT <figbert@figbert.com>
Date:   Fri, 30 Sep 2022 18:54:24 -0700

Add support for input status

Diffstat:
MShared/CapsuleView.swift | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 53 insertions(+), 9 deletions(-)

diff --git a/Shared/CapsuleView.swift b/Shared/CapsuleView.swift @@ -14,18 +14,32 @@ struct CapsuleView: View { if data.tab.home { StartPage() } else { - ScrollView { - HStack { - Spacer() - if data.tab.response?.body?.gemtext != nil { - VStack(alignment: .leading, spacing: 10) { - renderGemtext((data.tab.response?.body?.gemtext)!, url: data.tab.url) - } + switch data.tab.response?.status { + case .Input, .SensitiveInput: + InputView() + case .Success: + SuccessView() + default: + Text("boop") + } + } + } +} + +struct SuccessView: View { + @EnvironmentObject var data: BrowserData + var body: some View { + ScrollView { + HStack { + Spacer() + if data.tab.response?.body?.gemtext != nil { + VStack(alignment: .leading, spacing: 10) { + renderGemtext((data.tab.response?.body?.gemtext)!, url: data.tab.url) } - Spacer() } - .padding(.vertical) + Spacer() } + .padding(.vertical) } } @@ -80,6 +94,36 @@ struct CapsuleView: View { } } +struct InputView: View { + @EnvironmentObject var data: BrowserData + @State var input = "" + + var body: some View { + VStack(spacing: 40) { + VStack { + Text("\(data.tab.response?.status == .SensitiveInput ? "Sensitive " : "")Input") + .font(.system(size: 35, weight: .bold)) + if case .Prompt(let prompt) = data.tab.response?.header { + Text(prompt).font(.system(size: 15)) + } + } + + TextField("Type here", text: $input) + .frame(maxWidth: 500) + .textFieldStyle(.roundedBorder) + Button("Submit") { + Task { + var components = URLComponents(url: data.tab.url!, resolvingAgainstBaseURL: false) + components?.query = input + if let url = components?.url { + await data.openURL(url) + } + } + } + } + } +} + struct CapsuleView_Previews: PreviewProvider { static var previews: some View { CapsuleView()