-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Max Koon
committed
Jan 26, 2025
1 parent
d04f680
commit ce69792
Showing
4 changed files
with
3,528 additions
and
3,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,104 @@ | ||
import { Button, Image, Text } from "react-native"; | ||
import { SafeAreaView } from "react-native-safe-area-context"; | ||
import { Stack } from "expo-router"; | ||
import React, { useState } from "react"; | ||
import { | ||
Dimensions, | ||
StyleSheet, | ||
Text, | ||
TouchableOpacity, | ||
View, | ||
} from "react-native"; | ||
import InfinitePager from "react-native-infinite-pager"; | ||
|
||
import { api } from "~/utils/api"; | ||
import { useSignOut, useUser } from "~/utils/auth"; | ||
import { api, RouterOutputs } from "~/utils/api"; | ||
|
||
export default function Index() { | ||
const utils = api.useUtils(); | ||
const signOut = useSignOut(); | ||
const user = useUser(); | ||
const { height: HEIGHT } = Dimensions.get("window"); | ||
const height = HEIGHT - 200; | ||
|
||
type Cal = RouterOutputs["service"]["getEvents"][number]; | ||
|
||
const Page = | ||
(data: RouterOutputs["service"]["getEvents"]) => | ||
({ index }: { index: number }) => { | ||
const day = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * index); | ||
|
||
const events = | ||
data | ||
?.reduce( | ||
(acc, cur) => [ | ||
...acc, | ||
...cur.events.map((e) => ({ ...e, calendar: cur })), | ||
], | ||
[] as (Cal["events"][number] & { | ||
calendar: { name: string; color: string }; | ||
})[], | ||
) | ||
.filter((e) => e.start.toDateString() == day.toDateString()) || []; | ||
|
||
return ( | ||
<View className="flex-1 items-center justify-center"> | ||
<View className="absolute top-0 z-10 w-full flex-1"> | ||
{events.map((event) => ( | ||
<View | ||
key={event.name} | ||
style={{ | ||
height: | ||
(height * (event.end.getTime() - event.start.getTime())) / | ||
(1000 * 60 * 60 * 24), | ||
top: | ||
height * | ||
((event.start.getHours() * 60 + event.start.getMinutes()) / | ||
(60 * 24)), | ||
borderLeftColor: event.calendar.color, | ||
}} | ||
className="absolute w-full border-l bg-zinc-800 px-2 pt-2" | ||
> | ||
<Text className="text-white">{event.name}</Text> | ||
</View> | ||
))} | ||
</View> | ||
|
||
<View className="w-full flex-1"> | ||
{Array.from({ length: 24 }).map((_, i) => ( | ||
<View | ||
key={i} | ||
style={{ height: height / 24 }} | ||
className="w-full border-b border-zinc-800" | ||
></View> | ||
))} | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
const MS_DAY = 1000 * 60 * 60; | ||
|
||
/** | ||
* Return the last Sunday of the given date | ||
* @param from | ||
*/ | ||
function getLastSunday(from: Date): Date { | ||
const day = from.getDay(); | ||
const date = new Date(from.getTime() + -day * MS_DAY); | ||
date.setHours(0, 0, 0, 0); | ||
return date; | ||
} | ||
|
||
export default function App() { | ||
const [index, setIndex] = useState(0); | ||
|
||
const { data } = api.service.getEvents.useQuery({ | ||
start: getLastSunday(new Date()), | ||
}); | ||
|
||
return ( | ||
<SafeAreaView className="bg-background"> | ||
<Stack.Screen options={{ title: "Home Page" }} /> | ||
<Text className="text-white">Create</Text> | ||
<Image | ||
source={{ uri: user?.image! }} | ||
className="h-24 w-24 rounded-full" | ||
<View className="flex-1"> | ||
<InfinitePager | ||
PageComponent={Page(data || [])} | ||
style={{ flex: 1 }} | ||
pageWrapperStyle={{ flex: 1 }} | ||
// onPageChange={(index) => { | ||
// setIndex(index); | ||
// }} | ||
/> | ||
<Button title="Louout" onPress={() => signOut()} /> | ||
</SafeAreaView> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.