feat: entity dialog extract out
This commit is contained in:
@ -23,6 +23,7 @@ import { ImageStatus } from "./components/image-status/ImageStatus";
|
|||||||
import { SearchImageContextProvider } from "./contexts/SearchImageContext";
|
import { SearchImageContextProvider } from "./contexts/SearchImageContext";
|
||||||
import { type sendImage, sendImageFile } from "./network";
|
import { type sendImage, sendImageFile } from "./network";
|
||||||
import { Image } from "./Image";
|
import { Image } from "./Image";
|
||||||
|
import { WithEntityDialog } from "./WithEntityDialog";
|
||||||
|
|
||||||
const currentPlatform = platform();
|
const currentPlatform = platform();
|
||||||
console.log("Current Platform: ", currentPlatform);
|
console.log("Current Platform: ", currentPlatform);
|
||||||
@ -94,8 +95,10 @@ export const App = () => {
|
|||||||
<Route path="/login" component={Login} />
|
<Route path="/login" component={Login} />
|
||||||
|
|
||||||
<Route path="/" component={ProtectedRoute}>
|
<Route path="/" component={ProtectedRoute}>
|
||||||
<Route path="/" component={Search} />
|
<Route path="/" component={WithEntityDialog}>
|
||||||
<Route path="/image/:imageId" component={Image} />
|
<Route path="/" component={Search} />
|
||||||
|
<Route path="/image/imageId" component={Image} />
|
||||||
|
</Route>
|
||||||
<Route path="/settings" component={Settings} />
|
<Route path="/settings" component={Settings} />
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
|
@ -12,18 +12,16 @@ import {
|
|||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
import { SearchCard } from "./components/search-card/SearchCard";
|
import { SearchCard } from "./components/search-card/SearchCard";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { ItemModal } from "./components/item-modal/ItemModal";
|
|
||||||
import type { Shortcut } from "./components/shortcuts/hooks/useShortcutEditor";
|
import type { Shortcut } from "./components/shortcuts/hooks/useShortcutEditor";
|
||||||
import { base, type UserImage } from "./network";
|
import { base, type UserImage } from "./network";
|
||||||
import { useSearchImageContext } from "./contexts/SearchImageContext";
|
import { useSearchImageContext } from "./contexts/SearchImageContext";
|
||||||
import { A } from "@solidjs/router";
|
import { A } from "@solidjs/router";
|
||||||
|
import { useSetEntity } from "./WithEntityDialog";
|
||||||
|
|
||||||
export const Search = () => {
|
export const Search = () => {
|
||||||
const [searchResults, setSearchResults] = createSignal<UserImage[]>([]);
|
const [searchResults, setSearchResults] = createSignal<UserImage[]>([]);
|
||||||
const [searchQuery, setSearchQuery] = createSignal("");
|
const [searchQuery, setSearchQuery] = createSignal("");
|
||||||
const [selectedItem, setSelectedItem] = createSignal<UserImage | null>(
|
const setEntity = useSetEntity();
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
const { images, imagesWithProperties, onRefetchImages } =
|
const { images, imagesWithProperties, onRefetchImages } =
|
||||||
useSearchImageContext();
|
useSearchImageContext();
|
||||||
@ -146,12 +144,10 @@ export const Search = () => {
|
|||||||
<For each={searchResults()}>
|
<For each={searchResults()}>
|
||||||
{(item) => (
|
{(item) => (
|
||||||
<div
|
<div
|
||||||
onClick={() =>
|
onClick={() => setEntity(item)}
|
||||||
setSelectedItem(item)
|
|
||||||
}
|
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
setSelectedItem(item);
|
setEntity(item);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
class="h-[144px] border relative col-span-3 border-neutral-200 cursor-pointer overflow-hidden rounded-xl"
|
class="h-[144px] border relative col-span-3 border-neutral-200 cursor-pointer overflow-hidden rounded-xl"
|
||||||
@ -191,12 +187,6 @@ export const Search = () => {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{selectedItem() && (
|
|
||||||
<ItemModal
|
|
||||||
item={selectedItem() as UserImage}
|
|
||||||
onClose={() => setSelectedItem(null)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
34
frontend/src/WithEntityDialog.tsx
Normal file
34
frontend/src/WithEntityDialog.tsx
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import {
|
||||||
|
type Component,
|
||||||
|
type ParentProps,
|
||||||
|
Show,
|
||||||
|
createContext,
|
||||||
|
createSignal,
|
||||||
|
useContext,
|
||||||
|
} from "solid-js";
|
||||||
|
import { ItemModal } from "./components/item-modal/ItemModal";
|
||||||
|
import type { UserImage } from "./network";
|
||||||
|
|
||||||
|
const EntityDialogContext = createContext<
|
||||||
|
(image: UserImage | undefined) => void
|
||||||
|
>(() => {});
|
||||||
|
|
||||||
|
export const useSetEntity = () => useContext(EntityDialogContext);
|
||||||
|
|
||||||
|
export const WithEntityDialog: Component<ParentProps> = (props) => {
|
||||||
|
const [selectedEntity, setSelectedEntity] = createSignal<UserImage>();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<EntityDialogContext.Provider value={setSelectedEntity}>
|
||||||
|
<Show when={selectedEntity()}>
|
||||||
|
{(entity) => (
|
||||||
|
<ItemModal
|
||||||
|
item={entity()}
|
||||||
|
onClose={() => setSelectedEntity(undefined)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Show>
|
||||||
|
{props.children}
|
||||||
|
</EntityDialogContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
@ -8,7 +8,7 @@ type Props = {
|
|||||||
|
|
||||||
export const ItemModal = (props: Props) => {
|
export const ItemModal = (props: Props) => {
|
||||||
return (
|
return (
|
||||||
<div class="fixed inset-2 rounded-2xl p-4 bg-white border border-neutral-300">
|
<div class="fixed z-10 inset-2 rounded-2xl p-4 bg-white border border-neutral-300">
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<h1 class="text-2xl font-bold">{props.item.data.Name}</h1>
|
<h1 class="text-2xl font-bold">{props.item.data.Name}</h1>
|
||||||
<button type="button" onClick={props.onClose}>
|
<button type="button" onClick={props.onClose}>
|
||||||
|
@ -18,7 +18,7 @@ export const SearchCardEvent = ({ item }: Props) => {
|
|||||||
{data.Name.length > 0 ? data.Name : "Unknown 🐞"}
|
{data.Name.length > 0 ? data.Name : "Unknown 🐞"}
|
||||||
</p>
|
</p>
|
||||||
<p class="text-xs text-neutral-700">
|
<p class="text-xs text-neutral-700">
|
||||||
Organized by {data.Organizer?.Name ?? "unknown"} on{" "}
|
On{" "}
|
||||||
{data.StartDateTime
|
{data.StartDateTime
|
||||||
? new Date(data.StartDateTime).toLocaleDateString("en-US", {
|
? new Date(data.StartDateTime).toLocaleDateString("en-US", {
|
||||||
month: "long",
|
month: "long",
|
||||||
|
Reference in New Issue
Block a user