Skip to content

Commit

Permalink
exhibition, bugfix, style, stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mariansam committed Jun 15, 2023
1 parent 03a17c5 commit fae470c
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 28 deletions.
32 changes: 23 additions & 9 deletions scripts/resetdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,33 @@ assert(POCKETBASE_ENDPOINT, 'missing env var POCKETBASE_ENDPOINT');
assert(POCKETBASE_ADMIN_EMAIL, 'missing env var POCKETBASE_ADMIN_EMAIL');
assert(POCKETBASE_ADMIN_PASSWORD, 'missing env var POCKETBASE_ADMIN_PASSWORD');

const TEACHERS_TEAM_ID = 'pg7a6r910fvfhlq';

const pb = new PocketBase(POCKETBASE_ENDPOINT);
await pb.admins.authWithPassword(POCKETBASE_ADMIN_EMAIL, POCKETBASE_ADMIN_PASSWORD);

const gamesColl = pb.collection('games');
const games = await gamesColl.getFullList<Game>();

for (const game of games) {
console.log('clearing game', game.id);
await gamesColl.update(game.id!, {
finished: false,
goals1: 0,
goals2: 0,
goals: [],
});
if (game.team1 == TEACHERS_TEAM_ID || game.team2 === TEACHERS_TEAM_ID) {
console.log('clearing teachers game', game.id);
await gamesColl.update(game.id!, {
finished: false,
team2: null,
goals1: 0,
goals2: 0,
goals: [],
});
} else {
console.log('clearing game', game.id);
await gamesColl.update(game.id!, {
finished: false,
goals1: 0,
goals2: 0,
goals: [],
});
}
}
console.log('======== GAMES CLEARED ========');
console.log();
Expand All @@ -48,6 +61,7 @@ await miscColl.update(gameState.id!, {
matchStarted: false,
gameDuration: 6.5,
currentGameStart: null,
revealTeachers: false,
});
console.log('======== GAME STATE RESET ========');
console.log();
Expand All @@ -58,7 +72,7 @@ const playersColl = pb.collection('players');
const players = await playersColl.getFullList<Player>();

