feat: fallback to unsplash cover when article contains no image
This commit is contained in:
@@ -31,35 +31,52 @@ export const createNewMovie: MenuEntry = {
|
||||
|
||||
let currentQuery: string;
|
||||
const search = debounce(async function search(query: string) {
|
||||
currentQuery = query;
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
try {
|
||||
currentQuery = query;
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch("/api/tmdb/query?q=" + query);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
||||
const movies = await response.json() as TMDBMovie[];
|
||||
|
||||
if (query !== currentQuery) return;
|
||||
|
||||
state.menus["input_link"] = {
|
||||
title: "Search",
|
||||
entries: movies.map((r) => {
|
||||
return {
|
||||
title: `${r.title} - ${r.release_date}`,
|
||||
cb: async () => {
|
||||
try {
|
||||
state.activeState.value = "loading";
|
||||
const response = await fetch("/api/movies/" + r.id, {
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
const movie = await response.json() as ReviewResource;
|
||||
unsub();
|
||||
globalThis.location.href = "/movies/" + movie.name;
|
||||
} catch (e) {
|
||||
state.activeState.value = "error";
|
||||
state.loadingText.value = e.message;
|
||||
}
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
state.activeMenu.value = "input_link";
|
||||
} catch (e) {
|
||||
state.activeState.value = "error";
|
||||
state.loadingText.value = e.message;
|
||||
}
|
||||
|
||||
const response = await fetch("/api/tmdb/query?q=" + query);
|
||||
|
||||
const movies = await response.json() as TMDBMovie[];
|
||||
|
||||
if (query !== currentQuery) return;
|
||||
|
||||
state.menus["input_link"] = {
|
||||
title: "Search",
|
||||
entries: movies.map((r) => {
|
||||
return {
|
||||
title: `${r.title} - ${r.release_date}`,
|
||||
cb: async () => {
|
||||
state.activeState.value = "loading";
|
||||
const response = await fetch("/api/movies/" + r.id, {
|
||||
method: "POST",
|
||||
});
|
||||
const movie = await response.json() as ReviewResource;
|
||||
unsub();
|
||||
globalThis.location.href = "/movies/" + movie.name;
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
state.activeMenu.value = "input_link";
|
||||
}, 500);
|
||||
|
||||
const unsub = state.commandInput.subscribe((value) => {
|
||||
|
||||
Reference in New Issue
Block a user