Skip to content

Commit

Permalink
holy shit fantasy picking works
Browse files Browse the repository at this point in the history
Signed-off-by: anderssonw <wandersson.98@gmail.com>
  • Loading branch information
anderssonw committed Aug 22, 2023
1 parent d92e85c commit a0ba211
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
25 changes: 11 additions & 14 deletions src/lib/components/fantasy/CardSmall.svelte
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
<script lang="ts">
import { goto } from '$app/navigation';
import type { FantasyForm, FullPlayer } from '$lib/types/newTypes';
import CardSmallInfo from './CardSmallInfo.svelte';
export let player: FullPlayer;
export let fantasyForm: FantasyForm;
export let position: number;
let card_type: string = 'bronze';
function handleCardClick() {
fantasyForm.selectedCardPosition = position;
}
function handleCaptainClick(pid: number) {
fantasyForm.captainId = pid;
function handleCaptainClick(playerId: number) {
fantasyForm.captainId = playerId;
}
function sellPlayer(player: number) {
function sellPlayer() {
fantasyForm.players[position] = null;
//fantasyForm.cash += player.price;
if (fantasyForm.captainId == player.id) {
fantasyForm.captainId = -1;
}
}
$: isCaptain = fantasyForm.captainId == player.id;
</script>

<div class="small-card group">
<CardSmallInfo {player} />
<CardSmallInfo {isCaptain} {player} />

<div class="w-40 absolute left-[100%] hidden group-hover:block group-hover:animate-fadeIn z-100">
<button class="btn w-full mb-1" on:click={() => sellPlayer(player.id)}>Selg spiller</button>
<button class="btn w-full mb-1" on:click={() => handleCaptainClick(player.id || 0)}>Velg kaptein</button>
<button class="btn w-full mb-1" on:click={() => sellPlayer()}>Selg spiller</button>
<button class="btn w-full mb-1" on:click={() => handleCaptainClick(player.id)}>Velg kaptein</button>
<a href="/players/{player.id}" target="_blank" rel="noreferrer" class="p-0">
<button class="btn w-full mb-1">Statistikk</button>
</a>
Expand Down
8 changes: 8 additions & 0 deletions src/lib/components/fantasy/CardSmallInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { afterUpdate } from 'svelte';
export let player: FullPlayer;
export let isCaptain: boolean;
let cardType: string = 'bronze';
Expand All @@ -22,13 +23,20 @@
{#if player}
<img src="/cards/{cardType}.png" alt="card" />

{#if isCaptain}
<div class="w-full absolute top-[6%] left-[25%]">
<p class="text-center text-red-700 text-xl">(C)</p>
</div>
{/if}

<div class="w-16 absolute top-[19%] right-[10%]">
<img src="/profile/placeholder.png" alt="head" />
<div class="absolute top-[86%] bg-gradient-to-t from-slate-950/25 to-transparent w-[100%] h-2" />
</div>
<div class="w-full absolute top-[5%] right-[25%]">
<p class="text-center text-primary-color text-3xl">50</p>
</div>

<div class="w-full absolute top-[51%]">
<p class="text-center text-primary-color text-xl">{player.name.split(' ')[1]}</p>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/lib/components/fantasy/SelectCardModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
export let players: FullPlayer[];
export let fantasyForm: FantasyForm;
$: hasCardSelected = fantasyForm.selectedCardPosition > 0 ? true : false;
const calculatePlayersToShow = (allPlayers: FullPlayer[], playersInForm: (FullPlayer | null)[]) => {
let playersInFormIds = playersInForm.map((player) => player?.id || -1);
return allPlayers.filter((player) => {
return !playersInFormIds.includes(player.id);
});
};
$: playersNotInForm = calculatePlayersToShow(players, fantasyForm.players);
$: hasCardSelected = fantasyForm.selectedCardPosition >= 0 ? true : false;
// Apply animation
$: selectionVisible = `transition-all duration-300 ${hasCardSelected ? 'block opacity-100' : 'invisible opacity-0'}`;
Expand All @@ -26,7 +35,7 @@
</div>
<div class="max-w-screen-laptop h-3/4 p-8 rounded-lg fixed m-auto inset-x-0 inset-y-0 overflow-y-scroll">
<div class="w-full flex flex-row flex-wrap gap-8 justify-center {playerSlide}">
{#each players as player}
{#each playersNotInForm as player}
<SelectCard {player} bind:fantasyForm />
{/each}
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/routes/fantasy/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
teamName: fantasyTeam?.name || 'placeholder'
} satisfies FantasyForm;
$: currentCash = calculateCurrentCash();
$: currentCash = calculateCurrentCash(fantasyForm.players);
const fillFantasyFormPlayers = (currentPlayers: FullPlayer[] | undefined): (FullPlayer | null)[] => {
const maxPlayerCount = 4;
Expand All @@ -51,11 +51,11 @@
return formPlayers;
};
const calculateCurrentCash = () => {
const calculateCurrentCash = (players: (FullPlayer | null)[]) => {
if (season) {
return (
season?.starting_currency -
fantasyForm.players.reduce((accumulator, player) => {
players.reduce((accumulator, player) => {
if (!player) return accumulator;
return accumulator + player?.price;
Expand All @@ -68,7 +68,7 @@
</script>

{#if session && allPlayers && season}
<SelectCardModal {fantasyForm} players={allPlayers} />
<SelectCardModal bind:fantasyForm players={allPlayers} />

<div class="structure">
{#if season}
Expand All @@ -86,7 +86,7 @@
<img src="/cards/empty.png" alt="card" />
</div>
{:else}
<CardSmall {fantasyForm} {player} position={id} />
<CardSmall bind:fantasyForm {player} position={id} />
{/if}
</div>
{/each}
Expand Down

0 comments on commit a0ba211

Please sign in to comment.