for (const player of players) {
console.log('clearing player', player.id);
console.log('clearing player', player.id, player.name);
await playersColl.update(player.id!, {
goals: [],
});
Expand All @@ -72,7 +86,7 @@ const teamsColl = pb.collection('teams');
const teams = await teamsColl.getFullList<Team>();

for (const team of teams) {
console.log('clearing team', team.id);
console.log('clearing team', team.id, team.name);
await teamsColl.update(team.id!, {
points: 0,
});
Expand Down
2 changes: 2 additions & 0 deletions src/admin-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export const useAdminLogic = () => {
gameMiscActions.update(gameState.id as ReferenceTo<GameState>, {
matchStarted: true,
currentGameNo: 0,
currentGameStart: new Date(),
});
};

const startMatchFromNo = (no: number) => {
gameMiscActions.update(gameState.id as ReferenceTo<GameState>, {
matchStarted: true,
currentGameNo: no,
currentGameStart: new Date(),
});
};

Expand Down
14 changes: 10 additions & 4 deletions src/components/admin/goal-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const AdminGoalInput: React.FC<AdminGoalInputProps> = props => {
} = props;

const [minute, setMinute] = useState(1);
const [player, setPlayer] = useState<Player>();
const [playerId, setPlayerId] = useState<ReferenceTo<Player>>();

const {
players,
Expand All @@ -36,11 +36,17 @@ export const AdminGoalInput: React.FC<AdminGoalInputProps> = props => {
}, [players, team]);

const addGoal = async () => {
if (!player) {
if (!playerId) {
console.error('you stupid');
return;
}

const player = members.find(m => m.id === playerId);
if (!player) {
console.error('no player by id', playerId, members);
return;
}

console.log({game, team, player, minute, side});
await newGoal(game, team, player, minute, side);
};
Expand All @@ -57,8 +63,8 @@ export const AdminGoalInput: React.FC<AdminGoalInputProps> = props => {
<Button
key={mem.id}
className='m-0 p-1'
onClick={() => setPlayer(mem)}
variant={mem.id === player?.id ? 'primary' : 'secondary'}
onClick={() => setPlayerId(mem.id)}
variant={mem.id === playerId ? 'primary' : 'secondary'}
>
{mem.name}
</Button>
Expand Down
55 changes: 44 additions & 11 deletions src/components/future-matches.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import Card from 'react-bootstrap/Card';
import { useGameLogic } from '../logic';
import type {Game, Team} from '../types';
import type { Game } from '../types';

type FutureMatchesProps = {
limit?: number,
Expand All @@ -19,26 +19,36 @@ export const FutureMatches: React.FC<FutureMatchesProps> = props => {

const upcomingGames = useMemo(() => {
// we want to show the first game when match not started

let gamesToShow: Game[] = [];

if (!gameState.revealTeachers) {
gamesToShow = games.slice(0, -1);
} else {
gamesToShow = games;
}

const offset = gameState.matchStarted ? 0 : 1;

if (limit) {
const upGames = games.filter(g => g.no+offset > gameState.currentGameNo).slice(0, limit);
return upGames;
return gamesToShow.filter(g => g.no+offset > gameState.currentGameNo).slice(0, limit);
} else {
const upGames = games.filter(g => g.no+offset > gameState.currentGameNo);
return upGames;
return gamesToShow.filter(g => g.no+offset > gameState.currentGameNo);
}
}, [games, gameState, limit]);

return (
<Card className='text-center mb-4'>
<Card.Header>Nadcházející zápasy</Card.Header>
<Card.Body>
{upcomingGames.map((game, index) => (
<Card.Body className='py-1'>
{upcomingGames.length ? upcomingGames.map((game, index) => (
<>
<FutureMatch game={game} />
{index !== upcomingGames.length - 1 && <hr/>}
{index !== upcomingGames.length - 1 && <hr className='my-0' />}
</>
))}
)) : (
<p className='mt-3 fs-5'>vyhlášení :)</p>
)}
</Card.Body>
</Card>
);
Expand Down Expand Up @@ -71,10 +81,33 @@ const FutureMatch: React.FC<FutureMatchProps> = props => {
return formatted;
}, [game, gameState, nextGameStart]);


// if (!team1 || !team2)
// return null;
// return (<p>loading</p>);

if (gameState.revealTeachers && (team1?.teachers || team2?.teachers)) {
if (!team1)
return null;

if (!team2) {
return (
<Card.Text className='bg-warning bg-opacity-25 py-3 mb-3 rounded-bottom'>
<strong>{team1.name}</strong> - <strong>vítězové</strong> asi v {gameStartFormatted}
</Card.Text>
)
}
return (
<Card.Text className='bg-warning bg-opacity-25 py-3 mb-3 rounded-bottom'>
<strong>{team1.name}</strong> - <strong>{team2.name}</strong> asi v {gameStartFormatted}
</Card.Text>
);
}

if (!team1 || !team2)
return (<p>loading</p>);
return null;

return (
<Card.Text><strong>{team1.name}</strong> - <strong>{team2.name}</strong> asi v {gameStartFormatted}</Card.Text>
<Card.Text className='my-3'><strong>{team1.name}</strong> - <strong>{team2.name}</strong> asi v {gameStartFormatted}</Card.Text>
);
};
2 changes: 1 addition & 1 deletion src/pages/admin/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const AdminHomePage: React.FC = () => {
<Table bordered style={{ tableLayout: 'fixed' }}>
<tbody>
{shownGame.goals.map(goalId => (
<GoalRow goalId={goalId} />
<GoalRow goalId={goalId} key={goalId} />
))}
<tr>
<td>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/bufet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const BufetPage: React.FC = () => {
<Card className="m-4">
<Card.Header>Bufet</Card.Header>

<Card.Body>
<Card.Body style={{fontSize: 18}}>
<p className="pb-4">Bufet je otevřený! V nabídce najdete:</p>

<p>Whey protein - 3O</p>
<p>Whey protein - 30</p>
<p>Párek v rohlíku - 20 Kč</p>
<p>Párek na tácku - 10 Kč</p>
<p>Toust - 20 Kč</p>
Expand Down
8 changes: 8 additions & 0 deletions src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ import { BestPlayers } from '../components/best-players';
import { News } from '../components/news';

export const HomePage: React.FC = () => {
const { gameState: { matchStarted } } = useGameLogic();

return (
<div style={PAGE_STYLE}>
{!matchStarted && (
<p className='fs-3'>
Vítejte na třetím ročníku legendárního futsálového turnaje GJP&nbsp;Cup. Udělejte si pohodlí, připravte se na hru a občerstvěte se v bufetu – za chvíli začínáme!
</p>
)}

<CurrentMatch />
<FutureMatches limit={6} />
<BestPlayers />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const TeamsPage: React.FC = () => {
return (<p>loading</p>);

return (
<div style={PAGE_STYLE}>
<div style={{width: '100%', maxWidth: 600}}>
{teamsSorted.map(team => (
<TeamView team={team} key={team.name}/>
))}
Expand Down

0 comments on commit fae470c

Please sign in to comment.