Skip to content

Commit

Permalink
Move search form to a dedicated page
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Mar 2, 2024
1 parent 1b5edfc commit 90f386e
Show file tree
Hide file tree
Showing 27 changed files with 148 additions and 199 deletions.
1 change: 1 addition & 0 deletions internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Über",
"menu.export": "Exportieren",
"menu.import": "Importieren",
"menu.search": "Suche",
"menu.create_category": "Kategorie anlegen",
"menu.mark_page_as_read": "Diese Seite als gelesen markieren",
"menu.mark_all_as_read": "Alle als gelesen markieren",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/el_EL.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Περί",
"menu.export": "Εξαγωγή",
"menu.import": "Εισαγωγή",
"menu.search": "Αναζήτηση",
"menu.create_category": "Δημιουργήστε μια κατηγορία",
"menu.mark_page_as_read": "Σημείωση αυτής της σελίδας ως αναγνωσμένη",
"menu.mark_all_as_read": "Σημείωση όλων ως αναγνωσμένα",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "About",
"menu.export": "Export",
"menu.import": "Import",
"menu.search": "Search",
"menu.create_category": "Create a category",
"menu.mark_page_as_read": "Mark this page as read",
"menu.mark_all_as_read": "Mark all as read",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Acerca de",
"menu.export": "Exportar",
"menu.import": "Importar",
"menu.search": "Buscar",
"menu.create_category": "Crear una categoría",
"menu.mark_page_as_read": "Marcar esta página como leída",
"menu.mark_all_as_read": "Marcar todos como leídos",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Tietoja",
"menu.export": "Vie",
"menu.import": "Tuo",
"menu.search": "Haku",
"menu.create_category": "Luo kategoria",
"menu.mark_page_as_read": "Merkitse tämä sivu luetuksi",
"menu.mark_all_as_read": "Merkitse kaikki luetuksi",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "À propos",
"menu.export": "Export",
"menu.import": "Import",
"menu.search": "Recherche",
"menu.create_category": "Créer une catégorie",
"menu.mark_page_as_read": "Marquer cette page comme lu",
"menu.mark_all_as_read": "Tout marquer comme lu",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "के बारे में",
"menu.export": "निर्यात करे",
"menu.import": "आयात करे",
"menu.search": "खोज",
"menu.create_category": "श्रेणी बनाए",
"menu.mark_page_as_read": "इस पृष्ठ को पढ़ा हुआ चिह्नित करें",
"menu.mark_all_as_read": "सभी को पढ़ा हुआ मार्क करें",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Tentang",
"menu.export": "Ekspor",
"menu.import": "Impor",
"menu.search": "Cari",
"menu.create_category": "Buat kategori",
"menu.mark_page_as_read": "Tandai halaman ini sebagai telah dibaca",
"menu.mark_all_as_read": "Tandai semua sebagai telah dibaca",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Informazioni",
"menu.export": "Esporta",
"menu.import": "Importa",
"menu.search": "Cerca",
"menu.create_category": "Aggiungi una categoria",
"menu.mark_page_as_read": "Segna questa pagina come letta",
"menu.mark_all_as_read": "Segna tutti gli articoli come letti",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "ソフトウェア情報",
"menu.export": "エクスポート",
"menu.import": "インポート",
"menu.search": "検索",
"menu.create_category": "カテゴリを作成",
"menu.mark_page_as_read": "このページを既読にする",
"menu.mark_all_as_read": "すべて既読にする",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/nl_NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Over",
"menu.export": "Exporteren",
"menu.import": "Importeren",
"menu.search": "Zoeken",
"menu.create_category": "Categorie toevoegen",
"menu.mark_page_as_read": "Markeer deze pagina als gelezen",
"menu.mark_all_as_read": "Markeer alle items als gelezen",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "O stronie",
"menu.export": "Eksportuj",
"menu.import": "Importuj",
"menu.search": "Szukaj",
"menu.create_category": "Utwórz kategorię",
"menu.mark_page_as_read": "Oznacz jako przeczytane",
"menu.mark_all_as_read": "Oznacz wszystko jako przeczytane",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Sobre",
"menu.export": "Exportar",
"menu.import": "Importar",
"menu.search": "Buscar",
"menu.create_category": "Criar uma categoria",
"menu.mark_page_as_read": "Marcar essa página como lida",
"menu.mark_all_as_read": "Marcar todos como lido",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "О приложении",
"menu.export": "Экспорт",
"menu.import": "Импорт",
"menu.search": "Поиск",
"menu.create_category": "Создать категорию",
"menu.mark_page_as_read": "Отметить эту страницу прочитанной",
"menu.mark_all_as_read": "Отметить всё как прочитанное",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/tr_TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Hakkında",
"menu.export": "Dışarı Aktar",
"menu.import": "İçeri Aktar",
"menu.search": "Ara",
"menu.create_category": "Kategori oluştur",
"menu.mark_page_as_read": "Bu sayfayı okundu olarak işaretle",
"menu.mark_all_as_read": "Tümünü okundu olarak işaretle",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/uk_UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "Про додаток",
"menu.export": "Експорт",
"menu.import": "Імпорт",
"menu.search": "Пошук",
"menu.create_category": "Створити категорію",
"menu.mark_page_as_read": "Відмітити цю сторінку як прочитане",
"menu.mark_all_as_read": "Відмітити все як прочитане",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "关于",
"menu.export": "导出",
"menu.import": "导入",
"menu.search": "搜索",
"menu.create_category": "新建分类",
"menu.mark_page_as_read": "标记为已读",
"menu.mark_all_as_read": "全部标为已读",
Expand Down
1 change: 1 addition & 0 deletions internal/locale/translations/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"menu.about": "關於",
"menu.export": "匯出",
"menu.import": "匯入",
"menu.search": "搜尋",
"menu.create_category": "新建分類",
"menu.mark_page_as_read": "將此頁面標記為已讀",
"menu.mark_all_as_read": "全部標為已讀",
Expand Down
18 changes: 3 additions & 15 deletions internal/template/templates/common/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
{{ if .user }}{{ if not .user.KeyboardShortcuts }}data-disable-keyboard-shortcuts="true"{{ end }}{{ end }}>

