Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cd24b1c

Browse files
committedFeb 12, 2025·
add search suggestion
1 parent eb659d5 commit cd24b1c

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed
 

‎src/containers/SearchPageV2/SearchContainer.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,18 @@ export const SearchContainer = () => {
218218
[query, setSearchParams],
219219
);
220220

221+
const suggestion = data?.search?.suggestions?.[0]?.suggestions?.[0]?.options?.[0]?.text;
222+
221223
const resultsTranslation = useMemo(() => {
222224
if (!data?.search) return undefined;
223225
const from = page * data.search.pageSize - (data.search.pageSize - 1);
224226
const to = page * data.search.pageSize;
225227
const res = [t("searchPage.showingResults.hits", { from, to, total: data.search.totalCount })];
226228
if (query.length) {
227-
res.push(t("searchPage.showingResults.query", { query }));
229+
res.push(t("searchPage.showingResults.query"));
230+
// TODO: Should we account for the possibility that the query is wrapped in quotes? If so, how should we display it?
231+
// Keep query out of the translation string to avoid escaping issues
232+
res.push(`"${query}"`);
228233
}
229234
return res.filter(Boolean).join(" ");
230235
}, [data?.search, page, query, t]);
@@ -284,6 +289,20 @@ export const SearchContainer = () => {
284289
</SearchFieldWrapper>
285290
</form>
286291
{!!resultsTranslation && <Text textStyle="label.small">{resultsTranslation}</Text>}
292+
{!!suggestion && (
293+
<Text>
294+
{t("searchPage.querySuggestion")}
295+
<Button
296+
variant="link"
297+
onClick={() => {
298+
setQuery(suggestion);
299+
setSearchParams({ query: suggestion });
300+
}}
301+
>
302+
[{suggestion}]
303+
</Button>
304+
</Text>
305+
)}
287306
</FormWrapper>
288307
<ul>{data?.search?.results.map((result) => <SearchResult searchResult={result} key={result.id} />)}</ul>
289308
<StyledPaginationRoot

‎src/messages/messagesEN.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ const messages = {
6767
subjectLetter: "Subjects starting with {{letter}}",
6868
oldResourceTypeFilter: "Resource types",
6969
pagination: "Search results",
70+
querySuggestion: "Search instead for ",
7071
showingResults: {
7172
hits: "Showing results {{from}}-{{to}} of {{total}}",
72-
query: 'for "{{query}}"',
73+
query: "for",
7374
},
7475
traits: {
7576
VIDEO: "Video",

‎src/messages/messagesNB.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ const messages = {
6767
subjectLetter: "Fag som starter på {{letter}}",
6868
oldResourceTypeFilter: "Ressurstyper",
6969
pagination: "Søkeresultater",
70+
querySuggestion: "Søk heller ",
7071
showingResults: {
7172
hits: "Viser treff {{from}}-{{to}} av {{total}}",
72-
query: 'for "{{query}}"',
73+
query: "for",
7374
},
7475
traits: {
7576
VIDEO: "Video",
@@ -78,6 +79,10 @@ const messages = {
7879
PODCAST: "Podkast",
7980
},
8081
filtersHeading: "Tilpass søket ditt",
82+
context: {
83+
dialogTrigger: "+ {{count}} flere steder",
84+
dialogHeading: "Ressursen er brukt flere steder",
85+
},
8186
subjectFilter: {
8287
heading: "Sorter på fag",
8388
trigger: "Velg fag",

‎src/messages/messagesNN.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ const messages = {
6767
subjectLetter: "Fag som startar på {{letter}}",
6868
oldResourceTypeFilter: "Ressurstypar",
6969
pagination: "Søkeresultatar",
70+
querySuggestion: "Søk heller ",
7071
showingResults: {
7172
hits: "Viser treff {{from}}-{{to}} av {{total}}",
72-
query: 'for "{{query}}"',
73+
query: "for",
7374
},
7475
traits: {
7576
VIDEO: "Video",

‎src/messages/messagesSE.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ const messages = {
6666
subjectLetter: "Fag som starter på {{letter}}",
6767
oldResourceTypeFilter: "Ressurstyper",
6868
pagination: "Søkeresultater",
69+
querySuggestion: "Søk heller",
6970
showingResults: {
7071
hits: "Viser treff {{from}}-{{to}} av {{total}}",
71-
query: 'for "{{query}}"',
72+
query: "for",
7273
},
7374
traits: {
7475
VIDEO: "Video",

0 commit comments

Comments
 (0)
Please sign in to comment.