I have made better use of templates to address the Russian locale issue, although since I don't speak russian I expect that my copying the translation of "new name" for use as "new hypha name" can be improved upon. Note that although it is now styled the same as all other input text fields, the new hypha name input is still inside the h1 create tag. This seemed more semantically correct to me 🤷, but I haven't consulted accessibility guidelines so let me know if that needs to be moved out of the h1 tag. Lastly now that the new name field is required, the handler doesn't have any special behavior if the required field is somehow left out or sent empty. I haven't tested what would happen in that case. Let me know if I should. Thanks! Rosie K Languet (1): Create new hyphae from /edit hypview/hypview.go | 2 ++ hypview/view_edit.html | 19 +++++++++++++++++-- static/default.css | 1 + util/util.go | 18 +++++++++++++++--- web/mutators.go | 13 ++++++++++--- 5 files changed, 45 insertions(+), 8 deletions(-) -- 2.34.5
Thank you! I have found the following issues: 1. You have wrapped the input field in the <p> tag. a. It is on its own line, which does not really make sense on a wider screen. It should be part of the first line, I think. b. This is invalid HTML5. 2. The form accepts empty names such as ‘ ’ or ‘_’, which are in no way different from ‘’.
Re: 2. I have mistaken, it shows an error, as it should. Even if someone removes the `required` part, the error is still shown, so this part is good. I should get some sleep.
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~bouncepaw/mycorrhiza-devel/patches/37115/mbox | git am -3Learn more about email & git
From: Rosie K Languet <rkl@rosiesworkshop.net> This modifies handlerEdit to include a Name input field when one is not given in the url. It starts implementing the first part of bouncepaw's first bullet point: https://github.com/bouncepaw/mycorrhiza/issues/124#issuecomment-1219453093 --- hypview/hypview.go | 2 ++ hypview/view_edit.html | 19 +++++++++++++++++-- static/default.css | 1 + util/util.go | 18 +++++++++++++++--- web/mutators.go | 13 ++++++++++--- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/hypview/hypview.go b/hypview/hypview.go index c2abb38..c73553a 100644 --- a/hypview/hypview.go +++ b/hypview/hypview.go @@ -17,8 +17,10 @@ var ( ruTranslation = ` {{define "editing hypha"}}Редактирование {{beautifulName .}}{{end}} {{define "editing [[hypha]]"}}Редактирование <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}} +{{define "create"}}Создать{{end}} {{define "creating [[hypha]]"}}Создание <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}} {{define "you're creating a new hypha"}}Вы создаёте новую гифу.{{end}} +{{define "new hypha name"}}Новое название{{end}} {{define "describe your changes"}}Опишите ваши правки{{end}} {{define "save"}}Сохранить{{end}} {{define "preview"}}Предпросмотр{{end}} diff --git a/hypview/view_edit.html b/hypview/view_edit.html index dd6bdc9..7967031 100644 --- a/hypview/view_edit.html +++ b/hypview/view_edit.html @@ -42,6 +42,7 @@ <script src="/static/toolbar.js"></script> {{end}} +{{define "create"}}Create{{end}} {{define "editing hypha"}}Edit {{beautifulName .}}{{end}} {{define "previewing hypha"}}Preview of {{beautifulName .}}{{end}} {{define "title"}} @@ -56,8 +57,22 @@ <form method="post" class="edit-form" action="/upload-text/{{.HyphaName}}"> <h1 class="edit__title"> {{if .IsNew}} - {{block "creating [[hypha]]" .HyphaName}} - Create <a href="/hypha/{{.}}">{{beautifulName .}}</a> + {{if ne .HyphaName ""}} + {{block "creating [[hypha]]" .HyphaName}} + {{template "create"}} <a href="/hypha/{{.}}">{{beautifulName .}}</a> + {{end}} + {{else}} + {{template "create"}} + <p class="edit-form__message-zone"> + <input + id="name" + type="text" + name="name" + required + class="edit-form__name" + placeholder="{{block "new hypha name" .}}New hypha name{{end}}" + aria-label="{{template "new hypha name" .}}"> + </p> {{end}} {{else}} {{block "editing [[hypha]]" .HyphaName}} diff --git a/static/default.css b/static/default.css index 8d09d53..0cc496f 100644 --- a/static/default.css +++ b/static/default.css @@ -97,6 +97,7 @@ textarea {font-size:16px; font-family: inherit; line-height: 150%; } .edit__preview { border: 2px dashed #ddd; padding: 10px; margin: 0 -10px; } .edit-form__textarea { width: 100%; height: 80vh; min-height: 4rem; } .edit-form p { margin: .25rem 0; } +.edit-form__message-zone { font-size:16px; font-weight: normal; } .edit-form__message { width: 100%; margin: 0.25em 0; } .edit-form__save { font-weight: bold; } .edit-toolbar__buttons, .edit-toolbar__help { margin: .5rem; } diff --git a/util/util.go b/util/util.go index a00230c..04fac06 100644 --- a/util/util.go +++ b/util/util.go @@ -71,16 +71,28 @@ func IsProfileName(hyphaName string) bool { return strings.HasPrefix(hyphaName, cfg.UserHypha+"/") && strings.Count(hyphaName, "/") == 1 } -// HyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha". + // HyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha". When the url contains no hypha name, the configured HomeHypha is returned. func HyphaNameFromRq(rq *http.Request, actions ...string) string { + name := OptionalHyphaNameFromRq(rq, actions...) + if name == "" { + log.Println("HyphaNameFromRq: this request is invalid, fall back to home hypha") + return cfg.HomeHypha + } + return name +} + +// OptionalHyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha". +func OptionalHyphaNameFromRq(rq *http.Request, actions ...string) string { p := rq.URL.Path for _, action := range actions { if strings.HasPrefix(p, "/"+action+"/") { return CanonicalName(strings.TrimPrefix(p, "/"+action+"/")) } + if p == "/"+action { + break + } } - log.Println("HyphaNameFromRq: this request is invalid, fall back to home hypha") - return cfg.HomeHypha + return CanonicalName("") } // FormData is a convenient struct for passing user input and errors to HTML diff --git a/web/mutators.go b/web/mutators.go index e85ddda..e659865 100644 --- a/web/mutators.go +++ b/web/mutators.go @@ -22,7 +22,7 @@ import ( ) func initMutators(r *mux.Router) { - r.PathPrefix("/edit/").HandlerFunc(handlerEdit) + r.PathPrefix("/edit").HandlerFunc(handlerEdit) r.PathPrefix("/rename/").HandlerFunc(handlerRename).Methods("GET", "POST") r.PathPrefix("/delete/").HandlerFunc(handlerDelete).Methods("GET", "POST") r.PathPrefix("/remove-media/").HandlerFunc(handlerRemoveMedia).Methods("GET", "POST") @@ -145,7 +145,7 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) { lc = l18n.FromRequest(rq) meta = viewutil.MetaFrom(w, rq) - hyphaName = util.HyphaNameFromRq(rq, "edit") + hyphaName = util.OptionalHyphaNameFromRq(rq, "edit") h = hyphae.ByName(hyphaName) isNew bool @@ -179,7 +179,14 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) { u = user.FromRequest(rq) meta = viewutil.MetaFrom(w, rq) - hyphaName = util.HyphaNameFromRq(rq, "upload-text") + hyphaName = util.OptionalHyphaNameFromRq(rq, "upload-text") + ) + + if hyphaName == "" { + hyphaName = util.CanonicalName(rq.PostFormValue("name")) + } + + var ( h = hyphae.ByName(hyphaName) _, isNew = h.(*hyphae.EmptyHypha) -- 2.34.5
Thank you! I have found the following issues: 1. You have wrapped the input field in the <p> tag. a. It is on its own line, which does not really make sense on a wider screen. It should be part of the first line, I think. b. This is invalid HTML5. 2. The form accepts empty names such as ‘ ’ or ‘_’, which are in no way different from ‘’.