{{ if .user }}

<a class="skip-to-content-link" href="#main">{{ t "skip_to_content" }}</a>
<header class="header">
<nav>
Expand Down Expand Up @@ -105,6 +104,9 @@
<li {{ if eq .menu "categories" }}class="active"{{ end }} title="{{ t "tooltip.keyboard_shortcuts" "g c" }}">
<a href="{{ route "categories" }}" data-page="categories">{{ t "menu.categories" }}</a>
</li>
<li {{ if eq .menu "search" }}class="active"{{ end }} title="{{ t "tooltip.keyboard_shortcuts" "/" }}">
<a href="{{ route "search" }}" data-page="search">{{ t "menu.search" }}</a>
</li>
<li {{ if eq .menu "settings" }}class="active"{{ end }} title="{{ t "tooltip.keyboard_shortcuts" "g s" }}">
<a href="{{ route "settings" }}" data-page="settings">{{ t "menu.settings" }}</a>
</li>
Expand All @@ -115,20 +117,6 @@
{{ end }}
</ul>
</nav>
<search role="search" class="search">
<details class="search-details" {{ if $.searchQuery }}open{{ end }}>
<summary class="search-summary">
<span>{{ t "search.label" }}</span>
<svg class="bi bi-chevron-down search-summary-icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708"/>
</svg>
</summary>
<form action="{{ route "searchEntries" }}" aria-labelledby="search-input-label">
<input type="search" name="q" id="search-input" aria-label="{{ t "search.label" }}" placeholder="{{ t "search.placeholder" }}" {{ if $.searchQuery }}value="{{ .searchQuery }}"{{ end }} required>
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.loading" }}">{{ t "search.submit" }}</button>
</form>
</details>
</search>
</header>
{{ end }}
{{ if .flashMessage }}
Expand Down
57 changes: 57 additions & 0 deletions internal/template/templates/views/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{ define "title"}}{{ t "page.search.title" }} ({{ .total }}){{ end }}

{{ define "page_header"}}
<section class="page-header" aria-labelledby="page-header-title">
<h1 id="page-header-title">{{ t "page.search.title" }} ({{ .total }})</h1>
</section>
{{ end }}

{{ define "content"}}
<search role="search">
<form action="{{ route "search" }}" aria-labelledby="search-input-label">
<input type="search" name="q" id="search-input" aria-label="{{ t "search.label" }}" placeholder="{{ t "search.placeholder" }}" {{ if $.searchQuery }}value="{{ .searchQuery }}"{{ else }}autofocus{{ end }} required>
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.loading" }}">{{ t "search.submit" }}</button>
</form>
</search>

