1
- import type { MetaFunction } from "@remix-run/node" ;
1
+ import type { LoaderFunctionArgs , MetaFunction } from "@remix-run/node" ;
2
2
import { json , Link as RemixLink , useLoaderData , useSearchParams } from "@remix-run/react" ;
3
3
import { dbconnection } from "~/db/connection.server" ;
4
4
import { TagTree , TagTreeEntry } from "~/components/TagTree" ;
5
+ import { authenticator } from "~/services/auth.server" ;
5
6
6
7
7
8
export const meta : MetaFunction = ( ) => {
@@ -10,7 +11,9 @@ export const meta: MetaFunction = () => {
10
11
] ;
11
12
} ;
12
13
13
- export async function loader ( ) {
14
+ export async function loader ( { request } : LoaderFunctionArgs ) {
15
+
16
+ const user = await authenticator . isAuthenticated ( request ) ;
14
17
15
18
const taglinks = await dbconnection `SELECT rxl_id, rxl_title, rxl_url, UNNEST(rxl_tags) as tag FROM regex_link ORDER BY tag` ;
16
19
@@ -22,7 +25,11 @@ export async function loader() {
22
25
links = [ ] ;
23
26
tagmap [ tag ] = links ;
24
27
}
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
+ } ) ;
26
33
}
27
34
28
35
return json ( tagmap ) ;
@@ -37,7 +44,10 @@ export default function Tags() {
37
44
< >
38
45
< h1 className = "py-2" > Links by Tag</ h1 >
39
46
{ 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 >
41
51
</ >
42
52
) ;
43
53
0 commit comments