@@ -4,13 +4,14 @@ import { cookieStorage } from "~/services/session.server";
44import { User } from "~/types/User" ;
55import { AlertWidget } from "~/components/AlertWidget" ;
66import type { AlertMessage } from "~/types/AlertMessage" ;
7- import { db } from "~/db/connection.server" ;
7+ import { dborm } from "~/db/connection.server" ;
88import { regex_link } from "~/db/schema" ;
99import { LinkTagUrlBuilder } from "~/util/LinkTagUrlBuilder" ;
1010import { TagList } from "~/components/TagList" ;
1111import { authenticator } from "~/services/auth.server" ;
12- import { PiLockKey } from "react-icons/pi" ;
1312import { AdminIcon } from "~/components/AdminIcon" ;
13+ import { getLinkDomain } from "~/util/getLinkDomain" ;
14+ import { ItemLinks } from "~/components/ItemLinks" ;
1415
1516export const meta : MetaFunction = ( ) => {
1617 return [
@@ -27,10 +28,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
2728 const message = session . get ( "message" ) ;
2829 console . log ( "loader message" , JSON . stringify ( message ) ) ;
2930
30- const links = await db . select ( ) . from ( regex_link ) ;
31-
31+ const links = await dborm . select ( ) . from ( regex_link ) ;
32+
3233 const user = authenticator . isAuthenticated ( request ) ;
33-
34+
3435
3536 // Commit the session and return the message
3637 return json (
@@ -51,44 +52,42 @@ export default function Index() {
5152 const message = data . message as AlertMessage | undefined ;
5253
5354 const links = data . links ;
54-
55+
5556 return (
5657 < >
5758 < div className = "d-flex justify-content-between align-items-center" >
5859 < h1 className = "py-2" > Links</ h1 >
59- { user && user . isAdmin ?
60- < div >
61- < RemixLink to = "/links/add.html" className = "btn btn-primary mx-1" > < AdminIcon /> Add</ RemixLink >
60+ { user && user . isAdmin ?
61+ < div >
62+ < RemixLink to = "/links/add.html" className = "btn btn-primary mx-1" > < AdminIcon /> Add</ RemixLink >
6263 < RemixLink to = "/links/import.html" className = "btn btn-primary mx-1" > < AdminIcon /> Import</ RemixLink >
63- </ div >
64- : null }
64+ </ div >
65+ : null }
6566 </ div >
66- { message ? < AlertWidget alert = { message } /> : null }
67- { links . length == 0 ? < div className = "alert alert-warning" > No links found</ div > :
68- < table className = "table table-striped table-hover" >
69- < thead className = "d-none" >
70- < tr >
71- < th > Description</ th >
72- < th > Tags</ th >
73- </ tr >
74- </ thead >
75- < tbody >
76- { links . map ( link => (
77- < tr key = { link . rxl_id } >
78- < td > < a href = { link . rxl_url } > { link . rxl_title } </ a > </ td >
79- < td className = "text-end" >
80- < TagList tags = { link . rxl_tags } urlBuilder = { LinkTagUrlBuilder } />
81- { user && user . isAdmin ?
82- < >
83- < RemixLink to = { `/links/edit.html?rxl_id=${ link . rxl_id } ` } className = "btn btn-sm btn-secondary mx-1" > < AdminIcon /> Edit</ RemixLink >
84- < RemixLink to = { `/links/delete.html?rxl_id=${ link . rxl_id } ` } className = "btn btn-sm btn-secondary mx-1" > < AdminIcon /> Delete</ RemixLink >
85- </ >
86- : null }
87- </ td >
67+ { message ? < AlertWidget alert = { message } /> : null }
68+ { links . length == 0 ? < div className = "alert alert-warning" > No links found</ div > :
69+ < table className = "table table-striped table-hover" >
70+ < thead className = "d-none" >
71+ < tr >
72+ < th > Description</ th >
73+ < th > Tags</ th >
8874 </ tr >
89- ) ) }
90- </ tbody >
91- </ table >
75+ </ thead >
76+ < tbody >
77+ { links . map ( link => (
78+ < tr key = { link . rxl_id } >
79+ < td >
80+ < a className = "me-2" href = { link . rxl_url } > { link . rxl_title } </ a >
81+ ({ getLinkDomain ( link . rxl_url ) } )
82+ </ td >
83+ < td className = "text-end" >
84+ < TagList tags = { link . rxl_tags . sort ( ) } urlBuilder = { LinkTagUrlBuilder } />
85+ { user && user . isAdmin ? < ItemLinks adminOnly = { true } type = "link" id = { link . rxl_id } /> : null }
86+ </ td >
87+ </ tr >
88+ ) ) }
89+ </ tbody >
90+ </ table >
9291 }
9392 </ >
9493 ) ;
0 commit comments