summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-12 12:17:44 -0400
committerJune McEnroe <june@causal.agency>2020-07-12 12:17:44 -0400
commit7ff6e16e8ccda2433006f949ffc7b1ee5eaf08cf (patch)
tree03abf9d87da7810b364d27f97f9e541df9c9e46f /html.c
parentClean up page error handling (diff)
downloadscooper-7ff6e16e8ccda2433006f949ffc7b1ee5eaf08cf.tar.gz
scooper-7ff6e16e8ccda2433006f949ffc7b1ee5eaf08cf.zip
Reorganize code and add earlier messages link
Diffstat (limited to 'html.c')
-rw-r--r--html.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/html.c b/html.c
index 49b65e9..f5ea6bd 100644
--- a/html.c
+++ b/html.c
@@ -48,6 +48,30 @@ enum kcgi_err htmlHead(struct khtmlreq *html, const char *title) {
 		|| khtml_closeelem(html, 1);
 }
 
+enum kcgi_err htmlScopeFields(struct khtmlreq *html, struct Scope scope) {
+	if (scope.network) {
+		enum kcgi_err error = khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, Keys[Network].name,
+			KATTR_VALUE, scope.network,
+			KATTR__MAX
+		);
+		if (error) return error;
+	}
+	if (scope.context) {
+		enum kcgi_err error = khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, Keys[Context].name,
+			KATTR_VALUE, scope.context,
+			KATTR__MAX
+		);
+		if (error) return error;
+	}
+	return KCGI_OK;
+}
+
 enum kcgi_err
 htmlNav(struct khtmlreq *html, struct Scope scope) {
 	enum kcgi_err error = 0
@@ -97,7 +121,7 @@ htmlNav(struct khtmlreq *html, struct Scope scope) {
 		(scope.context ? scope.context : scope.network ? scope.network : "")
 	);
 
-	error = 0
+	return 0
 		|| khtml_closeelem(html, 1)
 		|| khtml_attr(
 			html, KELEM_FORM,
@@ -105,6 +129,7 @@ htmlNav(struct khtmlreq *html, struct Scope scope) {
 			KATTR_ACTION, Pages[Search],
 			KATTR__MAX
 		)
+		|| htmlScopeFields(html, scope)
 		|| khtml_attr(
 			html, KELEM_INPUT,
 			KATTR_TYPE, "search",
@@ -117,32 +142,8 @@ htmlNav(struct khtmlreq *html, struct Scope scope) {
 			KATTR_TYPE, "submit",
 			KATTR_VALUE, label,
 			KATTR__MAX
-		);
-	if (error) return error;
-
-	if (scope.network) {
-		error = khtml_attr(
-			html, KELEM_INPUT,
-			KATTR_TYPE, "hidden",
-			KATTR_NAME, Keys[Network].name,
-			KATTR_VALUE, scope.network,
-			KATTR__MAX
-		);
-		if (error) return error;
-	}
-
-	if (scope.context) {
-		error = khtml_attr(
-			html, KELEM_INPUT,
-			KATTR_TYPE, "hidden",
-			KATTR_NAME, Keys[Context].name,
-			KATTR_VALUE, scope.context,
-			KATTR__MAX
-		);
-		if (error) return error;
-	}
-
-	return khtml_closeelem(html, 2);
+		)
+		|| khtml_closeelem(html, 2);
 }
 
 static const char *SourceURL = "https://git.causal.agency/scooper";