From c317d25635e763adf5a826a69b71b7239cb68db1 Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 22 Jun 2024 21:48:57 +0200 Subject: [PATCH] fetch user profiles --- apps/expo/app/fissa/[pin]/index.tsx | 21 ++++++++++ apps/expo/app/fissa/[pin]/members.tsx | 43 ++++++++++++++++++++ apps/expo/src/components/shared/Icon.tsx | 2 +- apps/expo/src/components/shared/ListItem.tsx | 8 ++-- apps/expo/src/utils/Toast.ts | 3 +- packages/api/src/router/fissa.ts | 4 ++ packages/api/src/service/AuthService.ts | 9 +++- packages/api/src/service/FissaService.ts | 15 +++++++ 8 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 apps/expo/app/fissa/[pin]/members.tsx diff --git a/apps/expo/app/fissa/[pin]/index.tsx b/apps/expo/app/fissa/[pin]/index.tsx index 204a55f..d641604 100644 --- a/apps/expo/app/fissa/[pin]/index.tsx +++ b/apps/expo/app/fissa/[pin]/index.tsx @@ -67,6 +67,8 @@ const HeaderRight = () => { + + ); @@ -173,3 +175,22 @@ const SpeakerButton = () => { ); }; + +const FissaMembersButton = () => { + const { pin } = useGlobalSearchParams(); + const { push } = useRouter() + + const { data } = api.fissa.members.useQuery(String(pin), { + enabled: !!pin, + }); + + return ( + + push(`/fissa/${pin}/members`)} /> + + {data?.length} + + + ) +} diff --git a/apps/expo/app/fissa/[pin]/members.tsx b/apps/expo/app/fissa/[pin]/members.tsx new file mode 100644 index 0000000..a09a75a --- /dev/null +++ b/apps/expo/app/fissa/[pin]/members.tsx @@ -0,0 +1,43 @@ +import { AnimationSpeed } from "@fissa/utils"; +import { FlashList } from "@shopify/flash-list"; +import { Stack, useGlobalSearchParams, useRouter } from "expo-router"; +import { View } from "react-native"; +import { IconButton, ListItem, PageTemplate } from "../../../src/components"; +import { api } from "../../../src/utils"; + +const Members = () => { + const { pin } = useGlobalSearchParams(); + const { back } = useRouter(); + + const { data } = api.fissa.members.useQuery(String(pin), { + enabled: !!pin, + }); + + + return ( + + , + }} + /> + + ( + + )} /> + + + ) +} + +export default Members; diff --git a/apps/expo/src/components/shared/Icon.tsx b/apps/expo/src/components/shared/Icon.tsx index bd738b3..7702cc0 100644 --- a/apps/expo/src/components/shared/Icon.tsx +++ b/apps/expo/src/components/shared/Icon.tsx @@ -1,6 +1,6 @@ -import { type FC } from "react"; import { AntDesign, Feather, FontAwesome } from "@expo/vector-icons"; import { type IconProps } from "@expo/vector-icons/build/createIconSet"; +import { type FC } from "react"; export const Icon: FC = ({ name, ...props }) => { if (Object.keys(Feather.glyphMap).includes(name)) diff --git a/apps/expo/src/components/shared/ListItem.tsx b/apps/expo/src/components/shared/ListItem.tsx index 548ded9..959b36f 100644 --- a/apps/expo/src/components/shared/ListItem.tsx +++ b/apps/expo/src/components/shared/ListItem.tsx @@ -1,3 +1,5 @@ +import { theme } from "@fissa/tailwind-config"; +import { cva } from "@fissa/utils"; import { useEffect, useRef, type FC } from "react"; import { Animated, @@ -6,8 +8,6 @@ import { type TouchableWithoutFeedbackProps, type ViewProps, } from "react-native"; -import { theme } from "@fissa/tailwind-config"; -import { cva } from "@fissa/utils"; import { Image } from "./Image"; import { Typography } from "./Typography"; @@ -116,9 +116,9 @@ export const ListItem: FC = ({ export type ListItemProps = Props; interface Props extends TouchableWithoutFeedbackProps, ViewProps { - imageUri?: string; + imageUri?: string | null; title: string; - subtitle: string | boolean; + subtitle: string | number | boolean; subtitlePrefix?: JSX.Element | null; extra?: JSX.Element | null; end?: JSX.Element | null; diff --git a/apps/expo/src/utils/Toast.ts b/apps/expo/src/utils/Toast.ts index a64cddd..6236bee 100644 --- a/apps/expo/src/utils/Toast.ts +++ b/apps/expo/src/utils/Toast.ts @@ -5,8 +5,7 @@ import Toast from "react-native-toast-message"; class NativeToast extends Toaster { protected show({ type = "success", message, duration, icon }: ToasterProps) { const text2 = icon ?? this.defaultIcon(type); - const visibilityTime = duration ?? ToastAndroid.SHORT; - + const visibilityTime = duration ?? 1500; switch (Platform.OS) { case "ios": case "macos": diff --git a/packages/api/src/router/fissa.ts b/packages/api/src/router/fissa.ts index c7529d2..8d0a5a9 100644 --- a/packages/api/src/router/fissa.ts +++ b/packages/api/src/router/fissa.ts @@ -33,6 +33,10 @@ export const fissaRouter = createTRPCRouter({ const service = new FissaService(ctx, new SpotifyService(), new BadgeService(ctx)); return service.byId(input, ctx.session?.user.id); }), + members: publicProcedure.input(Z_PIN).query(({ ctx, input }) => { + const service = new FissaService(ctx, new SpotifyService(), new BadgeService(ctx)); + return service.members(input); + }), pause: protectedProcedure.input(Z_PIN).mutation(({ ctx, input }) => { const service = new FissaService(ctx, new SpotifyService(), new BadgeService(ctx)); return service.pause(input, ctx.session.user.id); diff --git a/packages/api/src/service/AuthService.ts b/packages/api/src/service/AuthService.ts index c2fe8f4..930c60a 100644 --- a/packages/api/src/service/AuthService.ts +++ b/packages/api/src/service/AuthService.ts @@ -70,10 +70,13 @@ export class AuthService extends ServiceWithContext { let session = sessions[0]; + if (session && isPast(session.expires)) { session = await this.db.session.update({ where: { id: session.id }, - data: { expires: addMonths(new Date(), 1) }, + data: { + expires: addMonths(new Date(), 1), + }, }); } @@ -87,6 +90,9 @@ export class AuthService extends ServiceWithContext { data: { access_token: tokens.body.access_token, expires_at: this.expiresAt(tokens.body.expires_in), + user: { + update: { image: spotifyUser.body.images?.[0]?.url }, + } }, }); @@ -143,6 +149,7 @@ export class AuthService extends ServiceWithContext { create: { email: spotifyUser.email, name: spotifyUser.display_name, + image: spotifyUser.images?.[0]?.url, sessions: { create: { expires: addMonths(new Date(), 1), diff --git a/packages/api/src/service/FissaService.ts b/packages/api/src/service/FissaService.ts index 929a617..d081e78 100644 --- a/packages/api/src/service/FissaService.ts +++ b/packages/api/src/service/FissaService.ts @@ -149,6 +149,21 @@ export class FissaService extends ServiceWithContext { await this.stopFissa(pin, fissa.by.accounts[0].access_token); }; + members = async (pin: string) => { + return this.db.userInFissa.findMany({ + where: { pin }, + select: { + points: true, + user: { + select: { + name: true, + image: true + } + } + }, + }); + } + playNextTrack = async (pin: string, forceToPlay = false) => { const fissaDetails = await this.getFissaDetailedInformation(pin); const { by, tracks, currentlyPlaying, expectedEndTime } = fissaDetails;