Welcome to Homelab Connector
Or sign in to access the dashboard.
diff --git a/src/app/paperless/document-search.tsx b/src/app/paperless/document-search.tsx
deleted file mode 100644
index 41b7554..0000000
--- a/src/app/paperless/document-search.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-"use client";
-
-import { usePathname, useRouter, useSearchParams } from "next/navigation";
-import { useForm } from "react-hook-form";
-import { z } from "zod";
-import { Button } from "~/components/ui/button";
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
-} from "~/components/ui/form";
-import { Input } from "~/components/ui/input";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { useCallback } from "react";
-
-const formSchema = z.object({
- query: z.string().min(3).max(256),
-});
-
-export default function DocumentsSearch() {
- const router = useRouter();
- const pathname = usePathname();
- const searchParams = useSearchParams();
- const givenQuery = searchParams.get("query") || "";
- // 1. Define your form.
- const form = useForm
>({
- resolver: zodResolver(formSchema),
- defaultValues: {
- query: givenQuery,
- },
- });
-
- const createQueryString = useCallback(
- (name: string, value: string) => {
- const params = new URLSearchParams(searchParams.toString());
- params.set(name, value);
-
- return params.toString();
- },
- [searchParams],
- );
-
- function onSubmit(values: z.infer) {
- if (values["query"]) router.replace(pathname + "?" + createQueryString("query", values["query"]));
- }
-
- return (
-
-
- );
-}
\ No newline at end of file
diff --git a/src/app/paperless/documents-page.tsx b/src/app/paperless/documents-page.tsx
deleted file mode 100644
index c7280fa..0000000
--- a/src/app/paperless/documents-page.tsx
+++ /dev/null
@@ -1,109 +0,0 @@
-import { ExternalLink, LoaderCircle } from "lucide-react";
-import { useSearchParams } from "next/navigation";
-import { useEffect } from "react";
-import {
- useQuery,
- QueryClientProvider,
- QueryClient,
-} from "@tanstack/react-query";
-
-const queryClient = new QueryClient();
-
-type DataType = {
- data: {
- total: number;
- documents: {
- added: string;
- archive_serial_number: string;
- archived_file_name: string;
- content: string;
- correspondent: string;
- created: string;
- created_date: string;
- custom_fields: [];
- document_type: number;
- id: number;
- is_shared_by_requester: boolean;
- modified: string;
- notes: [];
- original_file_name: string;
- owner: number;
- storage_path: number;
- tags: [];
- title: string;
- user_can_change: boolean;
- }[];
- saved_views: [];
- correspondents: [];
- document_types: [];
- storage_paths: [];
- tags: [];
- users: [];
- groups: [];
- mail_accounts: [];
- mail_rules: [];
- custom_fields: [];
- workflows: [];
- };
-};
-
-function Documents() {
- const searchParams = useSearchParams();
- const query = searchParams.get("query");
-
- const QueryResult = useQuery({
- queryKey: ["key"],
- queryFn: async () => {
- const response = await fetch("/api/paperless?query=" + query);
- const data = (await response.json()) as DataType;
- console.log("data just got got");
- return data;
- },
- });
-
- useEffect(() => {
- queryClient.refetchQueries();
- }, [query]);
-
- return (
-
- {QueryResult.isLoading ? (
-
-
- Loading...
-
- ) : QueryResult.data?.data ? (
-
- ) : (
-
Start searching!
- )}
-
- );
-}
-
-export default function DocumentsPage() {
- return (
-
-
-
-
-
- );
-}
\ No newline at end of file
diff --git a/src/app/paperless/page.tsx b/src/app/paperless/page.tsx
index e9fb1f3..0f77e2f 100644
--- a/src/app/paperless/page.tsx
+++ b/src/app/paperless/page.tsx
@@ -1,8 +1,170 @@
"use client";
import { SignedIn, SignedOut } from "@clerk/nextjs";
-import DocumentsSearch from "./document-search";
-import DocuemntsPage from "./documents-page";
+import { usePathname, useRouter, useSearchParams } from "next/navigation";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+import { Button } from "@/components/ui/button";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+} from "@/components/ui/form";
+import { Input } from "@/components/ui/input";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useCallback } from "react";
+import { ExternalLink } from "lucide-react";
+import { useEffect } from "react";
+import {
+ useQuery,
+ QueryClientProvider,
+ QueryClient,
+} from "@tanstack/react-query";
+import LoadingSpinner from "@/components/loading-spinner";
+
+const queryClient = new QueryClient();
+
+function DocumentsSearch() {
+ const formSchema = z.object({
+ query: z.string().min(3).max(256),
+ });
+ const router = useRouter();
+ const pathname = usePathname();
+ const searchParams = useSearchParams();
+ const givenQuery = searchParams.get("query") || "";
+ // 1. Define your form.
+ const form = useForm>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ query: givenQuery,
+ },
+ });
+
+ const createQueryString = useCallback(
+ (name: string, value: string) => {
+ const params = new URLSearchParams(searchParams.toString());
+ params.set(name, value);
+
+ return params.toString();
+ },
+ [searchParams],
+ );
+
+ function onSubmit(values: z.infer) {
+ if (values["query"])
+ router.replace(
+ pathname + "?" + createQueryString("query", values["query"]),
+ );
+ }
+
+ return (
+
+
+ );
+}
+
+function DocumentsPage() {
+ type DataType = {
+ data: {
+ total: number;
+ documents: {
+ added: string;
+ archive_serial_number: string;
+ archived_file_name: string;
+ content: string;
+ correspondent: string;
+ created: string;
+ created_date: string;
+ custom_fields: [];
+ document_type: number;
+ id: number;
+ is_shared_by_requester: boolean;
+ modified: string;
+ notes: [];
+ original_file_name: string;
+ owner: number;
+ storage_path: number;
+ tags: [];
+ title: string;
+ user_can_change: boolean;
+ }[];
+ saved_views: [];
+ correspondents: [];
+ document_types: [];
+ storage_paths: [];
+ tags: [];
+ users: [];
+ groups: [];
+ mail_accounts: [];
+ mail_rules: [];
+ custom_fields: [];
+ workflows: [];
+ };
+ };
+ const searchParams = useSearchParams();
+ const query = searchParams.get("query");
+
+ const QueryResult = useQuery({
+ queryKey: ["key"],
+ queryFn: async () => {
+ const response = await fetch("/api/paperless?query=" + query);
+ const data = (await response.json()) as DataType;
+ return data;
+ },
+ });
+
+ useEffect(() => {
+ queryClient.refetchQueries();
+ }, [query]);
+
+ return (
+
+ {QueryResult.isLoading ? (
+
Loading...
+ ) : QueryResult.data?.data ? (
+
+ ) : (
+
Start searching!
+ )}
+
+ );
+}
export default function PaperlessPage() {
return (
@@ -14,12 +176,16 @@ export default function PaperlessPage() {