feat: some shit
This commit is contained in:
@@ -3,6 +3,7 @@ import { addMovieInfos } from "@islands/KMenu/commands/add_movie_infos.ts";
|
||||
import { createNewMovie } from "@islands/KMenu/commands/create_movie.ts";
|
||||
import { createNewArticle } from "@islands/KMenu/commands/create_article.ts";
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
import { addSeriesInfo } from "@islands/KMenu/commands/add_series_infos.ts";
|
||||
|
||||
export const menus: Record<string, Menu> = {
|
||||
main: {
|
||||
@@ -54,6 +55,7 @@ export const menus: Record<string, Menu> = {
|
||||
return !!getCookie("session_cookie");
|
||||
},
|
||||
},
|
||||
addSeriesInfo,
|
||||
createNewArticle,
|
||||
createNewMovie,
|
||||
addMovieInfos,
|
||||
|
@@ -46,7 +46,6 @@ export const addMovieInfos: MenuEntry = {
|
||||
const loc = globalThis["location"];
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
return (loc?.pathname?.includes("movie") &&
|
||||
!loc.pathname.endsWith("movies")) ||
|
||||
(loc?.pathname?.includes("series") && !loc.pathname.endsWith("series"));
|
||||
!loc.pathname.endsWith("movies"));
|
||||
},
|
||||
};
|
||||
|
@@ -1,39 +1,43 @@
|
||||
import { MenuEntry } from "@islands/KMenu/types.ts";
|
||||
import { TMDBMovie } from "@lib/types.ts";
|
||||
import { TMDBSeries } from "@lib/types.ts";
|
||||
import { getCookie } from "@lib/string.ts";
|
||||
import { Series } from "@lib/resource/series.ts";
|
||||
|
||||
export const addMovieInfos: MenuEntry = {
|
||||
title: "Add Movie infos",
|
||||
export const addSeriesInfo: MenuEntry = {
|
||||
title: "Add Series infos",
|
||||
meta: "",
|
||||
icon: "IconReportSearch",
|
||||
cb: async (state, context) => {
|
||||
console.log({ state, context });
|
||||
state.activeState.value = "loading";
|
||||
const movie = context as Series;
|
||||
const series = context as Series;
|
||||
|
||||
const query = movie.name;
|
||||
const query = series.name;
|
||||
|
||||
const response = await fetch(
|
||||
`/api/tmdb/query?q=${encodeURIComponent(query)}&type=serie`,
|
||||
);
|
||||
|
||||
const json = await response.json() as TMDBMovie[];
|
||||
const json = await response.json() as TMDBSeries[];
|
||||
|
||||
const menuID = `result/${movie.name}`;
|
||||
console.log({ json });
|
||||
|
||||
const menuID = `result/${series.name}`;
|
||||
|
||||
state.menus[menuID] = {
|
||||
title: "Select",
|
||||
entries: json.map((m) => ({
|
||||
title: `${m.title} released ${m.release_date}`,
|
||||
title: `${m.name || m.original_name} released ${m.first_air_date}`,
|
||||
cb: async () => {
|
||||
state.activeState.value = "loading";
|
||||
await fetch(`/api/movies/enhance/${movie.name}/`, {
|
||||
console.log({ m });
|
||||
await fetch(`/api/series/enhance/${series.name}/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tmdbId: m.id }),
|
||||
});
|
||||
state.visible.value = false;
|
||||
state.activeState.value = "normal";
|
||||
window.location.reload();
|
||||
//window.location.reload();
|
||||
},
|
||||
})),
|
||||
};
|
||||
@@ -45,8 +49,7 @@ export const addMovieInfos: MenuEntry = {
|
||||
visible: () => {
|
||||
const loc = globalThis["location"];
|
||||
if (!getCookie("session_cookie")) return false;
|
||||
return (loc?.pathname?.includes("movie") &&
|
||||
!loc.pathname.endsWith("movies")) ||
|
||||
(loc?.pathname?.includes("series") && !loc.pathname.endsWith("series"));
|
||||
return (loc?.pathname?.includes("series") &&
|
||||
!loc.pathname.endsWith("series"));
|
||||
},
|
||||
};
|
||||
|
@@ -6,6 +6,9 @@ import { SearchResult } from "@lib/types.ts";
|
||||
import { resources } from "@lib/resources.ts";
|
||||
import { isLocalImage } from "@lib/string.ts";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
import Checkbox from "@components/Checkbox.tsx";
|
||||
import { Rating } from "@components/Rating.tsx";
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export const RedirectSearchHandler = () => {
|
||||
useEventListener("keydown", (e: KeyboardEvent) => {
|
||||
@@ -79,15 +82,24 @@ const SearchComponent = (
|
||||
const [searchQuery, setSearchQuery] = useState(q);
|
||||
const [data, setData] = useState<SearchResult>();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const showSeenStatus = useSignal(false);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
if ("history" in globalThis) {
|
||||
const u = new URL(window.location.href);
|
||||
if (u.searchParams.get("q") !== searchQuery) {
|
||||
u.searchParams.set("q", searchQuery);
|
||||
window.history.replaceState({}, "", u);
|
||||
}
|
||||
if (showSeenStatus.value) {
|
||||
u.searchParams.set("status", "not-seen");
|
||||
} else {
|
||||
u.searchParams.delete("status");
|
||||
}
|
||||
|
||||
window.history.replaceState({}, "", u);
|
||||
}
|
||||
|
||||
console.log({ showSeen: showSeenStatus.value });
|
||||
|
||||
const fetchData = async (query: string) => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
@@ -98,6 +110,9 @@ const SearchComponent = (
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (showSeenStatus.value) {
|
||||
fetchUrl.searchParams.set("status", "not-seen");
|
||||
}
|
||||
if (type) {
|
||||
fetchUrl.searchParams.set("type", type);
|
||||
}
|
||||
@@ -131,25 +146,28 @@ const SearchComponent = (
|
||||
debouncedFetchData(q);
|
||||
}, []);
|
||||
|
||||
console.log({ data, isLoading });
|
||||
return (
|
||||
<div class="mt-2">
|
||||
<div
|
||||
class="flex items-center gap-1 rounded-xl w-full shadow-2xl"
|
||||
style={{ background: "#2B2930", color: "#818181" }}
|
||||
>
|
||||
{isLoading && searchQuery
|
||||
? <IconLoader2 class="w-4 h-4 ml-4 mr-2 animate-spin" />
|
||||
: <IconSearch class="w-4 h-4 ml-4 mr-2" />}
|
||||
<input
|
||||
type="text"
|
||||
style={{ fontSize: "1.2em" }}
|
||||
class="bg-transparent py-3 w-full"
|
||||
ref={inputRef}
|
||||
value={searchQuery}
|
||||
onInput={handleInputChange}
|
||||
/>
|
||||
</div>
|
||||
<header class="flex items-center gap-4">
|
||||
<div
|
||||
class="flex items-center gap-1 rounded-xl w-full shadow-2xl"
|
||||
style={{ background: "#2B2930", color: "#818181" }}
|
||||
>
|
||||
{isLoading && searchQuery
|
||||
? <IconLoader2 class="w-4 h-4 ml-4 mr-2 animate-spin" />
|
||||
: <IconSearch class="w-4 h-4 ml-4 mr-2" />}
|
||||
<input
|
||||
type="text"
|
||||
style={{ fontSize: "1.2em" }}
|
||||
class="bg-transparent py-3 w-full"
|
||||
ref={inputRef}
|
||||
value={searchQuery}
|
||||
onInput={handleInputChange}
|
||||
/>
|
||||
</div>
|
||||
<Checkbox label="seen" checked={showSeenStatus} />
|
||||
<Rating rating={4} />
|
||||
</header>
|
||||
{data?.hits?.length && !isLoading
|
||||
? <SearchResultList showEmoji={!type} result={data} />
|
||||
: isLoading
|
||||
|
Reference in New Issue
Block a user