11import { Box , Text } from "ink"
2- import { useEffect , useState } from "react"
2+ import { useState } from "react"
33import { Select } from "./components/select"
44import { EmailInput , Spinner } from '@inkjs/ui' ;
55
66import { registerAction , type Event } from "../actions/register.action"
77import Link from "ink-link" ;
8+ import { useQuery , useZero } from "@rocicorp/zero/react" ;
9+ import { schema } from "@lib/zero-sync/schema" ;
810
911type RegisterJourneyProps = {
1012 unmount : ( ) => void
@@ -13,31 +15,13 @@ type RegisterJourneyProps = {
1315const toDate = ( date : string ) => `${ new Date ( date ) . toLocaleDateString ( ) } ${ new Date ( date ) . toLocaleTimeString ( ) } `
1416
1517export const RegisterJourney = ( { unmount } : RegisterJourneyProps ) => {
16- const [ events , setEvents ] = useState < {
17- id : string ,
18- slug : string ,
19- name : string ,
20- startDate : string ,
21- location : string
22- } [ ] > ( [ ] )
23-
18+ const z = useZero < typeof schema > ( ) ;
19+
20+ //where('startDate', '>', now.toUTCString())
21+ const eventQuery = z . query . events . orderBy ( 'startDate' , 'desc' ) . limit ( 10 ) ;
22+ const [ events ] = useQuery ( eventQuery ) ;
2423 const [ event , setEvent ] = useState < Event | null > ( null )
2524 const [ hasSucceeded , setHasSucceeded ] = useState ( false )
26-
27- useEffect ( ( ) => {
28- const fetchEvents = async ( ) => {
29- try {
30- const response = await fetch ( 'https://allthingsweb.dev/api/events' )
31- const { data } = await response . json ( )
32- setEvents ( data )
33- } catch ( error ) {
34- console . error ( error )
35- }
36-
37- }
38- fetchEvents ( )
39- } , [ ] )
40-
4125 return < Box flexDirection = "column" padding = { 1 } gap = { 1 } >
4226
4327 { ! event && < Text > Here is the list of the upcomping events:</ Text > }
@@ -49,7 +33,7 @@ export const RegisterJourney = ({ unmount }: RegisterJourneyProps) => {
4933 render : ( label , value , isSelected ) => < Box >
5034 < Box flexDirection = "column" >
5135 < Text bold = { isSelected } dimColor = { ! isSelected } > { label } </ Text >
52- < Text dimColor = { ! isSelected } > { toDate ( event . startDate ) } - { value . location } </ Text >
36+ < Text dimColor = { ! isSelected } > { toDate ( event . startDate ) } - { value . shortLocation } </ Text >
5337 < Link url = { link } >
5438 < Text color = { '#FF9900' } dimColor = { ! isSelected } > { link } </ Text >
5539 </ Link >
@@ -63,7 +47,7 @@ export const RegisterJourney = ({ unmount }: RegisterJourneyProps) => {
6347 { event && < Box flexDirection = "column" padding = { 1 } gap = { 1 } borderStyle = { "round" } >
6448 < Box flexDirection = "column" >
6549 < Text bold > { event . name } </ Text >
66- < Text > { toDate ( event . startDate ) } - { event . location } </ Text >
50+ < Text > { toDate ( event . startDate ) } - { event . shortLocation } </ Text >
6751 < Link url = { `https://allthingsweb.dev/${ event . slug } ` } >
6852 < Text color = { '#FF9900' } > { `https://allthingsweb.dev/${ event . slug } ` } </ Text >
6953 </ Link >
0 commit comments