Skip to content

Commit 6c388ce

Browse files
authored
Merge branch 'main' into dbajpeyi/refactor/decouple-import-meta
2 parents 91e99dc + 931740f commit 6c388ce

File tree

14 files changed

+117
-17
lines changed

14 files changed

+117
-17
lines changed

special-pages/pages/history/app/components/Empty.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { useTypedTranslation } from '../types.js';
33
import cn from 'classnames';
44
import styles from './VirtualizedList.module.css';
55
import { useQueryContext } from '../global/Providers/QueryProvider.js';
6+
import { useResultsData } from '../global/Providers/HistoryServiceProvider.js';
7+
import { useComputed } from '@preact/signals';
68

79
/**
810
* Empty state component displayed when no results are available
@@ -28,11 +30,28 @@ export function Empty({ title, text }) {
2830
*/
2931
export function EmptyState() {
3032
const { t } = useTypedTranslation();
33+
const results = useResultsData();
3134
const query = useQueryContext();
32-
const hasSearch = query.value.term !== null && query.value.term.trim().length > 0;
35+
const hasSearch = useComputed(() => query.value.term !== null && query.value.term.trim().length > 0);
3336

34-
if (hasSearch) {
35-
return <Empty title={t('no_results_title', { term: `"${query.value.term}"` })} text={t('no_results_text')} />;
37+
/**
38+
* Compute the empty state title. this text needs to match the results
39+
* it produces, not just the latest UI value.
40+
*/
41+
const text = useComputed(() => {
42+
const termFromSearchBox = query.value.term;
43+
if (!('term' in results.value.info.query)) return termFromSearchBox;
44+
45+
// if we have results + a search term in the UI, choose which term to show
46+
const termFromApiResponse = results.value.info.query.term;
47+
if (termFromSearchBox === termFromApiResponse) {
48+
return termFromSearchBox;
49+
}
50+
return termFromApiResponse;
51+
});
52+
53+
if (hasSearch.value) {
54+
return <Empty title={t('no_results_title', { term: `"${text.value}"` })} text={t('no_results_text')} />;
3655
}
3756

3857
return <Empty title={t('empty_title')} text={t('empty_text')} />;

special-pages/pages/history/app/global/Providers/HistoryServiceProvider.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { signal, useSignal, useSignalEffect } from '@preact/signals';
77
import { generateHeights, generateViewIds } from '../../utils.js';
88

99
/**
10+
* @typedef {import('../../../types/history.ts').HistoryQueryInfo} HistoryQueryInfo
1011
* @typedef {import('../../../types/history.ts').HistoryQuery['source']} Source
1112
* @typedef {{kind: 'search-commit', params: URLSearchParams, source: Source}
1213
* | {kind: 'delete-range'; value: string }
@@ -33,13 +34,23 @@ const HistoryServiceDispatchContext = createContext(defaultDispatch);
3334
* @property {import('../../../types/history.ts').HistoryItem[]} items
3435
* @property {number[]} heights
3536
* @property {string[]} viewIds
37+
* @property {HistoryQueryInfo} info
3638
*/
3739
/**
3840
* @typedef {import('../../../types/history.ts').Range} Range
3941
* @import { ReadonlySignal } from '@preact/signals'
4042
*/
4143

42-
const ResultsContext = createContext(/** @type {ReadonlySignal<Results>} */ (signal({ items: [], heights: [], viewIds: [] })));
44+
const ResultsContext = createContext(
45+
/** @type {ReadonlySignal<Results>} */ (
46+
signal({
47+
items: [],
48+
heights: [],
49+
viewIds: [],
50+
info: { finished: false, query: { term: '' } },
51+
})
52+
),
53+
);
4354
const RangesContext = createContext(/** @type {ReadonlySignal<Range[]>} */ (signal([])));
4455

4556
/**
@@ -55,6 +66,7 @@ export function HistoryServiceProvider({ service, children, initial }) {
5566
const queryDispatch = useQueryDispatch();
5667
const ranges = useSignal(initial.ranges.ranges);
5768
const results = useSignal({
69+
info: initial.query.info,
5870
items: initial.query.results,
5971
heights: generateHeights(initial.query.results),
6072
viewIds: generateViewIds(initial.query.results),
@@ -64,6 +76,7 @@ export function HistoryServiceProvider({ service, children, initial }) {
6476
const unsub = service.onResults((data) => {
6577
results.value = {
6678
items: data.results,
79+
info: data.info,
6780
heights: generateHeights(data.results),
6881
viewIds: generateViewIds(data.results),
6982
};

special-pages/pages/history/app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async function fetchInitial(query, service, didCatch) {
139139
async function getStrings(environment) {
140140
return environment.locale === 'en'
141141
? enStrings
142-
: await fetch(`./locales/${environment.locale}/new-tab.json`)
142+
: await fetch(`./locales/${environment.locale}/history.json`)
143143
.then((x) => x.json())
144144
.catch((e) => {
145145
console.error('Could not load locale', environment.locale, e);

special-pages/pages/history/app/mocks/mock-transport.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,14 @@ function queryResponseFrom(memory, msg) {
219219
const { term } = msg.params.query;
220220
if (term !== '') {
221221
if (term === 'empty' || term.includes('"') || term.includes('<')) {
222-
return asResponse([], msg.params.offset, msg.params.limit);
222+
const response = asResponse([], msg.params.offset, msg.params.limit);
223+
response.info.query = { term };
224+
return response;
223225
}
224226
if (term === 'empty') {
225-
return asResponse([], msg.params.offset, msg.params.limit);
227+
const response = asResponse([], msg.params.offset, msg.params.limit);
228+
response.info.query = { term };
229+
return response;
226230
}
227231
if (term.trim().match(/^\d+$/)) {
228232
const int = parseInt(term.trim(), 10);

special-pages/pages/history/app/strings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"note": "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
1313
},
1414
"no_results_text": {
15-
"title": "Try searching for a different URL or keywords",
15+
"title": "Try searching for a different URL or keywords.",
1616
"note": "Placeholder text when a search gave no results."
1717
},
1818
"delete_all": {

special-pages/pages/history/public/locales/de/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Seitenbesuche werden angezeigt, sobald du mit dem Browsen beginnst.",
16+
"title" : "Noch kein Browserverlauf.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "Keine Ergebnisse für {term} gefunden",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Versuche es mit einer anderen URL oder anderen Stichwörtern.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Alle löschen",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/en/history.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"note": "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
2323
},
2424
"no_results_text": {
25-
"title": "Try searching for a different URL or keywords",
25+
"title": "Try searching for a different URL or keywords.",
2626
"note": "Placeholder text when a search gave no results."
2727
},
2828
"delete_all": {

special-pages/pages/history/public/locales/es/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Las visitas a la página se mostrarán cuando empieces a navegar.",
16+
"title" : "Todavía no hay historial de navegación.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "No se han encontrado resultados para {term}",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Intenta buscar una URL diferente o palabras clave distintas.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Eliminar todo",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/fr/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Les visites de page apparaîtront une fois que vous commencerez à naviguer.",
16+
"title" : "Aucun historique de navigation pour le moment.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "Aucun résultat trouvé pour {term}",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Essayez de rechercher une URL ou des mots-clés différents.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Tout supprimer",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/it/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Le visite alla pagina appariranno non appena inizierai la navigazione.",
16+
"title" : "Ancora nessuna cronologia di navigazione.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "Nessun risultato trovato per {term}",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Prova a cercare un URL o parole chiave diverse.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Elimina tutto",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/nl/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Paginabezoeken worden zichtbaar zodra je begint te browsen.",
16+
"title" : "Nog geen surfgeschiedenis.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "Geen resultaten gevonden voor {term}",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Probeer te zoeken naar een andere URL of trefwoorden.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Alles verwijderen",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/pl/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Gdy zaczniesz przeglądać, pojawią się odwiedziny stron.",
16+
"title" : "Jeszcze nie ma historii przeglądania.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "Brak wyników dla {term}",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Spróbuj wyszukać inny adres URL lub inne słowa kluczowe.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Usuń wszystko",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/pt/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "As visitas a páginas vão aparecer assim que começares a navegar.",
16+
"title" : "Ainda não há histórico de navegação.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "Nenhum resultado encontrado para {term}",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Experimenta pesquisar um URL ou palavras-chave diferentes.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Eliminar tudo",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

special-pages/pages/history/public/locales/ru/history.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
"note" : "Text shown where there are no remaining history entries"
1414
},
1515
"empty_text" : {
16-
"title" : "Информация о посещении страниц появится после того, как вы начнете просмотр.",
16+
"title" : "Истории посещений пока нет.",
1717
"note" : "Placeholder text when there's no results to show"
1818
},
19+
"no_results_title" : {
20+
"title" : "По запросу «{term}» ничего не найдено.",
21+
"note" : "The placeholder {term} will be dynamically replaced with the search term entered by the user. For example, if the user searches for 'cats', the title will become 'No results found for cats'."
22+
},
23+
"no_results_text" : {
24+
"title" : "Попробуйте ввести другой адрес или ключевые слова.",
25+
"note" : "Placeholder text when a search gave no results."
26+
},
1927
"delete_all" : {
2028
"title" : "Удалить все",
2129
"note" : "Text for a button that deletes all items or entries. An additional confirmation dialog will be presented."

0 commit comments

Comments
 (0)