mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-14 22:19:32 +02:00
Implement archive mode for search component (#46)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
export let placeholder;
|
||||
export let value;
|
||||
export let tags;
|
||||
export let mode = 'default';
|
||||
export let apiClient;
|
||||
|
||||
let isFocus = false;
|
||||
@@ -111,7 +112,9 @@
|
||||
let bookmarks = []
|
||||
|
||||
if (value && value.length >= 3) {
|
||||
const fetchedBookmarks = await apiClient.getBookmarks(value, {limit: 5, offset: 0})
|
||||
const fetchedBookmarks = mode === 'archive'
|
||||
? await apiClient.getArchivedBookmarks(value, {limit: 5, offset: 0})
|
||||
: await apiClient.getBookmarks(value, {limit: 5, offset: 0})
|
||||
bookmarks = fetchedBookmarks.map(bookmark => {
|
||||
const fullLabel = bookmark.title || bookmark.website_title || bookmark.url
|
||||
const label = clampText(fullLabel, 60)
|
||||
|
@@ -11,4 +11,13 @@ export class ApiClient {
|
||||
.then(response => response.json())
|
||||
.then(data => data.results)
|
||||
}
|
||||
|
||||
getArchivedBookmarks(query, options = {limit: 100, offset: 0}) {
|
||||
const encodedQuery = encodeURIComponent(query)
|
||||
const url = `${this.baseUrl}bookmarks/archived?q=${encodedQuery}&limit=${options.limit}&offset=${options.offset}`
|
||||
|
||||
return fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => data.results)
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@
|
||||
<div class="content-area-header">
|
||||
<h2>Archived bookmarks</h2>
|
||||
<div class="spacer"></div>
|
||||
{% include 'bookmarks/search.html' %}
|
||||
{% bookmark_search query tags mode='archive' %}
|
||||
</div>
|
||||
|
||||
{% if empty %}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<div class="content-area-header">
|
||||
<h2>Bookmarks</h2>
|
||||
<div class="spacer"></div>
|
||||
{% include 'bookmarks/search.html' %}
|
||||
{% bookmark_search query tags %}
|
||||
</div>
|
||||
|
||||
{% if empty %}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
placeholder: 'Search for words or #tags',
|
||||
value: '{{ query }}',
|
||||
tags: currentTags,
|
||||
mode: '{{ mode }}',
|
||||
apiClient
|
||||
}
|
||||
})
|
||||
|
@@ -61,3 +61,14 @@ def bookmark_list(context, bookmarks: Page, return_url: str):
|
||||
'bookmarks': bookmarks,
|
||||
'return_url': return_url
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('bookmarks/search.html', name='bookmark_search', takes_context=True)
|
||||
def bookmark_search(context, query: str, tags: [Tag], mode: str = 'default'):
|
||||
tag_names = [tag.name for tag in tags]
|
||||
tags_string = build_tag_string(tag_names, ' ')
|
||||
return {
|
||||
'query': query,
|
||||
'tags_string': tags_string,
|
||||
'mode': mode,
|
||||
}
|
||||
|
@@ -38,8 +38,6 @@ def get_bookmark_view_context(request, query_set, tags, base_url):
|
||||
query_string = request.GET.get('q')
|
||||
paginator = Paginator(query_set, _default_page_size)
|
||||
bookmarks = paginator.get_page(page)
|
||||
tag_names = [tag.name for tag in tags]
|
||||
tags_string = build_tag_string(tag_names, ' ')
|
||||
return_url = generate_return_url(base_url, page, query_string)
|
||||
|
||||
if request.GET.get('tag'):
|
||||
@@ -50,7 +48,6 @@ def get_bookmark_view_context(request, query_set, tags, base_url):
|
||||
return {
|
||||
'bookmarks': bookmarks,
|
||||
'tags': tags,
|
||||
'tags_string': tags_string,
|
||||
'query': query_string if query_string else '',
|
||||
'empty': paginator.count == 0,
|
||||
'return_url': return_url
|
||||
|
Reference in New Issue
Block a user