mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-08 03:08:29 +02:00
Avoid page reload when triggering actions in bookmark list (#506)
* Extract bookmark view contexts * Implement basic partial updates for bookmark list and tag cloud * Refactor confirm button JS into web component * Refactor bulk edit JS into web component * Refactor tag autocomplete JS into web component * Refactor bookmark page JS into web component * Refactor global shortcuts JS into web component * Update tests * Add E2E test for partial updates * Add partial updates for archived bookmarks * Add partial updates for shared bookmarks * Cleanup helpers * Improve naming in bulk edit * Refactor shared components into behaviors * Refactor bulk edit components into behaviors * Refactor bookmark list components into behaviors * Update tests * Combine all scripts into bundle * Fix E2E CI
This commit is contained in:
52
bookmarks/frontend/components/SearchHistory.js
Normal file
52
bookmarks/frontend/components/SearchHistory.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const SEARCH_HISTORY_KEY = "searchHistory";
|
||||
const MAX_ENTRIES = 30;
|
||||
|
||||
export class SearchHistory {
|
||||
getHistory() {
|
||||
const historyJson = localStorage.getItem(SEARCH_HISTORY_KEY);
|
||||
return historyJson
|
||||
? JSON.parse(historyJson)
|
||||
: {
|
||||
recent: [],
|
||||
};
|
||||
}
|
||||
|
||||
pushCurrent() {
|
||||
// Skip if browser is not compatible
|
||||
if (!window.URLSearchParams) return;
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const searchParam = urlParams.get("q");
|
||||
|
||||
if (!searchParam) return;
|
||||
|
||||
this.push(searchParam);
|
||||
}
|
||||
|
||||
push(search) {
|
||||
const history = this.getHistory();
|
||||
|
||||
history.recent.unshift(search);
|
||||
|
||||
// Remove duplicates and clamp to max entries
|
||||
history.recent = history.recent.reduce((acc, cur) => {
|
||||
if (acc.length >= MAX_ENTRIES) return acc;
|
||||
if (acc.indexOf(cur) >= 0) return acc;
|
||||
acc.push(cur);
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const newHistoryJson = JSON.stringify(history);
|
||||
localStorage.setItem(SEARCH_HISTORY_KEY, newHistoryJson);
|
||||
}
|
||||
|
||||
getRecentSearches(query, max) {
|
||||
const history = this.getHistory();
|
||||
|
||||
return history.recent
|
||||
.filter(
|
||||
(search) =>
|
||||
!query || search.toLowerCase().indexOf(query.toLowerCase()) >= 0,
|
||||
)
|
||||
.slice(0, max);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user