|
| 1 | +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; |
| 2 | +import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { Routes, Route, Link, useLocation } from "react-router-dom"; |
| 5 | +import { IdTokenExample } from "./components/IdTokenExample"; |
| 6 | +import { CollectionQueryExample } from "./components/CollectionQueryExample"; |
| 7 | + |
| 8 | +import "./firebase"; |
| 9 | + |
| 10 | +function App() { |
| 11 | + const [queryClient] = useState( |
| 12 | + () => |
| 13 | + new QueryClient({ |
| 14 | + defaultOptions: { |
| 15 | + queries: { |
| 16 | + staleTime: 60 * 1000, |
| 17 | + }, |
| 18 | + }, |
| 19 | + }) |
| 20 | + ); |
| 21 | + |
| 22 | + return ( |
| 23 | + <QueryClientProvider client={queryClient}> |
| 24 | + <div className="min-h-screen bg-gray-50"> |
| 25 | + <Navigation /> |
| 26 | + <div className="py-12"> |
| 27 | + <div className="max-w-6xl mx-auto px-4"> |
| 28 | + <Routes> |
| 29 | + <Route path="/" element={<Home />} /> |
| 30 | + <Route path="/auth/id-token" element={<IdTokenExample />} /> |
| 31 | + <Route |
| 32 | + path="/firestore/collection-query" |
| 33 | + element={<CollectionQueryExample />} |
| 34 | + /> |
| 35 | + </Routes> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + <ReactQueryDevtools initialIsOpen={false} /> |
| 40 | + </QueryClientProvider> |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +function Navigation() { |
| 45 | + const location = useLocation(); |
| 46 | + |
| 47 | + const navItems = [ |
| 48 | + { path: "/", label: "Home" }, |
| 49 | + { path: "/auth/id-token", label: "ID Token Query" }, |
| 50 | + { path: "/firestore/collection-query", label: "Collection Query" }, |
| 51 | + ]; |
| 52 | + |
| 53 | + return ( |
| 54 | + <nav className="bg-white shadow-sm border-b"> |
| 55 | + <div className="max-w-6xl mx-auto px-4"> |
| 56 | + <div className="flex items-center justify-between h-16"> |
| 57 | + <div className="flex items-center space-x-8"> |
| 58 | + <h1 className="text-xl font-bold text-gray-900"> |
| 59 | + TanStack Query Firebase |
| 60 | + </h1> |
| 61 | + <div className="flex space-x-4"> |
| 62 | + {navItems.map((item) => ( |
| 63 | + <Link |
| 64 | + key={item.path} |
| 65 | + to={item.path} |
| 66 | + className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${ |
| 67 | + location.pathname === item.path |
| 68 | + ? "bg-blue-100 text-blue-700" |
| 69 | + : "text-gray-600 hover:text-gray-900 hover:bg-gray-100" |
| 70 | + }`} |
| 71 | + > |
| 72 | + {item.label} |
| 73 | + </Link> |
| 74 | + ))} |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + </nav> |
| 80 | + ); |
| 81 | +} |
| 82 | + |
| 83 | +function Home() { |
| 84 | + return ( |
| 85 | + <div className="text-center"> |
| 86 | + <h1 className="text-4xl font-bold text-gray-900 mb-4"> |
| 87 | + TanStack Query Firebase Examples |
| 88 | + </h1> |
| 89 | + <p className="text-xl text-gray-600 mb-8"> |
| 90 | + Explore different Firebase hooks and patterns with TanStack Query |
| 91 | + </p> |
| 92 | + |
| 93 | + <div className="grid md:grid-cols-2 gap-6 max-w-4xl mx-auto"> |
| 94 | + <div className="bg-white rounded-lg shadow-md p-6"> |
| 95 | + <h2 className="text-2xl font-bold text-gray-900 mb-4"> |
| 96 | + Authentication |
| 97 | + </h2> |
| 98 | + <p className="text-gray-600 mb-4"> |
| 99 | + Examples of Firebase Authentication hooks including ID token |
| 100 | + management. |
| 101 | + </p> |
| 102 | + <Link |
| 103 | + to="/auth/id-token" |
| 104 | + className="inline-block bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition-colors" |
| 105 | + > |
| 106 | + View ID Token Example |
| 107 | + </Link> |
| 108 | + </div> |
| 109 | + |
| 110 | + <div className="bg-white rounded-lg shadow-md p-6"> |
| 111 | + <h2 className="text-2xl font-bold text-gray-900 mb-4">Firestore</h2> |
| 112 | + <p className="text-gray-600 mb-4"> |
| 113 | + Examples of Firestore hooks for querying collections and documents. |
| 114 | + </p> |
| 115 | + <Link |
| 116 | + to="/firestore/collection-query" |
| 117 | + className="inline-block bg-green-600 text-white px-4 py-2 rounded-md hover:bg-green-700 transition-colors" |
| 118 | + > |
| 119 | + View Collection Query Example |
| 120 | + </Link> |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + |
| 124 | + <div className="mt-12 text-center"> |
| 125 | + <p className="text-gray-500"> |
| 126 | + Built with Vite, TanStack Query, React Router, and Firebase |
| 127 | + </p> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + ); |
| 131 | +} |
| 132 | + |
| 133 | +export default App; |
0 commit comments