@@ -2,32 +2,22 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
22import { json , Link as RemixLink , useLoaderData , useParams , useRouteLoaderData } from "@remix-run/react" ;
33import { desc , sql } from "drizzle-orm" ;
44
5- import { cookieStorage } from "~/services/session.server" ;
65import { User } from "~/types/User" ;
76import { AlertWidget } from "~/components/AlertWidget" ;
8- import type { AlertMessage } from "~/types/AlertMessage" ;
97import { dborm } from "~/db/connection.server" ;
108import { regex_link } from "~/db/schema" ;
119import { authenticator } from "~/services/auth.server" ;
12- import { AdminIcon } from "~/components/AdminIcon" ;
1310import LinksTable from "~/components/LinksTable" ;
1411import { PiArrowFatUpBold , PiCaretLeftBold , PiCaretRightBold } from "react-icons/pi" ;
12+ import { MIN_ARCHIVE_YEAR } from "~/util/constants" ;
1513
1614export const meta : MetaFunction = ( { params } ) => {
1715 return [
1816 { title : `Links Archive for ${ params . year } - Regex Zone` } ,
1917 ] ;
2018} ;
2119
22- const MIN_YEAR = 2007 ;
23-
2420export async function loader ( { request, params } : LoaderFunctionArgs ) {
25- // Retrieves the current session from the incoming request's Cookie header
26- const session = await cookieStorage . getSession ( request . headers . get ( "Cookie" ) ) ;
27-
28- // Retrieve the session value set in the previous request
29- const message = session . get ( "message" ) ;
30- console . log ( "loader message" , JSON . stringify ( message ) ) ;
3121
3222 if ( ! params || ! params . year || ! / ^ 2 \d { 3 } $ / . test ( params . year ) ) {
3323 throw new Error ( "Invalid year" ) ;
@@ -43,14 +33,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
4333
4434 // Commit the session and return the message
4535 return json (
46- { links, message, user } ,
47- {
48- headers : {
49- "Set-Cookie" : await cookieStorage . commitSession ( session ) ,
50- } ,
51- }
36+ { links, user } ,
5237 ) ;
5338}
39+
5440export default function Index ( ) {
5541 const params = useParams ( ) ;
5642 const user = useRouteLoaderData < User | null > ( "root" ) ;
@@ -59,27 +45,21 @@ export default function Index() {
5945 const currentYear = new Date ( ) . getFullYear ( ) ;
6046 const year = parseInt ( params . year || currentYear . toString ( ) ) ;
6147
62-
63- console . log ( "func message" , JSON . stringify ( data ) ) ;
64-
65- const message = data . message as AlertMessage | undefined ;
66-
6748 const links = data . links as unknown as typeof regex_link . $inferSelect [ ] ;
6849
6950 return (
7051 < >
7152 < div className = "d-flex justify-content-between align-items-center" >
7253 < h1 className = "py-2" > Links Archive for { year } </ h1 >
73- < div >
74- { year > MIN_YEAR ? < RemixLink to = { `/links/archive/${ year - 1 } /` } className = "btn btn-primary mx-1" > < PiCaretLeftBold /> { year - 1 } </ RemixLink > : null }
75- < RemixLink to = "/links/archive/" className = "btn btn-primary" > < PiArrowFatUpBold /> </ RemixLink >
76- { year < currentYear ? < RemixLink to = { `/links/archive/${ year + 1 } /` } className = "btn btn-primary mx-1" > { year + 1 } < PiCaretRightBold /> </ RemixLink > : null }
77- </ div >
54+ < div >
55+ { year > MIN_ARCHIVE_YEAR ? < RemixLink to = { `/links/archive/${ year - 1 } /` } className = "btn btn-primary mx-1" > < PiCaretLeftBold /> { year - 1 } </ RemixLink > : null }
56+ < RemixLink to = "/links/archive/" className = "btn btn-primary" > < PiArrowFatUpBold /> </ RemixLink >
57+ { year < currentYear ? < RemixLink to = { `/links/archive/${ year + 1 } /` } className = "btn btn-primary mx-1" > { year + 1 } < PiCaretRightBold /> </ RemixLink > : null }
58+ </ div >
7859 </ div >
79- { message ? < AlertWidget alert = { message } /> : null }
80- { links . length == 0
81- ? < AlertWidget alert = { { type : "danger" , message : `No links for ${ year } ` } } />
82- : < LinksTable currentUrl = { `/links/archive/${ year } /` } links = { links } isAdmin = { user ?. isAdmin } />
60+ { links . length == 0
61+ ? < AlertWidget alert = { { type : "danger" , message : `No links for ${ year } ` } } />
62+ : < LinksTable currentUrl = { `/links/archive/${ year } /` } links = { links } isAdmin = { user ?. isAdmin } />
8363 }
8464 </ >
8565 ) ;
0 commit comments