1- import type { MetaFunction } from "@remix-run/node" ;
1+ import type { LoaderFunctionArgs , MetaFunction } from "@remix-run/node" ;
22import { json , Link as RemixLink , useLoaderData , useSearchParams } from "@remix-run/react" ;
33import { dbconnection } from "~/db/connection.server" ;
44import { TagTree , TagTreeEntry } from "~/components/TagTree" ;
5+ import { authenticator } from "~/services/auth.server" ;
56
67
78export const meta : MetaFunction = ( ) => {
@@ -10,7 +11,9 @@ export const meta: MetaFunction = () => {
1011 ] ;
1112} ;
1213
13- export async function loader ( ) {
14+ export async function loader ( { request } : LoaderFunctionArgs ) {
15+
16+ const user = await authenticator . isAuthenticated ( request ) ;
1417
1518 const taglinks = await dbconnection `SELECT rxl_id, rxl_title, rxl_url, UNNEST(rxl_tags) as tag FROM regex_link ORDER BY tag` ;
1619
@@ -22,7 +25,11 @@ export async function loader() {
2225 links = [ ] ;
2326 tagmap [ tag ] = links ;
2427 }
25- links . push ( { id : taglink . rxl_id , title : taglink . rxl_title , url : taglink . rxl_url } ) ;
28+ links . push ( {
29+ id : taglink . rxl_id ,
30+ title : taglink . rxl_title ,
31+ url : user ?. isAdmin ? `/links/edit.html?rxl_id=${ encodeURIComponent ( taglink . rxl_id ) } ` : taglink . rxl_url
32+ } ) ;
2633 }
2734
2835 return json ( tagmap ) ;
@@ -37,7 +44,10 @@ export default function Tags() {
3744 < >
3845 < h1 className = "py-2" > Links by Tag</ h1 >
3946 { TagTree ( currentTag , tagMap ) }
40- < RemixLink to = "/links/untagged.html" className = "btn btn-primary" > Untagged</ RemixLink >
47+ < div className = "mt-3" >
48+ { Object . entries ( tagMap ) . length } tags
49+ </ div >
50+ < RemixLink to = "/links/untagged.html" className = "btn btn-primary mt-3" > Untagged</ RemixLink >
4151 </ >
4252 ) ;
4353
0 commit comments