Go directly to video if Video ID provided in search
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
isAndroidTvStore,
|
||||
searchHistoryStore
|
||||
} from '../store';
|
||||
import { isVideoID } from '$lib/misc';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
@@ -39,20 +40,27 @@
|
||||
function handleSubmit(event: Event | undefined = undefined) {
|
||||
if (event) event.preventDefault();
|
||||
|
||||
if (search.trim() === '') return;
|
||||
const searchTrimed = search.trim();
|
||||
|
||||
if (searchTrimed) return;
|
||||
|
||||
if (isVideoID(searchTrimed)) {
|
||||
// Go directly to video if Video ID provided
|
||||
goto(`/watch/${searchTrimed}`);
|
||||
}
|
||||
|
||||
selectedSuggestionIndex = -1;
|
||||
goto(`/search/${encodeURIComponent(search)}`);
|
||||
goto(`/search/${encodeURIComponent(searchTrimed)}`);
|
||||
|
||||
suggestionsForSearch = [];
|
||||
showSearchBox = false;
|
||||
|
||||
if ($interfaceSearchHistoryEnabled && !$searchHistoryStore.includes(search)) {
|
||||
if ($interfaceSearchHistoryEnabled && !$searchHistoryStore.includes(searchTrimed)) {
|
||||
let pastHistory = $searchHistoryStore;
|
||||
if (pastHistory.length > 15) {
|
||||
pastHistory.pop();
|
||||
}
|
||||
searchHistoryStore.set([search, ...pastHistory]);
|
||||
searchHistoryStore.set([searchTrimed, ...pastHistory]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ import type {
|
||||
VideoBase
|
||||
} from './api/model';
|
||||
|
||||
export function isVideoID(videoId: string): boolean {
|
||||
var regExp = /^[a-zA-Z0-9_-]{11}$/;
|
||||
return regExp.test(videoId);
|
||||
}
|
||||
|
||||
export function truncate(value: string, maxLength: number = 50): string {
|
||||
return value.length > maxLength ? `${value.substring(0, maxLength)}...` : value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user