@@ -2,32 +2,22 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
2
2
import { json , Link as RemixLink , useLoaderData , useParams , useRouteLoaderData } from "@remix-run/react" ;
3
3
import { desc , sql } from "drizzle-orm" ;
4
4
5
- import { cookieStorage } from "~/services/session.server" ;
6
5
import { User } from "~/types/User" ;
7
6
import { AlertWidget } from "~/components/AlertWidget" ;
8
- import type { AlertMessage } from "~/types/AlertMessage" ;
9
7
import { dborm } from "~/db/connection.server" ;
10
8
import { regex_link } from "~/db/schema" ;
11
9
import { authenticator } from "~/services/auth.server" ;
12
- import { AdminIcon } from "~/components/AdminIcon" ;
13
10
import LinksTable from "~/components/LinksTable" ;
14
11
import { PiArrowFatUpBold , PiCaretLeftBold , PiCaretRightBold } from "react-icons/pi" ;
12
+ import { MIN_ARCHIVE_YEAR } from "~/util/constants" ;
15
13
16
14
export const meta : MetaFunction = ( { params } ) => {
17
15
return [
18
16
{ title : `Links Archive for ${ params . year } - Regex Zone` } ,
19
17
] ;
20
18
} ;
21
19
22
- const MIN_YEAR = 2007 ;
23
-
24
20
export 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 ) ) ;
31
21
32
22
if ( ! params || ! params . year || ! / ^ 2 \d { 3 } $ / . test ( params . year ) ) {
33
23
throw new Error ( "Invalid year" ) ;
@@ -43,14 +33,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
43
33
44
34
// Commit the session and return the message
45
35
return json (
46
- { links, message, user } ,
47
- {
48
- headers : {
49
- "Set-Cookie" : await cookieStorage . commitSession ( session ) ,
50
- } ,
51
- }
36
+ { links, user } ,
52
37
) ;
53
38
}
39
+
54
40
export default function Index ( ) {
55
41
const params = useParams ( ) ;
56
42
const user = useRouteLoaderData < User | null > ( "root" ) ;
@@ -59,27 +45,21 @@ export default function Index() {
59
45
const currentYear = new Date ( ) . getFullYear ( ) ;
60
46
const year = parseInt ( params . year || currentYear . toString ( ) ) ;
61
47
62
-
63
- console . log ( "func message" , JSON . stringify ( data ) ) ;
64
-
65
- const message = data . message as AlertMessage | undefined ;
66
-
67
48
const links = data . links as unknown as typeof regex_link . $inferSelect [ ] ;
68
49
69
50
return (
70
51
< >
71
52
< div className = "d-flex justify-content-between align-items-center" >
72
53
< 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 >
78
59
</ 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 } />
83
63
}
84
64
</ >
85
65
) ;
0 commit comments