Skip to content

Commit ceb64f2

Browse files
committed
Merge #598: Fix permanent link to search result
de44e47 fix: [#593] permanent link to search result (Jose Celano) Pull request description: This fixes loading the search term from the GET parameter in the URL before loading the torrents list from the API. ACKs for top commit: josecelano: ACK de44e47 Tree-SHA512: daffbaeb15a53b2177d42f5e1791b293c277cb4b8e985b7ed9c7c082530168ff382c00bd8806c3372cd1bbf0a5f54f2b2def61694520c201fd233fe99b12a373
2 parents b91f1f4 + de44e47 commit ceb64f2

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

components/navigation/NavigationBar.vue

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
<NuxtLink to="/" class="flex flex-row text-xl normal-case btn btn-ghost">
88
<span>{{ settings?.website_name || "Torrust" }}</span>
99
</NuxtLink>
10-
<div class="hidden form-control md:flex">
11-
<input
12-
v-model="searchQuery"
13-
name="search"
14-
type="text"
15-
class="border-2 input input-bordered rounded-2xl placeholder-neutral-content"
16-
:placeholder="`Search torrents`"
17-
@keyup.enter="submitSearch"
18-
@focusin="typingInSearch = true"
19-
@focusout="typingInSearch = false"
20-
>
21-
</div>
2210
<div class="flex-none gap-2 ml-auto">
2311
<template v-if="user">
2412
<NuxtLink id="upload-button" to="/upload" class="hidden md:flex btn bg-base-100 rounded-2xl">
@@ -56,18 +44,6 @@
5644
<template v-if="!mobileCollapsed">
5745
<div class="items-center justify-between w-full py-4 md:hidden">
5846
<div class="flex flex-row gap-2">
59-
<div class="w-full form-control">
60-
<input
61-
v-model="searchQuery"
62-
name="search"
63-
type="text"
64-
class="border-2 input input-bordered"
65-
:placeholder="`Search ${settings?.website_name ?? 'Torrust'}`"
66-
@keyup.enter="submitSearch"
67-
@focusin="typingInSearch = true"
68-
@focusout="typingInSearch = false"
69-
>
70-
</div>
7147
<button class="btn btn-square btn-ghost" @click="submitSearch">
7248
<MagnifyingGlassIcon class="w-6" />
7349
</button>
@@ -104,17 +80,6 @@ const settings: PublicSettings = useSettings().value;
10480
const user = useUser();
10581
10682
const mobileCollapsed = ref(true);
107-
const searchQuery: Ref<string> = ref("");
108-
const typingInSearch = ref(false);
109-
110-
function submitSearch () {
111-
navigateTo({
112-
path: "/torrents",
113-
query: {
114-
search: searchQuery.value ?? null
115-
}
116-
});
117-
}
11883
11984
</script>
12085

pages/torrents.vue

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
<div class="flex w-full">
44
<div class="flex flex-wrap justify-between w-full gap-2">
55
<div class="flex flex-wrap gap-2">
6+
<input
7+
v-model="searchQuery"
8+
name="search"
9+
type="text"
10+
class="border-2 input input-bordered rounded-2xl placeholder-neutral-content"
11+
:placeholder="`Search torrents`"
12+
@keyup.enter="submitSearch"
13+
>
14+
15+
</div>
16+
<div class="flex flex-wrap gap-1">
617
<TorrustSelect
718
v-model:selected="categoryFilters"
819
:options="categories.map(entry => ({ name: entry.name, value: entry.name }))"
@@ -17,8 +28,6 @@
1728
:multiple="true"
1829
search
1930
/>
20-
</div>
21-
<div>
2231
<TorrustSelect v-model:selected="selectedSorting" class="ml-auto" :options="sortingOptions" label="Sort by" />
2332
</div>
2433
</div>
@@ -102,7 +111,13 @@ const selectedSorting = computed({
102111
});
103112
104113
watch(() => route.fullPath, () => {
105-
searchQuery.value = route.query.search as string;
114+
searchQuery.value = route.query.search as string ?? null;
115+
itemsSorting.value = route.query.sorting as string ?? null;
116+
pageSize.value = route.query.pageSize as number ?? null;
117+
currentPage.value = route.query.page as number ?? null;
118+
layout.value = route.query.layout as string ?? null;
119+
categoryFilters.value = route.query.categoryFilters as string[] ?? null;
120+
tagFilters.value = route.query.tagFilters as string[] ?? null;
106121
});
107122
108123
watch([searchQuery, itemsSorting, pageSize, currentPage, layout, categoryFilters, tagFilters], () => {
@@ -123,12 +138,34 @@ watch([searchQuery, itemsSorting, pageSize, currentPage, layout, categoryFilters
123138
124139
onActivated(() => {
125140
searchQuery.value = route.query.search as string ?? null;
141+
itemsSorting.value = route.query.sorting as string ?? null;
142+
pageSize.value = route.query.pageSize as number ?? null;
143+
currentPage.value = route.query.page as number ?? null;
144+
layout.value = route.query.layout as string ?? null;
145+
categoryFilters.value = route.query.categoryFilters as string[] ?? null;
146+
tagFilters.value = route.query.tagFilters as string[] ?? null;
126147
});
127148
128149
onMounted(() => {
150+
searchQuery.value = route.query.search as string ?? null;
129151
loadTorrents();
130152
});
131153
154+
function submitSearch () {
155+
navigateTo({
156+
path: "/torrents",
157+
query: {
158+
search: searchQuery.value,
159+
sorting: itemsSorting.value,
160+
pageSize: pageSize.value,
161+
page: 1,
162+
layout: layout.value,
163+
categoryFilters: categoryFilters.value,
164+
tagFilters: tagFilters.value
165+
}
166+
});
167+
}
168+
132169
function loadTorrents () {
133170
rest.value.torrent.getTorrents(
134171
{

0 commit comments

Comments
 (0)