aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/components/dashboard')
-rw-r--r--apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx11
-rw-r--r--apps/web/components/dashboard/bookmarks/BookmarkMarkdownComponent.tsx2
-rw-r--r--apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx53
-rw-r--r--apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx63
-rw-r--r--apps/web/components/dashboard/lists/EditListModal.tsx119
-rw-r--r--apps/web/components/dashboard/lists/ListHeader.tsx38
-rw-r--r--apps/web/components/dashboard/lists/ListOptions.tsx4
-rw-r--r--apps/web/components/dashboard/preview/ActionBar.tsx37
-rw-r--r--apps/web/components/dashboard/preview/BookmarkPreview.tsx2
-rw-r--r--apps/web/components/dashboard/search/QueryExplainerTooltip.tsx162
-rw-r--r--apps/web/components/dashboard/search/SearchInput.tsx51
11 files changed, 450 insertions, 92 deletions
diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx
index 1df0c197..a2323987 100644
--- a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx
@@ -30,6 +30,13 @@ interface Props {
wrapTags: boolean;
}
+function BookmarkFormattedCreatedAt({ bookmark }: { bookmark: ZBookmark }) {
+ const createdAt = dayjs(bookmark.createdAt);
+ const oneYearAgo = dayjs().subtract(1, "year");
+ const formatString = createdAt.isAfter(oneYearAgo) ? "MMM D" : "MMM D, YYYY";
+ return createdAt.format(formatString);
+}
+
function BottomRow({
footer,
bookmark,
@@ -45,7 +52,7 @@ function BottomRow({
href={`/dashboard/preview/${bookmark.id}`}
suppressHydrationWarning
>
- {dayjs(bookmark.createdAt).format("MMM DD")}
+ <BookmarkFormattedCreatedAt bookmark={bookmark} />
</Link>
</div>
<BookmarkActionBar bookmark={bookmark} />
@@ -232,7 +239,7 @@ function CompactView({ bookmark, title, footer, className }: Props) {
suppressHydrationWarning
className="shrink-0 gap-2 text-gray-500"
>
- {dayjs(bookmark.createdAt).format("MMM DD")}
+ <BookmarkFormattedCreatedAt bookmark={bookmark} />
</Link>
</div>
<BookmarkActionBar bookmark={bookmark} />
diff --git a/apps/web/components/dashboard/bookmarks/BookmarkMarkdownComponent.tsx b/apps/web/components/dashboard/bookmarks/BookmarkMarkdownComponent.tsx
index 74eb0868..60a6d634 100644
--- a/apps/web/components/dashboard/bookmarks/BookmarkMarkdownComponent.tsx
+++ b/apps/web/components/dashboard/bookmarks/BookmarkMarkdownComponent.tsx
@@ -30,7 +30,7 @@ export function BookmarkMarkdownComponent({
});
};
return (
- <div className="h-full overflow-hidden">
+ <div className="h-full">
{readOnly ? (
<MarkdownReadonly>{bookmark.content.text}</MarkdownReadonly>
) : (
diff --git a/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx b/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx
index 8dfb96fd..c37c6417 100644
--- a/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx
+++ b/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx
@@ -28,15 +28,16 @@ import type {
ZBookmarkedLink,
} from "@hoarder/shared/types/bookmarks";
import {
- useDeleteBookmark,
useRecrawlBookmark,
useUpdateBookmark,
} from "@hoarder/shared-react/hooks//bookmarks";
import { useRemoveBookmarkFromList } from "@hoarder/shared-react/hooks//lists";
import { useBookmarkGridContext } from "@hoarder/shared-react/hooks/bookmark-grid-context";
+import { useBookmarkListContext } from "@hoarder/shared-react/hooks/bookmark-list-context";
import { BookmarkTypes } from "@hoarder/shared/types/bookmarks";
import { BookmarkedTextEditor } from "./BookmarkedTextEditor";
+import DeleteBookmarkConfirmationDialog from "./DeleteBookmarkConfirmationDialog";
import { ArchivedActionIcon, FavouritedActionIcon } from "./icons";
import { useManageListsModal } from "./ManageListsModal";
import { useTagModel } from "./TagModal";
@@ -53,9 +54,12 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
const { setOpen: setManageListsModalOpen, content: manageListsModal } =
useManageListsModal(bookmark.id);
+ const [deleteBookmarkDialogOpen, setDeleteBookmarkDialogOpen] =
+ useState(false);
const [isTextEditorOpen, setTextEditorOpen] = useState(false);
const { listId } = useBookmarkGridContext() ?? {};
+ const withinListContext = useBookmarkListContext();
const onError = () => {
toast({
@@ -63,14 +67,6 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
title: t("common.something_went_wrong"),
});
};
- const deleteBookmarkMutator = useDeleteBookmark({
- onSuccess: () => {
- toast({
- description: t("toasts.bookmarks.deleted"),
- });
- },
- onError,
- });
const updateBookmarkMutator = useUpdateBookmark({
onSuccess: () => {
@@ -112,6 +108,11 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
<>
{tagModal}
{manageListsModal}
+ <DeleteBookmarkConfirmationDialog
+ bookmark={bookmark}
+ open={deleteBookmarkDialogOpen}
+ setOpen={setDeleteBookmarkDialogOpen}
+ />
<BookmarkedTextEditor
bookmark={bookmark}
open={isTextEditorOpen}
@@ -211,20 +212,22 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
<span>{t("actions.manage_lists")}</span>
</DropdownMenuItem>
- {listId && (
- <DropdownMenuItem
- disabled={demoMode}
- onClick={() =>
- removeFromListMutator.mutate({
- listId,
- bookmarkId: bookmark.id,
- })
- }
- >
- <ListX className="mr-2 size-4" />
- <span>{t("actions.remove_from_list")}</span>
- </DropdownMenuItem>
- )}
+ {listId &&
+ withinListContext &&
+ withinListContext.type === "manual" && (
+ <DropdownMenuItem
+ disabled={demoMode}
+ onClick={() =>
+ removeFromListMutator.mutate({
+ listId,
+ bookmarkId: bookmark.id,
+ })
+ }
+ >
+ <ListX className="mr-2 size-4" />
+ <span>{t("actions.remove_from_list")}</span>
+ </DropdownMenuItem>
+ )}
{bookmark.content.type === BookmarkTypes.LINK && (
<DropdownMenuItem
@@ -240,9 +243,7 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
<DropdownMenuItem
disabled={demoMode}
className="text-destructive"
- onClick={() =>
- deleteBookmarkMutator.mutate({ bookmarkId: bookmark.id })
- }
+ onClick={() => setDeleteBookmarkDialogOpen(true)}
>
<Trash2 className="mr-2 size-4" />
<span>{t("actions.delete")}</span>
diff --git a/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx b/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx
new file mode 100644
index 00000000..4a69e3d0
--- /dev/null
+++ b/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx
@@ -0,0 +1,63 @@
+import { usePathname, useRouter } from "next/navigation";
+import { ActionButton } from "@/components/ui/action-button";
+import ActionConfirmingDialog from "@/components/ui/action-confirming-dialog";
+import { toast } from "@/components/ui/use-toast";
+import { useTranslation } from "@/lib/i18n/client";
+
+import { useDeleteBookmark } from "@hoarder/shared-react/hooks//bookmarks";
+import { ZBookmark } from "@hoarder/shared/types/bookmarks";
+
+export default function DeleteBookmarkConfirmationDialog({
+ bookmark,
+ children,
+ open,
+ setOpen,
+}: {
+ bookmark: ZBookmark;
+ children?: React.ReactNode;
+ open: boolean;
+ setOpen: (v: boolean) => void;
+}) {
+ const { t } = useTranslation();
+ const currentPath = usePathname();
+ const router = useRouter();
+
+ const { mutate: deleteBoomark, isPending } = useDeleteBookmark({
+ onSuccess: () => {
+ toast({
+ description: t("toasts.bookmarks.deleted"),
+ });
+ setOpen(false);
+ if (currentPath.includes(bookmark.id)) {
+ router.push("/dashboard/bookmarks");
+ }
+ },
+ onError: () => {
+ toast({
+ variant: "destructive",
+ description: `Something went wrong`,
+ });
+ },
+ });
+
+ return (
+ <ActionConfirmingDialog
+ open={open}
+ setOpen={setOpen}
+ title={t("dialogs.bookmarks.delete_confirmation_title")}
+ description={t("dialogs.bookmarks.delete_confirmation_description")}
+ actionButton={() => (
+ <ActionButton
+ type="button"
+ variant="destructive"
+ loading={isPending}
+ onClick={() => deleteBoomark({ bookmarkId: bookmark.id })}
+ >
+ Delete
+ </ActionButton>
+ )}
+ >
+ {children}
+ </ActionConfirmingDialog>
+ );
+}
diff --git a/apps/web/components/dashboard/lists/EditListModal.tsx b/apps/web/components/dashboard/lists/EditListModal.tsx
index d66d7096..98bb19be 100644
--- a/apps/web/components/dashboard/lists/EditListModal.tsx
+++ b/apps/web/components/dashboard/lists/EditListModal.tsx
@@ -25,6 +25,13 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { toast } from "@/components/ui/use-toast";
import { useTranslation } from "@/lib/i18n/client";
import data from "@emoji-mart/data";
@@ -38,7 +45,10 @@ import {
useCreateBookmarkList,
useEditBookmarkList,
} from "@hoarder/shared-react/hooks/lists";
-import { ZBookmarkList } from "@hoarder/shared/types/lists";
+import {
+ ZBookmarkList,
+ zNewBookmarkListSchema,
+} from "@hoarder/shared/types/lists";
import { BookmarkListSelector } from "./BookmarkListSelector";
@@ -46,13 +56,13 @@ export function EditListModal({
open: userOpen,
setOpen: userSetOpen,
list,
- parent,
+ prefill,
children,
}: {
open?: boolean;
setOpen?: (v: boolean) => void;
list?: ZBookmarkList;
- parent?: ZBookmarkList;
+ prefill?: Partial<Omit<ZBookmarkList, "id">>;
children?: React.ReactNode;
}) {
const { t } = useTranslation();
@@ -64,17 +74,14 @@ export function EditListModal({
throw new Error("You must provide both open and setOpen or neither");
}
const [customOpen, customSetOpen] = useState(false);
- const formSchema = z.object({
- name: z.string(),
- icon: z.string(),
- parentId: z.string().nullish(),
- });
- const form = useForm<z.infer<typeof formSchema>>({
- resolver: zodResolver(formSchema),
+ const form = useForm<z.infer<typeof zNewBookmarkListSchema>>({
+ resolver: zodResolver(zNewBookmarkListSchema),
defaultValues: {
- name: list?.name ?? "",
- icon: list?.icon ?? "🚀",
- parentId: list?.parentId ?? parent?.id,
+ name: list?.name ?? prefill?.name ?? "",
+ icon: list?.icon ?? prefill?.icon ?? "🚀",
+ parentId: list?.parentId ?? prefill?.parentId,
+ type: list?.type ?? prefill?.type ?? "manual",
+ query: list?.query ?? prefill?.query ?? undefined,
},
});
const [open, setOpen] = [
@@ -84,9 +91,11 @@ export function EditListModal({
useEffect(() => {
form.reset({
- name: list?.name ?? "",
- icon: list?.icon ?? "🚀",
- parentId: list?.parentId ?? parent?.id,
+ name: list?.name ?? prefill?.name ?? "",
+ icon: list?.icon ?? prefill?.icon ?? "🚀",
+ parentId: list?.parentId ?? prefill?.parentId,
+ type: list?.type ?? prefill?.type ?? "manual",
+ query: list?.query ?? prefill?.query ?? undefined,
});
}, [open]);
@@ -154,14 +163,24 @@ export function EditListModal({
}
},
});
+ const listType = form.watch("type");
+
+ useEffect(() => {
+ if (listType !== "smart") {
+ form.resetField("query");
+ }
+ }, [listType]);
const isEdit = !!list;
const isPending = isCreating || isEditing;
- const onSubmit = form.handleSubmit((value: z.infer<typeof formSchema>) => {
- value.parentId = value.parentId === "" ? null : value.parentId;
- isEdit ? editList({ ...value, listId: list.id }) : createList(value);
- });
+ const onSubmit = form.handleSubmit(
+ (value: z.infer<typeof zNewBookmarkListSchema>) => {
+ value.parentId = value.parentId === "" ? null : value.parentId;
+ value.query = value.type === "smart" ? value.query : undefined;
+ isEdit ? editList({ ...value, listId: list.id }) : createList(value);
+ },
+ );
return (
<Dialog
@@ -176,7 +195,9 @@ export function EditListModal({
<Form {...form}>
<form onSubmit={onSubmit}>
<DialogHeader>
- <DialogTitle>{isEdit ? "Edit" : "New"} List</DialogTitle>
+ <DialogTitle>
+ {isEdit ? t("lists.edit_list") : t("lists.new_list")}
+ </DialogTitle>
</DialogHeader>
<div className="flex w-full gap-2 py-4">
<FormField
@@ -232,7 +253,7 @@ export function EditListModal({
render={({ field }) => {
return (
<FormItem className="grow pb-4">
- <FormLabel>Parent</FormLabel>
+ <FormLabel>{t("lists.parent_list")}</FormLabel>
<div className="flex items-center gap-1">
<FormControl>
<BookmarkListSelector
@@ -240,7 +261,7 @@ export function EditListModal({
hideSubtreeOf={list ? list.id : undefined}
value={field.value}
onChange={field.onChange}
- placeholder={"No Parent"}
+ placeholder={t("lists.no_parent")}
/>
</FormControl>
<Button
@@ -258,6 +279,58 @@ export function EditListModal({
);
}}
/>
+ <FormField
+ control={form.control}
+ name="type"
+ render={({ field }) => {
+ return (
+ <FormItem className="grow pb-4">
+ <FormLabel>{t("lists.list_type")}</FormLabel>
+ <FormControl>
+ <Select
+ disabled={isEdit}
+ onValueChange={field.onChange}
+ value={field.value}
+ >
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="manual">
+ {t("lists.manual_list")}
+ </SelectItem>
+ <SelectItem value="smart">
+ {t("lists.smart_list")}
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ );
+ }}
+ />
+ {listType === "smart" && (
+ <FormField
+ control={form.control}
+ name="query"
+ render={({ field }) => {
+ return (
+ <FormItem className="grow pb-4">
+ <FormLabel>{t("lists.search_query")}</FormLabel>
+ <FormControl>
+ <Input
+ value={field.value}
+ onChange={field.onChange}
+ placeholder={t("lists.search_query")}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ );
+ }}
+ />
+ )}
<DialogFooter className="sm:justify-end">
<DialogClose asChild>
<Button type="button" variant="secondary">
diff --git a/apps/web/components/dashboard/lists/ListHeader.tsx b/apps/web/components/dashboard/lists/ListHeader.tsx
index a6780e1e..b8bfb4ad 100644
--- a/apps/web/components/dashboard/lists/ListHeader.tsx
+++ b/apps/web/components/dashboard/lists/ListHeader.tsx
@@ -1,19 +1,24 @@
"use client";
+import { useMemo } from "react";
import { useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
-import { MoreHorizontal } from "lucide-react";
+import { useTranslation } from "@/lib/i18n/client";
+import { MoreHorizontal, SearchIcon } from "lucide-react";
import { api } from "@hoarder/shared-react/trpc";
+import { parseSearchQuery } from "@hoarder/shared/searchQueryParser";
import { ZBookmarkList } from "@hoarder/shared/types/lists";
+import QueryExplainerTooltip from "../search/QueryExplainerTooltip";
import { ListOptions } from "./ListOptions";
export default function ListHeader({
initialData,
}: {
- initialData: ZBookmarkList & { bookmarks: string[] };
+ initialData: ZBookmarkList;
}) {
+ const { t } = useTranslation();
const router = useRouter();
const { data: list, error } = api.lists.get.useQuery(
{
@@ -24,6 +29,13 @@ export default function ListHeader({
},
);
+ const parsedQuery = useMemo(() => {
+ if (!list.query) {
+ return null;
+ }
+ return parseSearchQuery(list.query);
+ }, [list.query]);
+
if (error) {
// This is usually exercised during list deletions.
if (error.data?.code == "NOT_FOUND") {
@@ -33,10 +45,24 @@ export default function ListHeader({
return (
<div className="flex items-center justify-between">
- <span className="text-2xl">
- {list.icon} {list.name}
- </span>
- <div className="flex">
+ <div className="flex items-center gap-2">
+ <span className="text-2xl">
+ {list.icon} {list.name}
+ </span>
+ </div>
+ <div className="flex items-center">
+ {parsedQuery && (
+ <QueryExplainerTooltip
+ header={
+ <div className="flex items-center justify-center gap-1">
+ <SearchIcon className="size-3" />
+ <span className="text-sm">{t("lists.smart_list")}</span>
+ </div>
+ }
+ parsedSearchQuery={parsedQuery}
+ className="size-6 stroke-foreground"
+ />
+ )}
<ListOptions list={list}>
<Button variant="ghost">
<MoreHorizontal />
diff --git a/apps/web/components/dashboard/lists/ListOptions.tsx b/apps/web/components/dashboard/lists/ListOptions.tsx
index e663a2e0..a7217954 100644
--- a/apps/web/components/dashboard/lists/ListOptions.tsx
+++ b/apps/web/components/dashboard/lists/ListOptions.tsx
@@ -33,7 +33,9 @@ export function ListOptions({
<EditListModal
open={newNestedListModalOpen}
setOpen={setNewNestedListModalOpen}
- parent={list}
+ prefill={{
+ parentId: list.id,
+ }}
/>
<EditListModal
open={editModalOpen}
diff --git a/apps/web/components/dashboard/preview/ActionBar.tsx b/apps/web/components/dashboard/preview/ActionBar.tsx
index 38ad8fa2..86c86d5a 100644
--- a/apps/web/components/dashboard/preview/ActionBar.tsx
+++ b/apps/web/components/dashboard/preview/ActionBar.tsx
@@ -1,5 +1,6 @@
-import { useRouter } from "next/navigation";
+import { useState } from "react";
import { ActionButton } from "@/components/ui/action-button";
+import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
@@ -10,16 +11,16 @@ import { useTranslation } from "@/lib/i18n/client";
import { Trash2 } from "lucide-react";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
-import {
- useDeleteBookmark,
- useUpdateBookmark,
-} from "@hoarder/shared-react/hooks/bookmarks";
+import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks";
+import DeleteBookmarkConfirmationDialog from "../bookmarks/DeleteBookmarkConfirmationDialog";
import { ArchivedActionIcon, FavouritedActionIcon } from "../bookmarks/icons";
export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
const { t } = useTranslation();
- const router = useRouter();
+ const [deleteBookmarkDialogOpen, setDeleteBookmarkDialogOpen] =
+ useState(false);
+
const onError = () => {
toast({
variant: "destructive",
@@ -44,16 +45,6 @@ export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
},
onError,
});
- const { mutate: deleteBookmark, isPending: pendingDeletion } =
- useDeleteBookmark({
- onSuccess: () => {
- toast({
- description: "The bookmark has been deleted!",
- });
- router.back();
- },
- onError,
- });
return (
<div className="flex items-center justify-center gap-3">
@@ -100,17 +91,19 @@ export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
</TooltipContent>
</Tooltip>
<Tooltip delayDuration={0}>
+ <DeleteBookmarkConfirmationDialog
+ bookmark={bookmark}
+ open={deleteBookmarkDialogOpen}
+ setOpen={setDeleteBookmarkDialogOpen}
+ />
<TooltipTrigger asChild>
- <ActionButton
- loading={pendingDeletion}
+ <Button
className="size-14 rounded-full bg-background"
variant="none"
- onClick={() => {
- deleteBookmark({ bookmarkId: bookmark.id });
- }}
+ onClick={() => setDeleteBookmarkDialogOpen(true)}
>
<Trash2 />
- </ActionButton>
+ </Button>
</TooltipTrigger>
<TooltipContent side="bottom">{t("actions.delete")}</TooltipContent>
</Tooltip>
diff --git a/apps/web/components/dashboard/preview/BookmarkPreview.tsx b/apps/web/components/dashboard/preview/BookmarkPreview.tsx
index c257d902..fd70fd4e 100644
--- a/apps/web/components/dashboard/preview/BookmarkPreview.tsx
+++ b/apps/web/components/dashboard/preview/BookmarkPreview.tsx
@@ -114,7 +114,7 @@ export default function BookmarkPreview({
<div className="row-span-2 h-full w-full overflow-auto p-2 md:col-span-2 lg:row-auto">
{isBookmarkStillCrawling(bookmark) ? <ContentLoading /> : content}
</div>
- <div className="lg:col-span1 row-span-1 flex flex-col gap-4 overflow-auto bg-accent p-4 lg:row-auto">
+ <div className="row-span-1 flex flex-col gap-4 overflow-auto bg-accent p-4 md:col-span-2 lg:col-span-1 lg:row-auto">
<div className="flex w-full flex-col items-center justify-center gap-y-2">
<EditableTitle bookmark={bookmark} />
{sourceUrl && (
diff --git a/apps/web/components/dashboard/search/QueryExplainerTooltip.tsx b/apps/web/components/dashboard/search/QueryExplainerTooltip.tsx
new file mode 100644
index 00000000..f5f73be3
--- /dev/null
+++ b/apps/web/components/dashboard/search/QueryExplainerTooltip.tsx
@@ -0,0 +1,162 @@
+import InfoTooltip from "@/components/ui/info-tooltip";
+import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
+import { useTranslation } from "@/lib/i18n/client";
+
+import { TextAndMatcher } from "@hoarder/shared/searchQueryParser";
+import { Matcher } from "@hoarder/shared/types/search";
+
+export default function QueryExplainerTooltip({
+ parsedSearchQuery,
+ header,
+ className,
+}: {
+ header?: React.ReactNode;
+ parsedSearchQuery: TextAndMatcher & { result: string };
+ className?: string;
+}) {
+ const { t } = useTranslation();
+ if (parsedSearchQuery.result == "invalid") {
+ return null;
+ }
+
+ const MatcherComp = ({ matcher }: { matcher: Matcher }) => {
+ switch (matcher.type) {
+ case "tagName":
+ return (
+ <TableRow>
+ <TableCell>
+ {matcher.inverse
+ ? t("search.does_not_have_tag")
+ : t("search.has_tag")}
+ </TableCell>
+ <TableCell>{matcher.tagName}</TableCell>
+ </TableRow>
+ );
+ case "listName":
+ return (
+ <TableRow>
+ <TableCell>
+ {matcher.inverse
+ ? t("search.is_not_in_list")
+ : t("search.is_in_list")}
+ </TableCell>
+ <TableCell>{matcher.listName}</TableCell>
+ </TableRow>
+ );
+ case "dateAfter":
+ return (
+ <TableRow>
+ <TableCell>
+ {matcher.inverse
+ ? t("search.not_created_on_or_after")
+ : t("search.created_on_or_after")}
+ </TableCell>
+ <TableCell>{matcher.dateAfter.toDateString()}</TableCell>
+ </TableRow>
+ );
+ case "dateBefore":
+ return (
+ <TableRow>
+ <TableCell>
+ {matcher.inverse
+ ? t("search.not_created_on_or_before")
+ : t("search.created_on_or_before")}
+ </TableCell>
+ <TableCell>{matcher.dateBefore.toDateString()}</TableCell>
+ </TableRow>
+ );
+ case "favourited":
+ return (
+ <TableRow>
+ <TableCell colSpan={2} className="text-center">
+ {matcher.favourited
+ ? t("search.is_favorited")
+ : t("search.is_not_favorited")}
+ </TableCell>
+ </TableRow>
+ );
+ case "archived":
+ return (
+ <TableRow>
+ <TableCell colSpan={2} className="text-center">
+ {matcher.archived
+ ? t("search.is_archived")
+ : t("search.is_not_archived")}
+ </TableCell>
+ </TableRow>
+ );
+ case "tagged":
+ return (
+ <TableRow>
+ <TableCell colSpan={2} className="text-center">
+ {matcher.tagged
+ ? t("search.has_any_tag")
+ : t("search.has_no_tags")}
+ </TableCell>
+ </TableRow>
+ );
+ case "inlist":
+ return (
+ <TableRow>
+ <TableCell colSpan={2} className="text-center">
+ {matcher.inList
+ ? t("search.is_in_any_list")
+ : t("search.is_not_in_any_list")}
+ </TableCell>
+ </TableRow>
+ );
+ case "and":
+ case "or":
+ return (
+ <TableRow>
+ <TableCell>
+ {matcher.type === "and" ? t("search.and") : t("search.or")}
+ </TableCell>
+ <TableCell>
+ <Table>
+ <TableBody>
+ {matcher.matchers.map((m, i) => (
+ <MatcherComp key={i} matcher={m} />
+ ))}
+ </TableBody>
+ </Table>
+ </TableCell>
+ </TableRow>
+ );
+ case "url":
+ return (
+ <TableRow>
+ <TableCell>
+ {matcher.inverse
+ ? t("search.url_does_not_contain")
+ : t("search.url_contains")}
+ </TableCell>
+ <TableCell>{matcher.url}</TableCell>
+ </TableRow>
+ );
+ default: {
+ const _exhaustiveCheck: never = matcher;
+ return null;
+ }
+ }
+ };
+
+ return (
+ <InfoTooltip className={className}>
+ {header}
+ <Table>
+ <TableBody>
+ {parsedSearchQuery.text && (
+ <TableRow>
+ <TableCell>{t("search.full_text_search")}</TableCell>
+ <TableCell>{parsedSearchQuery.text}</TableCell>
+ </TableRow>
+ )}
+ {parsedSearchQuery.matcher && (
+ <MatcherComp matcher={parsedSearchQuery.matcher} />
+ )}
+ </TableBody>
+ </Table>
+ </InfoTooltip>
+ );
+}
diff --git a/apps/web/components/dashboard/search/SearchInput.tsx b/apps/web/components/dashboard/search/SearchInput.tsx
index 55f304e3..5e46fc18 100644
--- a/apps/web/components/dashboard/search/SearchInput.tsx
+++ b/apps/web/components/dashboard/search/SearchInput.tsx
@@ -1,9 +1,14 @@
"use client";
-import React, { useEffect, useImperativeHandle, useRef } from "react";
+import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
+import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { useDoBookmarkSearch } from "@/lib/hooks/bookmark-search";
import { useTranslation } from "@/lib/i18n/client";
+import { cn } from "@/lib/utils";
+
+import { EditListModal } from "../lists/EditListModal";
+import QueryExplainerTooltip from "./QueryExplainerTooltip";
function useFocusSearchOnKeyPress(
inputRef: React.RefObject<HTMLInputElement>,
@@ -47,7 +52,8 @@ const SearchInput = React.forwardRef<
React.HTMLAttributes<HTMLInputElement> & { loading?: boolean }
>(({ className, ...props }, ref) => {
const { t } = useTranslation();
- const { debounceSearch, searchQuery, isInSearchPage } = useDoBookmarkSearch();
+ const { debounceSearch, searchQuery, parsedSearchQuery, isInSearchPage } =
+ useDoBookmarkSearch();
const [value, setValue] = React.useState(searchQuery);
@@ -59,6 +65,7 @@ const SearchInput = React.forwardRef<
useFocusSearchOnKeyPress(inputRef, onChange);
useImperativeHandle(ref, () => inputRef.current!);
+ const [newNestedListModalOpen, setNewNestedListModalOpen] = useState(false);
useEffect(() => {
if (!isInSearchPage) {
@@ -67,14 +74,38 @@ const SearchInput = React.forwardRef<
}, [isInSearchPage]);
return (
- <Input
- ref={inputRef}
- value={value}
- onChange={onChange}
- placeholder={t("common.search")}
- className={className}
- {...props}
- />
+ <div className={cn("relative flex-1", className)}>
+ <EditListModal
+ open={newNestedListModalOpen}
+ setOpen={setNewNestedListModalOpen}
+ prefill={{
+ type: "smart",
+ query: value,
+ }}
+ />
+ <QueryExplainerTooltip
+ className="-translate-1/2 absolute right-1.5 top-2 stroke-foreground p-0.5"
+ parsedSearchQuery={parsedSearchQuery}
+ />
+ {parsedSearchQuery.result === "full" &&
+ parsedSearchQuery.text.length == 0 && (
+ <Button
+ onClick={() => setNewNestedListModalOpen(true)}
+ size="none"
+ variant="secondary"
+ className="absolute right-9 top-2 z-50 px-2 py-1 text-xs"
+ >
+ {t("actions.save")}
+ </Button>
+ )}
+ <Input
+ ref={inputRef}
+ value={value}
+ onChange={onChange}
+ placeholder={t("common.search")}
+ {...props}
+ />
+ </div>
);
});
SearchInput.displayName = "SearchInput";