Search filters in web app (#176)
This commit is contained in:
1 parent
a61c0afe16
commit
2bc4d43f51
5 files changed
+304
-3
No files matched your search
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- This adds support for multi languages audio tracks
|
- This adds support for multi languages audio tracks
|
||||||
- Also adds thumbnails/preview in trick play mode
|
- Also adds thumbnails/preview in trick play mode
|
||||||
- Known issue: thumbnails might appear cropped/misaligned at the end of videos. This will be addressed in a later release.
|
- Known issue: thumbnails might appear cropped/misaligned at the end of videos. This will be addressed in a later release.
|
||||||
|
- Search filters in web app
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<svg
|
||||||
|
enable-background="new 0 0 24 24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24"
|
||||||
|
focusable="false"
|
||||||
|
style="pointer-events: none; display: block; width: 100%; height: 100%;"
|
||||||
|
>
|
||||||
|
<g class="fill-current">
|
||||||
|
<path
|
||||||
|
d="M15 17h6v1h-6v-1zm-4 0H3v1h8v2h1v-5h-1v2zm3-9h1V3h-1v2H3v1h11v2zm4-3v1h3V5h-3zM6 14h1V9H6v2H3v1h3v2zm4-2h11v-1H10v1z"
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 372 B |
@@ -20,8 +20,22 @@ export class InvidiousApi {
|
|||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async search(query: string) {
|
public async search(query: string, filters: any) {
|
||||||
const response = await fetch(`${this.instance}/api/v1/search?q=${encodeURIComponent(query)}®ion=${this.userCountryCode}`);
|
let url = `${this.instance}/api/v1/search?q=${encodeURIComponent(query)}®ion=${this.userCountryCode}`;
|
||||||
|
for (let filter in filters) {
|
||||||
|
if (typeof filters[filter] === 'string') {
|
||||||
|
if (filters[filter] === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
url += `&${filter}=${filters[filter]}`;
|
||||||
|
} else {
|
||||||
|
if (filters[filter].length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
url += `&${filter}=${filters[filter].join(',')}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const response = await fetch(url);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,250 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let modal;
|
||||||
|
|
||||||
|
export let label = "Filters";
|
||||||
|
|
||||||
|
export const filters = {
|
||||||
|
date: "",
|
||||||
|
type: "",
|
||||||
|
duration: "",
|
||||||
|
features: [],
|
||||||
|
sort_by: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
let features_kv: any = {};
|
||||||
|
|
||||||
|
$: {
|
||||||
|
filters.features = Object.keys(features_kv).filter(
|
||||||
|
(key) => features_kv[key]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
count += filters.date ? 1 : 0;
|
||||||
|
count += filters.type ? 1 : 0;
|
||||||
|
count += filters.duration ? 1 : 0;
|
||||||
|
count += filters.features.length;
|
||||||
|
count += filters.sort_by ? 1 : 0;
|
||||||
|
|
||||||
|
label = `Filters` + `${count > 0 ? ` (${count})` : ""}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
date: [
|
||||||
|
{
|
||||||
|
title: "Any date",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Last hour",
|
||||||
|
value: "hour",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Today",
|
||||||
|
value: "today",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "This week",
|
||||||
|
value: "week",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "This month",
|
||||||
|
value: "month",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "This year",
|
||||||
|
value: "year",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
type: [
|
||||||
|
{
|
||||||
|
title: "Any type",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Video",
|
||||||
|
value: "video",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Playlist",
|
||||||
|
value: "playlist",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Channel",
|
||||||
|
value: "channel",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Movie",
|
||||||
|
value: "movie",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Show",
|
||||||
|
value: "show",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
duration: [
|
||||||
|
{
|
||||||
|
title: "Any duration",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Under 4 minutes",
|
||||||
|
value: "short",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "4 - 20 minutes",
|
||||||
|
value: "medium",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Over 20 minutes",
|
||||||
|
value: "long",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
features: [
|
||||||
|
{
|
||||||
|
title: "Live",
|
||||||
|
value: "live",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "4K",
|
||||||
|
value: "4k",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "HD",
|
||||||
|
value: "hd",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Subtitles/CC",
|
||||||
|
value: "subtitles",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Creative Commons",
|
||||||
|
value: "creative_commons",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "360°",
|
||||||
|
value: "360",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "VR180",
|
||||||
|
value: "vr180",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "3D",
|
||||||
|
value: "3d",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "HDR",
|
||||||
|
value: "hdr",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Purchased",
|
||||||
|
value: "purchased",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Location",
|
||||||
|
value: "location",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
sort_by: [
|
||||||
|
{
|
||||||
|
title: "Relevance",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Upload date",
|
||||||
|
value: "upload_date",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "View count",
|
||||||
|
value: "view_count",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Rating",
|
||||||
|
value: "rating",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export function open() {
|
||||||
|
modal.showModal();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<dialog bind:this={modal} id="modal_search_filters" class="modal">
|
||||||
|
<form method="dialog" class="modal-box bg-base-100">
|
||||||
|
<div class="p-6">
|
||||||
|
<h2 class="text-xl font-bold mb-4">{label}</h2>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<h3 class="text-lg font-bold mb-2">Date</h3>
|
||||||
|
<select class="input input-bordered w-full" bind:value={filters.date}>
|
||||||
|
{#each options.date as { title, value }}
|
||||||
|
<option {value}>{title}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<h3 class="text-lg font-bold mb-2">Type</h3>
|
||||||
|
<select class="input input-bordered w-full" bind:value={filters.type}>
|
||||||
|
{#each options.type as { title, value }}
|
||||||
|
<option {value}>{title}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<h3 class="text-lg font-bold mb-2">Duration</h3>
|
||||||
|
<select
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
bind:value={filters.duration}
|
||||||
|
>
|
||||||
|
{#each options.duration as { title, value }}
|
||||||
|
<option {value}>{title}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<h3 class="text-lg font-bold mb-2">Features</h3>
|
||||||
|
{#each options.features as { title, value }}
|
||||||
|
<label class="flex items-center">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
{value}
|
||||||
|
class="form-checkbox"
|
||||||
|
bind:checked={features_kv[value]}
|
||||||
|
/>
|
||||||
|
<span class="ml-2">{title}</span>
|
||||||
|
</label>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<h3 class="text-lg font-bold mb-2">Sort By</h3>
|
||||||
|
<select
|
||||||
|
class="input input-bordered w-full"
|
||||||
|
bind:value={filters.sort_by}
|
||||||
|
>
|
||||||
|
{#each options.sort_by as { title, value }}
|
||||||
|
<option {value}>{title}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button
|
||||||
|
class="btn btn-outline"
|
||||||
|
type="button"
|
||||||
|
on:click={() => modal.close()}>Close</button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form method="dialog" class="modal-backdrop">
|
||||||
|
<button>Close</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
@@ -5,7 +5,9 @@
|
|||||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||||
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
||||||
|
import FiltersIcon from "assets/filters.svg.svelte";
|
||||||
import ChannelCell from "./Home/ChannelCell.svelte";
|
import ChannelCell from "./Home/ChannelCell.svelte";
|
||||||
|
import SearchFilters from "./Search/SearchFilters.svelte";
|
||||||
|
|
||||||
export let visibility: boolean;
|
export let visibility: boolean;
|
||||||
|
|
||||||
@@ -18,6 +20,10 @@
|
|||||||
let searchHistory = [];
|
let searchHistory = [];
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
||||||
|
let searchFiltersComponent;
|
||||||
|
let searchFilters;
|
||||||
|
let searchFiltersLabel;
|
||||||
|
|
||||||
playletStateStore.subscribe((value) => {
|
playletStateStore.subscribe((value) => {
|
||||||
invidiousApi.instance = value?.invidious?.current_instance;
|
invidiousApi.instance = value?.invidious?.current_instance;
|
||||||
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
||||||
@@ -81,7 +87,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
videos = await invidiousApi.search(searchBoxText);
|
videos = await invidiousApi.search(searchBoxText, searchFilters);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
}
|
}
|
||||||
@@ -123,6 +129,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
class="btn border border-neutral rounded-full mt-1"
|
||||||
|
on:click={searchFiltersComponent.open()}
|
||||||
|
>
|
||||||
|
<div class="h-6">
|
||||||
|
<FiltersIcon />
|
||||||
|
</div>
|
||||||
|
{searchFiltersLabel}
|
||||||
|
</button>
|
||||||
|
|
||||||
{#if suggestions.suggestions.length > 0}
|
{#if suggestions.suggestions.length > 0}
|
||||||
<ul
|
<ul
|
||||||
class="dropdown-content menu z-10 p-2 shadow-xl bg-base-200 rounded-box"
|
class="dropdown-content menu z-10 p-2 shadow-xl bg-base-200 rounded-box"
|
||||||
@@ -163,4 +179,10 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<SearchFilters
|
||||||
|
bind:this={searchFiltersComponent}
|
||||||
|
bind:label={searchFiltersLabel}
|
||||||
|
bind:filters={searchFilters}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
Reference in new issue
Block a user