1
- import type { ActionFunction , LoaderFunction } from "react-router" ;
2
- import { data , useLoaderData } from "react-router" ;
3
- import type { LabelHTMLAttributes } from "react" ;
1
+ import type { LoaderFunction } from "react-router" ;
2
+ import { data , useLoaderData , useNavigation } from "react-router" ;
3
+ import type { LabelHTMLAttributes , PropsWithChildren } from "react" ;
4
4
import { getTopParticipants } from "#~/models/activity.server" ;
5
5
6
6
export const loader = async ( {
@@ -18,6 +18,7 @@ export const loader = async ({
18
18
}
19
19
20
20
const REACTIFLUX_GUILD_ID = "102860784329052160" ;
21
+
21
22
const output = await getTopParticipants (
22
23
REACTIFLUX_GUILD_ID ,
23
24
start ,
@@ -29,43 +30,64 @@ export const loader = async ({
29
30
return output ;
30
31
} ;
31
32
32
- export const action : ActionFunction = async ( { request } ) => {
33
- console . log ( { request } ) ;
34
- } ;
35
-
36
33
const Label = ( props : LabelHTMLAttributes < Element > ) => (
37
34
< label { ...props } className = { `${ props . className ?? "" } m-4` } >
38
35
{ props . children }
39
36
</ label >
40
37
) ;
41
38
42
- const formatter = new Intl . NumberFormat ( "en-US" , {
39
+ const percent = new Intl . NumberFormat ( "en-US" , {
43
40
style : "percent" ,
44
41
maximumFractionDigits : 0 ,
45
- } ) ;
42
+ } ) . format ;
43
+
44
+ function RangeForm ( ) {
45
+ return (
46
+ < form method = "GET" >
47
+ < Label >
48
+ Start date
49
+ < input name = "start" type = "date" />
50
+ </ Label >
51
+ < Label >
52
+ End date
53
+ < input name = "end" type = "date" />
54
+ </ Label >
55
+ < input type = "submit" value = "Submit" />
56
+ </ form >
57
+ ) ;
58
+ }
59
+
60
+ const DataHeading = ( { children } : PropsWithChildren ) => {
61
+ return (
62
+ < th className = "relative origin-bottom-left -rotate-45 max-w-8 text-nowrap" >
63
+ { children }
64
+ </ th >
65
+ ) ;
66
+ } ;
46
67
47
68
export default function DashboardPage ( ) {
69
+ const nav = useNavigation ( ) ;
48
70
const data = useLoaderData < typeof loader > ( ) ;
49
71
50
- if ( ! data ) {
72
+ if ( nav . state === "loading" ) {
51
73
return "loading…" ;
52
74
}
53
75
76
+ if ( ! data ) {
77
+ return (
78
+ < div >
79
+ < div className = "flex min-h-full justify-center" >
80
+ < RangeForm />
81
+ </ div >
82
+ < div > </ div >
83
+ </ div >
84
+ ) ;
85
+ }
86
+
54
87
return (
55
88
< div >
56
89
< div className = "flex min-h-full justify-center" >
57
- < div > test butts</ div >
58
- < form method = "GET" >
59
- < Label >
60
- Start date
61
- < input name = "start" type = "date" />
62
- </ Label >
63
- < Label >
64
- End date
65
- < input name = "end" type = "date" />
66
- </ Label >
67
- < input type = "submit" value = "Submit" />
68
- </ form >
90
+ < RangeForm />
69
91
</ div >
70
92
< div >
71
93
< textarea
@@ -77,27 +99,27 @@ ${data
77
99
)
78
100
. join ( "\n" ) } `}
79
101
> </ textarea >
80
- < table >
102
+ < table className = "mt-24" >
81
103
< thead >
82
104
< tr >
83
- < th > Author ID</ th >
84
- < th > Percent Zero Days</ th >
85
- < th > Word Count</ th >
86
- < th > Message Count</ th >
87
- < th > Channel Count</ th >
88
- < th > Category Count</ th >
89
- < th > Reaction Count</ th >
90
- < th > Word Score</ th >
91
- < th > Message Score</ th >
92
- < th > Channel Score</ th >
93
- < th > Consistency Score</ th >
105
+ < DataHeading > Author ID</ DataHeading >
106
+ < DataHeading > Percent Zero Days</ DataHeading >
107
+ < DataHeading > Word Count</ DataHeading >
108
+ < DataHeading > Message Count</ DataHeading >
109
+ < DataHeading > Channel Count</ DataHeading >
110
+ < DataHeading > Category Count</ DataHeading >
111
+ < DataHeading > Reaction Count</ DataHeading >
112
+ < DataHeading > Word Score</ DataHeading >
113
+ < DataHeading > Message Score</ DataHeading >
114
+ < DataHeading > Channel Score</ DataHeading >
115
+ < DataHeading > Consistency Score</ DataHeading >
94
116
</ tr >
95
117
</ thead >
96
118
< tbody >
97
119
{ data . map ( ( d ) => (
98
120
< tr key = { d . data . member . author_id } >
99
121
< td > { d . data . member . author_id } </ td >
100
- < td > { formatter . format ( d . metadata . percentZeroDays ) } </ td >
122
+ < td > { percent ( d . metadata . percentZeroDays ) } </ td >
101
123
< td > { d . data . member . total_word_count } </ td >
102
124
< td > { d . data . member . message_count } </ td >
103
125
< td > { d . data . member . channel_count } </ td >
0 commit comments