Skip to content

Commit

Permalink
feat: show avalibilty no overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Koon committed Feb 2, 2025
1 parent 383a26c commit fd3ea62
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/expo/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
},
assetBundlePatterns: ["**/*"],
ios: {
buildNumber: "4",
buildNumber: "5",
bundleIdentifier: "com.koonindustries.trinity" + ifDev(".dev"),
supportsTablet: true,
infoPlist: {
Expand Down
5 changes: 4 additions & 1 deletion apps/expo/src/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { Button, SafeAreaView, Text } from "react-native";
import { Slot } from "expo-router";

import { api } from "~/utils/api";
import { signIn, useUser } from "~/utils/auth";
import { useSignIn } from "~/utils/auth";
// import { signIn, useUser } from "~/utils/auth";
import { getToken } from "~/utils/session-store";

export default function Layout() {
const signIn = useSignIn();

const { data, isLoading } = api.auth.getSession.useQuery();
if (isLoading)
return (
Expand Down
28 changes: 22 additions & 6 deletions apps/expo/src/app/(app)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ import BottomSheet, { BottomSheetView } from "@gorhom/bottom-sheet";
import { useColorScheme } from "nativewind";

import { api, RouterOutputs } from "~/utils/api";
import { useSignOut } from "~/utils/auth";

const { width, height: HEIGHT } = Dimensions.get("window");
const height = HEIGHT - 300;

type Cal = RouterOutputs["service"]["getEvents"][number];

type FreeTime = { start: Date; end: Date };
type CalMarking = {
marking: "free" | { name: string };
start: Date;
end: Date;
};

const Page =
(
Expand All @@ -45,14 +50,14 @@ const Page =
)
.filter((e) => e.start.toDateString() == day.toDateString()) || [];

function dayFreeTime(date: Date): FreeTime[] {
function dayFreeTime(date: Date): CalMarking[] {
if (data.length == 0) return [];
if (friendEvents.length == 0) return [];

const freeTimes: FreeTime[] = [];
const freeTimes: CalMarking[] = [];

const allEvents = [
...data.flatMap((cal) => cal.events),
// ...data.flatMap((cal) => cal.events),
...friendEvents.flatMap((cal) => cal.events),
]
.sort((a, b) => a.start.getTime() - b.start.getTime())
Expand All @@ -61,6 +66,7 @@ const Page =
if (allEvents.length === 0) {
return [
{
marking: "free",
start: new Date(date.setHours(0, 0, 0, 0)),
end: new Date(date.setHours(23, 59, 59, 999)),
},
Expand All @@ -73,6 +79,7 @@ const Page =
for (const event of allEvents) {
if (currentTime < event.start) {
freeTimes.push({
marking: "free",
start: new Date(currentTime),
end: new Date(event.start),
});
Expand All @@ -84,6 +91,7 @@ const Page =
const endOfDay = new Date(date.setHours(23, 59, 59, 999));
if (currentTime < endOfDay) {
freeTimes.push({
marking: "free",
start: new Date(currentTime),
end: endOfDay,
});
Expand All @@ -110,7 +118,7 @@ const Page =
((event.start.getHours() * 60 + event.start.getMinutes()) /
(60 * 24)),
borderLeftColor: event.calendar.color,
width: width - 50,
width: width - 70,
}}
className="absolute ml-12 border-l bg-zinc-800 px-2 pt-2"
>
Expand All @@ -131,8 +139,9 @@ const Page =
height *
((event.start.getHours() * 60 + event.start.getMinutes()) /
(60 * 24)),
right: 0,
}}
className="absolute ml-12 w-1 rounded-full border-l bg-green-400 px-2 pt-2"
className="absolute ml-12 w-1 border-l bg-green-400 px-2 pt-2"
></View>
))}
</View>
Expand Down Expand Up @@ -190,6 +199,7 @@ export default function App() {
const { data: friends } = api.friends.list.useQuery();

const { colorScheme } = useColorScheme();
const signOut = useSignOut();

return (
<View className="flex-1">
Expand Down Expand Up @@ -232,6 +242,12 @@ export default function App() {
))}
</Text>
</View>
<Button
onPress={() => {
signOut();
}}
title="Logout"
/>
</BottomSheetView>
</BottomSheet>
</View>
Expand Down
4 changes: 2 additions & 2 deletions apps/expo/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useSignIn = () => {
if (!success) return;

await utils.invalidate();
router.replace("/");
// router.replace("/");
};
};

Expand All @@ -52,6 +52,6 @@ export const useSignOut = () => {
if (!res.success) return;
await deleteToken();
await utils.invalidate();
router.replace("/");
// router.replace("/");
};
};
2 changes: 1 addition & 1 deletion packages/auth/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const authConfig = {
}
: {}),
secret: env.AUTH_SECRET,
providers: [Google, Apple],
providers: [Apple, Google],
callbacks: {
session: (opts) => {
if (!("user" in opts))
Expand Down

0 comments on commit fd3ea62

Please sign in to comment.