⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
feat(search): display note in search bar when there are unindexed links
daniel31x13549299743cfe
diff --git a/apps/web/components/SearchBar.tsx b/apps/web/components/SearchBar.tsxindex 19eda9ad..4a0b264f 100644--- a/apps/web/components/SearchBar.tsx+++ b/apps/web/components/SearchBar.tsx@@ -4,6 +4,7 @@ import { useRouter } from "next/router";import { toast } from "react-hot-toast";import { useTranslation } from "next-i18next";import { Button } from "@/components/ui/button";+import { useUser } from "@linkwarden/router/user";type Props = {placeholder?: string;@@ -71,9 +72,11 @@ export default function SearchBar({ placeholder }: Props) {const router = useRouter();const { t } = useTranslation();const [searchQuery, setSearchQuery] = useState("");- const [isFocused, setIsFocused] = useState(false);const [showSuggestions, setShowSuggestions] = useState(false);const inputRef = useRef<HTMLInputElement>(null);+ const { data: user } = useUser();++ const [dismissSearchNote, setDismissSearchNote] = useState(false);useEffect(() => {router.query.q@@ -106,11 +109,9 @@ export default function SearchBar({ placeholder }: Props) {placeholder={placeholder || t("search_for_links")}value={searchQuery}onFocus={() => {- setIsFocused(true);setShowSuggestions(true);}}onBlur={() => {- setIsFocused(false);setShowSuggestions(false);}}onChange={(e) => {@@ -157,7 +158,7 @@ export default function SearchBar({ placeholder }: Props) {<buttonkey={entry.operator}type="button"- className="flex items-center gap-2 justify-between rounded-md px-2 py-1 text-left hover:bg-base-100 duration-100"+ className="flex items-center gap-2 justify-between rounded-md px-2 py-1 text-left hover:bg-neutral-content duration-100"onClick={() => handleSuggestionClick(entry.operator)}><div className="flex items-center gap-2">@@ -173,7 +174,7 @@ export default function SearchBar({ placeholder }: Props) {))}</div><div className="flex justify-end">- <Button asChild variant="simple" size="sm" className="text-xs">+ <Button asChild variant="ghost" size="sm" className="text-xs"><Linkhref="https://docs.linkwarden.app/Usage/advanced-search"target="_blank"@@ -184,6 +185,26 @@ export default function SearchBar({ placeholder }: Props) {</Link></Button></div>++ {user?.hasUnIndexedLinks && !dismissSearchNote ? (+ <div+ role="alert"+ className="border border-neutral p-2 my-1 rounded flex flex-col gap-2"+ >+ <p className="text-xs text-neutral">+ <i className="bi-info-circle text-primary mr-1" />+ <b>{t("note")}:</b> {t("search_unindexed_links_in_bg_info")}+ </p>+ <Button+ variant="ghost"+ size="sm"+ className="w-full"+ onClick={() => setDismissSearchNote(true)}+ >+ Dismiss+ </Button>+ </div>+ ) : undefined}</div></div>)}diff --git a/apps/web/lib/api/controllers/users/userId/getUserById.ts b/apps/web/lib/api/controllers/users/userId/getUserById.tsindex 6d4cb45e..7e95c7b5 100644--- a/apps/web/lib/api/controllers/users/userId/getUserById.ts+++ b/apps/web/lib/api/controllers/users/userId/getUserById.ts@@ -1,37 +1,35 @@+import { MEILI_INDEX_VERSION } from "@linkwarden/lib/constants";import { prisma } from "@linkwarden/prisma";-import {- DashboardSection,- Subscription,- User,-} from "@linkwarden/prisma/client";--type GetUserByIdResponse = Omit<User, "password"> &- Partial<{ subscription: Pick<Subscription, "active" | "quantity"> }> & {- parentSubscription: {- active: boolean | undefined;- user: {- email: string | null | undefined;- };- };- } & {- dashboardSections: DashboardSection[];- };+import { GetUserByIdResponse } from "@linkwarden/types/global";export default async function getUserById(userId: number) {- const user = await prisma.user.findUnique({- where: {- id: userId,- },- include: {- subscriptions: true,- parentSubscription: {- include: {- user: true,+ const [user, firstUnIndexedLinks] = await Promise.all([+ prisma.user.findUnique({+ where: {+ id: userId,+ },+ include: {+ subscriptions: true,+ parentSubscription: {+ include: {+ user: true,+ },},+ dashboardSections: true,},- dashboardSections: true,- },- });+ }),+ prisma.link.findFirst({+ where: {+ collection: {+ OR: [{ ownerId: userId }, { members: { some: { userId } } }],+ },+ OR: [+ { indexVersion: null },+ { NOT: { indexVersion: MEILI_INDEX_VERSION } },+ ],+ },+ }),+ ]);if (!user) return { response: "User not found.", status: 404 };@@ -50,6 +48,7 @@ export default async function getUserById(userId: number) {email: parentSubscription?.user.email,},},+ hasUnIndexedLinks: !!firstUnIndexedLinks,};return { response: data, status: 200 };diff --git a/apps/web/public/locales/en/common.json b/apps/web/public/locales/en/common.jsonindex 2594327f..e283c320 100644--- a/apps/web/public/locales/en/common.json+++ b/apps/web/public/locales/en/common.json@@ -548,5 +548,7 @@"regenerate_broken_links": "Regenerate Broken Links","regenerate_all_links": "Regenerate All Links","regenerate_broken_preserved_content_desc": "<0>Delete and re-preserve broken links with at least one missing preserved format.</0><0>This action will immediately delete any existing preserved format for {{count}} links.</0><0>Affected links will be scheduled to have their preserved formats rebuilt.</0>",- "delete_all_preserved_content_and_regenerate_desc": "<0>This action will immediately delete all your existing preserved formats.</0><0>Affected links will be scheduled to have their preserved formats rebuilt.</0>"+ "delete_all_preserved_content_and_regenerate_desc": "<0>This action will immediately delete all your existing preserved formats.</0><0>Affected links will be scheduled to have their preserved formats rebuilt.</0>",+ "note": "Note",+ "search_unindexed_links_in_bg_info": "Search may be less accurate because some links are still being processed."}diff --git a/packages/router/user.tsx b/packages/router/user.tsxindex e54be22a..38eeef1c 100644--- a/packages/router/user.tsx+++ b/packages/router/user.tsx@@ -4,7 +4,7 @@ import {Subscription,User,} from "@linkwarden/prisma/client";-import { MobileAuth } from "@linkwarden/types/global";+import { GetUserByIdResponse, MobileAuth } from "@linkwarden/types/global";import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";import { useSession } from "next-auth/react";@@ -40,17 +40,7 @@ const useUser = (auth?: MobileAuth) => {if (!response.ok) throw new Error("Failed to fetch user data.");- const data = (await response.json()).response as Omit<User, "password"> &- Partial<{ subscription: Subscription }> & {- parentSubscription: {- active: boolean | undefined;- user: {- email: string | null | undefined;- };- };- } & {- dashboardSections: DashboardSection[];- };+ const data = (await response.json()).response as GetUserByIdResponse;if (!auth)document.querySelector("html")?.setAttribute("data-theme", data.theme);@@ -60,17 +50,7 @@ const useUser = (auth?: MobileAuth) => {enabled: !auth? !!userId && status === "authenticated": status === "authenticated",- placeholderData: {} as Omit<User, "password"> &- Partial<{ subscription: Subscription }> & {- parentSubscription: {- active: boolean | undefined;- user: {- email: string | null | undefined;- };- };- } & {- dashboardSections: DashboardSection[];- },+ placeholderData: {} as GetUserByIdResponse,});};diff --git a/packages/types/global.ts b/packages/types/global.tsindex 9913e72d..85a19aa8 100644--- a/packages/types/global.ts+++ b/packages/types/global.ts@@ -1,4 +1,11 @@-import { Collection, Link, Tag, User } from "@linkwarden/prisma/client";+import {+ Collection,+ Link,+ Tag,+ User,+ DashboardSection,+ Subscription,+} from "@linkwarden/prisma/client";import Stripe from "stripe";type OptionalExcluding<T, TRequired extends keyof T> = Partial<T> &@@ -200,3 +207,16 @@ export interface WorkerStats {done: number;};}++export type GetUserByIdResponse = Omit<User, "password"> &+ Partial<{ subscription: Pick<Subscription, "active" | "quantity"> }> & {+ parentSubscription: {+ active: boolean | undefined;+ user: {+ email: string | null | undefined;+ };+ };+ } & {+ dashboardSections: DashboardSection[];+ hasUnIndexedLinks: boolean;+ };