~roselandgoose: 3 Create new hyphae from /edit Add 'Create new' button to top bar for non-anons in-line new hypha name field and fix HTML5 10 files changed, 89 insertions(+), 23 deletions(-)
Thank you! I have found the following issues: 1. On /edit, if I enter a name of a different existing hypha, the hypha's text will become emptied. An error should be shown instead, saying something like ‘Cannot create a hypha with a name that is taken already’ or something nicer. 2. When editing existing hyphae in the Russian locale, there is a space character lacking. So, instead of ‘Редактирование Home’ we have ‘РедактированиеHome’. Same for hypha creation. 3. The create button placement is indeed good, but: a. Well, it is in auth block, according to CSS. `auth-links__link auth-links__create-link` does not really fit the link. b. It shows English text in the Russian locale, but not on every page. c. I would recommend leaving it for later and focusing on making /edit work as intended. In the previous patch thread, you said:
I'm sorry! I meant a completely different thing. I wanted to say that <p> cannot be nested in <h1>. <input> in <p> is very nice actually! I propose to change the heading structure from ‘<input> in <div>/<p> in <h1>’ to just ‘<input> in <h1>’.
You can just return "" instead.
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~bouncepaw/mycorrhiza-devel/patches/37333/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 9596c00..4dabc3f 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
From: Rosie K Languet <rkl@rosiesworkshop.net> --- hypview/view_edit.html | 1 - viewutil/base.html | 4 +++- viewutil/viewutil.go | 27 ++++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/hypview/view_edit.html b/hypview/view_edit.html index 7967031..9d3dd88 100644 --- a/hypview/view_edit.html +++ b/hypview/view_edit.html @@ -42,7 +42,6 @@ <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"}} diff --git a/viewutil/base.html b/viewutil/base.html index 48ac707..0d0be4f 100644 --- a/viewutil/base.html +++ b/viewutil/base.html @@ -30,7 +30,9 @@ </form> </li> <li class="top-bar__section top-bar__section_auth"> - {{block "auth" .}}{{end}} + <ul class="top-bar__auth auth-links"> + {{block "auth" .}}{{end}} + </ul> </li> <li class="top-bar__section top-bar__section_highlights"> <ul class="top-bar__highlights"> diff --git a/viewutil/viewutil.go b/viewutil/viewutil.go index 25de03b..3881d78 100644 --- a/viewutil/viewutil.go +++ b/viewutil/viewutil.go @@ -43,10 +43,21 @@ func Init() { "inc": func(i int) int { return i + 1 }, }).ParseFS(fsys, "base.html")). Parse(dataText)) + + BaseEn = m(BaseEn.Parse(` +{{define "create"}}Create{{end}} +`)) + if cfg.UseAuth { BaseEn = m(BaseEn.Parse(` {{define "auth"}} -<ul class="top-bar__auth auth-links"> + {{if .Meta.U.Group | ne "anon" }} + <li class="auth-links__box auth-links__create-box"> + <a href="/edit" class="auth-links__link auth-links__create-link"> + {{template "create" .}} + </a> + </li> + {{end}} <li class="auth-links__box auth-links__user-box"> {{if .Meta.U.Group | eq "anon" }} <a href="/login" class="auth-links__link auth-links__login-link"> @@ -59,10 +70,20 @@ func Init() { {{end}} </li> {{block "registration" .}}{{end}} -</ul> {{end}} `)) - } + } else { + BaseEn = m(BaseEn.Parse(` +{{define "auth"}} + <li class="auth-links__box auth-links__create-box"> + <a href="/edit" class="auth-links__link auth-links__create-link"> + {{template "create" .}} + </a> + </li> +{{end}} +`)) +} + if cfg.AllowRegistration { m(BaseEn.Parse(`{{define "registration"}} {{if .Meta.U.Group | eq "anon"}} -- 2.34.5
From: Rosie K Languet <rkl@rosiesworkshop.net> --- hypview/view_edit.html | 16 ++++++++-------- static/default.css | 11 +++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/hypview/view_edit.html b/hypview/view_edit.html index 9d3dd88..7937105 100644 --- a/hypview/view_edit.html +++ b/hypview/view_edit.html @@ -58,11 +58,11 @@ {{if .IsNew}} {{if ne .HyphaName ""}} {{block "creating [[hypha]]" .HyphaName}} - {{template "create"}} <a href="/hypha/{{.}}">{{beautifulName .}}</a> + {{template "create"}} <div class="edit-form__name"><a href="/hypha/{{.}}">{{beautifulName .}}</a></div> {{end}} {{else}} {{template "create"}} - <p class="edit-form__message-zone"> + <div class="edit-form__message-zone edit-form__name"> <input id="name" type="text" @@ -71,16 +71,16 @@ class="edit-form__name" placeholder="{{block "new hypha name" .}}New hypha name{{end}}" aria-label="{{template "new hypha name" .}}"> - </p> + </div> {{end}} {{else}} {{block "editing [[hypha]]" .HyphaName}} - Edit <a href="/hypha/{{.}}">{{beautifulName .}}</a> + Edit <div class="edit-form__name"><a href="/hypha/{{.}}">{{beautifulName .}}</a></div> {{end}} {{end}} </h1> <textarea name="text" class="edit-form__textarea" autofocus>{{.Content}}</textarea> - <p class="edit-form__message-zone"> + <div class="edit-form__message-zone"> <input id="text" type="text" @@ -89,8 +89,8 @@ value="{{.Message}}" placeholder="{{block "describe your changes" .}}Describe your changes{{end}}" aria-label="{{template "describe your changes" .}}"> - </p> - <p class="edit-form__buttons"> + </div> + <div class="edit-form__buttons"> <button type="submit" name="action" class="btn btn_accent edit-form__save" value="save"> {{template "save" .}} </button> @@ -100,7 +100,7 @@ <a href="/hypha/{{.HyphaName}}" class="btn btn_weak"> {{template "cancel" .}} </a> - </p> + </div> </form> {{if .Preview}} <p class="warning"> diff --git a/static/default.css b/static/default.css index 4dabc3f..d0ade06 100644 --- a/static/default.css +++ b/static/default.css @@ -93,10 +93,17 @@ textarea {font-size:16px; font-family: inherit; line-height: 150%; } .edit_no-preview { height: 90vh; } .edit_with-preview .edit-form { height: 90vh; } -.edit__title { margin-top: 0; } +.edit__title { + margin-top: 0; + display: flex; + flex-direction: row; + align-items: center; + justify-content: start; +} +.edit-form .edit-form__name { margin: 0.25em; } .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 div { 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; } -- 2.34.5
Thank you! I have found the following issues: 1. On /edit, if I enter a name of a different existing hypha, the hypha's text will become emptied. An error should be shown instead, saying something like ‘Cannot create a hypha with a name that is taken already’ or something nicer. 2. When editing existing hyphae in the Russian locale, there is a space character lacking. So, instead of ‘Редактирование Home’ we have ‘РедактированиеHome’. Same for hypha creation. 3. The create button placement is indeed good, but: a. Well, it is in auth block, according to CSS. `auth-links__link auth-links__create-link` does not really fit the link. b. It shows English text in the Russian locale, but not on every page. c. I would recommend leaving it for later and focusing on making /edit work as intended. In the previous patch thread, you said:
I'm sorry! I meant a completely different thing. I wanted to say that <p> cannot be nested in <h1>. <input> in <p> is very nice actually! I propose to change the heading structure from ‘<input> in <div>/<p> in <h1>’ to just ‘<input> in <h1>’.
You can just return "" instead.