|
| 1 | +import { useState } from "react"; |
| 2 | +import { useRevalidator } from "react-router"; |
| 3 | +import { Input } from "~/components/input"; |
| 4 | +import { getPublic } from "~/utils/.client/public"; |
| 5 | +import { getCommon } from "~/utils/.common/common"; |
| 6 | +import { getSecret } from "~/utils/.server/secret"; |
| 7 | +import { getEnv } from "~/utils/env.server"; |
| 8 | +import dbLogo from "/images/database.svg"; |
| 9 | +import type { Route } from "./+types/_index"; |
| 10 | + |
| 11 | +export function loader() { |
| 12 | + console.log(getSecret(), getCommon()); |
| 13 | + return { |
| 14 | + env: getEnv(), |
| 15 | + }; |
| 16 | +} |
| 17 | + |
| 18 | +export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) { |
| 19 | + console.log(getPublic(), getCommon()); |
| 20 | + return { |
| 21 | + ...(await serverLoader()), |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +clientLoader.hydrate = true; |
| 26 | + |
| 27 | +export default function Index({ loaderData: data }: Route.ComponentProps) { |
| 28 | + const [value, setValue] = useState(""); |
| 29 | + console.log("dbLogo", dbLogo); |
| 30 | + console.log("value", value); |
| 31 | + const { revalidate } = useRevalidator(); |
| 32 | + return ( |
| 33 | + <div className="min-h-screen bg-gray-100 flex flex-col items-center justify-center"> |
| 34 | + <button type="button" onClick={revalidate} className="flex items-center gap-2"> |
| 35 | + <img src={dbLogo} alt="Database" /> |
| 36 | + Revalidate |
| 37 | + </button> |
| 38 | + <input /> |
| 39 | + <Input value={value} onChange={(e) => setValue(e.target.value)} /> |
| 40 | + <div className="mt-8 w-full max-w-4xl overflow-x-auto"> |
| 41 | + <table className="w-full border-collapse bg-gray-100 shadow-md rounded-lg"> |
| 42 | + <thead> |
| 43 | + <tr className="bg-gray-200"> |
| 44 | + <th className="px-6 py-3 text-left text-xs font-medium text-gray-600 uppercase tracking-wider">Key</th> |
| 45 | + <th className="px-6 py-3 text-left text-xs font-medium text-gray-600 uppercase tracking-wider">Value</th> |
| 46 | + </tr> |
| 47 | + </thead> |
| 48 | + <tbody className="bg-white divide-y divide-gray-200"> |
| 49 | + {Object.entries(data.env).map(([key, value]) => ( |
| 50 | + <tr key={key} className="hover:bg-gray-50"> |
| 51 | + <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{key}</td> |
| 52 | + <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{value ?? "-"}</td> |
| 53 | + </tr> |
| 54 | + ))} |
| 55 | + </tbody> |
| 56 | + </table> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + ); |
| 60 | +} |
0 commit comments