{{ if $.searchQuery }}
{{ if not .entries }}
<p role="alert" class="alert alert-info">{{ t "alert.no_search_result" }}</p>
{{ else }}
<div class="pagination-top">
{{ template "pagination" .pagination }}
</div>
<div class="items">
{{ range .entries }}
<article
class="item entry-item {{ if $.user.EntrySwipe }}entry-swipe{{ end }} item-status-{{ .Status }}"
data-id="{{ .ID }}"
aria-labelledby="entry-title-{{ .ID }}"
>
<header class="item-header" dir="auto">
<h2 id="entry-title-{{ .ID }}" class="item-title">
<a href="{{ route "searchEntry" "entryID" .ID }}?q={{ $.searchQuery }}">
{{ if ne .Feed.Icon.IconID 0 }}
<img src="{{ route "icon" "iconID" .Feed.Icon.IconID }}" width="16" height="16" loading="lazy" alt="{{ .Feed.Title }}">
{{ else }}
<span class="sr-only">{{ .Feed.Title }}</span>
{{ end }}
{{ .Title }}
</a>
</h2>
<span class="category">
<a href="{{ route "categoryEntries" "categoryID" .Feed.Category.ID }}">
{{ .Feed.Category.Title }}
</a>
</span>
</header>
{{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }}
</article>
{{ end }}
</div>
<div class="pagination-bottom">
{{ template "pagination" .pagination }}
</div>
{{ end }}
{{ end }}
{{ end }}
49 changes: 0 additions & 49 deletions internal/template/templates/views/search_entries.html

This file was deleted.

42 changes: 24 additions & 18 deletions internal/ui/search_entries.go → internal/ui/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"miniflux.app/v2/internal/ui/view"
)

func (h *handler) showSearchEntriesPage(w http.ResponseWriter, r *http.Request) {
func (h *handler) showSearchPage(w http.ResponseWriter, r *http.Request) {
user, err := h.store.UserByID(request.UserID(r))
if err != nil {
html.ServerError(w, r, err)
Expand All @@ -23,38 +23,44 @@ func (h *handler) showSearchEntriesPage(w http.ResponseWriter, r *http.Request)

searchQuery := request.QueryStringParam(r, "q", "")
offset := request.QueryIntParam(r, "offset", 0)
builder := h.store.NewEntryQueryBuilder(user.ID)
builder.WithSearchQuery(searchQuery)
builder.WithoutStatus(model.EntryStatusRemoved)
builder.WithOffset(offset)
builder.WithLimit(user.EntriesPerPage)

entries, err := builder.GetEntries()
if err != nil {
html.ServerError(w, r, err)
return
}
var entries model.Entries
var entriesCount int

count, err := builder.CountEntries()
if err != nil {
html.ServerError(w, r, err)
return
if searchQuery != "" {
builder := h.store.NewEntryQueryBuilder(user.ID)
builder.WithSearchQuery(searchQuery)
builder.WithoutStatus(model.EntryStatusRemoved)
builder.WithOffset(offset)
builder.WithLimit(user.EntriesPerPage)

entries, err = builder.GetEntries()
if err != nil {
html.ServerError(w, r, err)
return
}

entriesCount, err = builder.CountEntries()
if err != nil {
html.ServerError(w, r, err)
return
}
}

sess := session.New(h.store, request.SessionID(r))
view := view.New(h.tpl, r, sess)
pagination := getPagination(route.Path(h.router, "searchEntries"), count, offset, user.EntriesPerPage)
pagination := getPagination(route.Path(h.router, "search"), entriesCount, offset, user.EntriesPerPage)
pagination.SearchQuery = searchQuery

view.Set("searchQuery", searchQuery)
view.Set("entries", entries)
view.Set("total", count)
view.Set("total", entriesCount)
view.Set("pagination", pagination)
view.Set("menu", "search")
view.Set("user", user)
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
view.Set("hasSaveEntry", h.store.HasSaveEntry(user.ID))

html.OK(w, r, view.Render("search_entries"))
html.OK(w, r, view.Render("search"))
}
Loading

0 comments on commit 90f386e

Please sign in to comment.