play walkout songs
This commit is contained in:
@@ -100,7 +100,7 @@ export function createPlayersService(pb: PocketBase) {
|
||||
expand: "tournament,home,away",
|
||||
});
|
||||
|
||||
return result.map(transformMatch);
|
||||
return result.map((match) => transformMatch(match));
|
||||
},
|
||||
|
||||
async getUnenrolledPlayers(tournamentId: string): Promise<Player[]> {
|
||||
|
||||
@@ -100,7 +100,7 @@ export function createTeamsService(pb: PocketBase) {
|
||||
expand: "tournament,home,away",
|
||||
});
|
||||
|
||||
return result.map(transformMatch);
|
||||
return result.map((match) => transformMatch(match));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ import { PlayerInfo } from "@/features/players/types";
|
||||
|
||||
export function createTournamentsService(pb: PocketBase) {
|
||||
return {
|
||||
async getTournament(id: string): Promise<Tournament> {
|
||||
async getTournament(id: string, isAdmin: boolean = false): Promise<Tournament> {
|
||||
const result = await pb.collection("tournaments").getOne(id, {
|
||||
expand: "teams, teams.players, matches, matches.tournament, matches.home, matches.away, matches.home.players, matches.away.players",
|
||||
});
|
||||
return transformTournament(result);
|
||||
return transformTournament(result, isAdmin);
|
||||
},
|
||||
async getMostRecentTournament(): Promise<Tournament> {
|
||||
const result = await pb
|
||||
|
||||
@@ -27,7 +27,7 @@ export function transformTeamInfo(record: any): TeamInfo {
|
||||
};
|
||||
}
|
||||
|
||||
export const transformMatch = (record: any): Match => {
|
||||
export const transformMatch = (record: any, isAdmin: boolean = false): Match => {
|
||||
return {
|
||||
id: record.id,
|
||||
order: record.order,
|
||||
@@ -47,8 +47,8 @@ export const transformMatch = (record: any): Match => {
|
||||
is_losers_bracket: record.is_losers_bracket,
|
||||
status: record.status || "tbd",
|
||||
tournament: record.expand?.tournament ? transformTournamentInfo(record.expand?.tournament) : record.tournament,
|
||||
home: record.expand?.home ? transformTeamInfo(record.expand.home) : record.home,
|
||||
away: record.expand?.away ? transformTeamInfo(record.expand.away) : record.away,
|
||||
home: record.expand?.home ? (isAdmin ? transformTeam(record.expand.home) : transformTeamInfo(record.expand.home)) : record.home,
|
||||
away: record.expand?.away ? (isAdmin ? transformTeam(record.expand.away) : transformTeamInfo(record.expand.away)) : record.away,
|
||||
created: record.created,
|
||||
updated: record.updated,
|
||||
home_seed: record.home_seed,
|
||||
@@ -135,20 +135,20 @@ export function transformTeam(record: any): Team {
|
||||
};
|
||||
}
|
||||
|
||||
export function transformTournament(record: any): Tournament {
|
||||
export function transformTournament(record: any, isAdmin: boolean = false): Tournament {
|
||||
const teams =
|
||||
record.expand?.teams
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created) < new Date(b.created) ? -1 : 0
|
||||
)
|
||||
?.map(transformTeamInfo) ?? [];
|
||||
?.map(isAdmin ? transformTeam : transformTeamInfo) ?? [];
|
||||
|
||||
const matches =
|
||||
record.expand?.matches
|
||||
?.sort((a: any, b: any) =>
|
||||
a.lid - b.lid ? -1 : 0
|
||||
)
|
||||
?.map(transformMatch) ?? [];
|
||||
?.map((match: any) => transformMatch(match, isAdmin)) ?? [];
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
|
||||
@@ -96,6 +96,17 @@ export class SpotifyWebApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
async playTrack(trackId: string, deviceId?: string, positionMs?: number): Promise<void> {
|
||||
const endpoint = deviceId ? `/me/player/play?device_id=${deviceId}` : '/me/player/play';
|
||||
await this.request(endpoint, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
uris: [`spotify:track:${trackId}`],
|
||||
position_ms: positionMs || 0,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
async pause(): Promise<void> {
|
||||
await this.request('/me/player/pause', {
|
||||
method: 'PUT',
|
||||
|
||||
@@ -22,6 +22,7 @@ export const useSpotifyPlayback = () => {
|
||||
playbackState,
|
||||
currentTrack,
|
||||
play,
|
||||
playTrack,
|
||||
pause,
|
||||
skipNext,
|
||||
skipPrevious,
|
||||
@@ -29,11 +30,12 @@ export const useSpotifyPlayback = () => {
|
||||
refreshPlaybackState,
|
||||
isLoading,
|
||||
} = useSpotify();
|
||||
|
||||
|
||||
return {
|
||||
playbackState,
|
||||
currentTrack,
|
||||
play,
|
||||
playTrack,
|
||||
pause,
|
||||
skipNext,
|
||||
skipPrevious,
|
||||
|
||||
@@ -90,6 +90,7 @@ export interface SpotifyContextType extends SpotifyAuthState {
|
||||
logout: () => void;
|
||||
|
||||
play: (deviceId?: string) => Promise<void>;
|
||||
playTrack: (trackId: string, deviceId?: string, positionMs?: number) => Promise<void>;
|
||||
pause: () => Promise<void>;
|
||||
skipNext: () => Promise<void>;
|
||||
skipPrevious: () => Promise<void>;
|
||||
|
||||
Reference in New Issue
Block a user