Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassimoen committed Dec 3, 2023
1 parent 775d8ab commit 4f05f09
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/components/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const Player = (props: PlayerProps) => {

{
showPlayerName && // badgeBgColor of playerPositionColor // span: color: pointsColor
<Badge color={badgeColor} bgColor={motm ? "#c4a747" : theme.primaryContrast}>
<Badge color={badgeColor} bgColor={motm ? "#c4a747" : badgeBgColor}>
<span style={{ color: "white" }}>{playerName}</span>
</Badge>
}
Expand All @@ -217,16 +217,16 @@ export const Player = (props: PlayerProps) => {

{
opponentInfo ?
<OpponentBadge color={"#000"} bgColor={"#fff"}>
<p style={{ fontSize: "10px" }}>
<OpponentBadge color={pointsColor} bgColor={pointsBgColor}>
<p>
{`${opponentInfo.opponentShort} (${opponentInfo.playing})`}
</p>
</OpponentBadge> : null
}
{
(
player && showPlayerValue &&
<Value benchPlayer={benchPlayer}>
<Value benchPlayer={benchPlayer} color={badgeColor}>
<span>{(player.value) ? `€${player.value}M` : null}</span>
</Value>
) || null
Expand Down
4 changes: 2 additions & 2 deletions src/components/Player/PlayerStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const OpponentBadge = styled.div`
width: 100%;
height: 20px;
background: ${theme.primaryContrast};
background: ${(props: any) => props.bgColor};
color: white;
padding: 3px;
overflow: hidden;
Expand Down Expand Up @@ -114,7 +114,7 @@ export const Value = styled.div`
justify-content: center;
align-items: center;
background: #00FAFA;
color: #16002b;
color: ${(props: any) => props.color};
h4 {
font-family: Aeonik,"Helvetica Neue",Helvetica,Arial,sans-serif;
Expand Down
2 changes: 0 additions & 2 deletions src/components/PlayerStatsList/PlayerStatsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export const PlayerStatsList = (props: PlayerStatsListProps) => {
title: t("stats.allPlayersTable.playerColumn"),
sorter: (a: any, b: any) => a.generalInfo.short.localeCompare(b.generalInfo.short),
dataIndex: "generalInfo",
fixed: "left",
render: (text: string, record: any) => {
return (<span>{record.generalInfo.short || record.generalInfo.name}</span>);
},
Expand Down Expand Up @@ -268,7 +267,6 @@ export const PlayerStatsList = (props: PlayerStatsListProps) => {

return (
<ContainerStyle>
{stats?.filter(playerStat => playerFilter(playerStat)).length}
{
<Input
prefix={<SearchOutlined />}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Substitutes/Substitutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Substitutes = (props: SubstitutesProps) => {
pointsColor={props.playerPointsColor}
pointsBgColor={props.playerPointsBgColor}
badgeColor={props.playerBadgeColor}
badgeBgColor={player.playerBadgeBgColor}
badgeBgColor={props.playerBadgeBgColor}
player={player}
club={club}
type={props.playerType}
Expand Down
15 changes: 14 additions & 1 deletion src/components/Team/TeamStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ export const TeamStyle = styled.div`
height: ${(props: TeamProps) => (props.heightRatio / props.widthRatio) * 630}px;
background-size: 100% 100%;
}
` as any;
` as any;

export const SaveLineupButton = styled.div`
text-align: center;
margin: 10px 0px;
@media ${mediaQueries.tabletL} {
text-align: right;
}
.ant-btn {
width: 100%;
}
`;
223 changes: 223 additions & 0 deletions src/pages/EditTeam/EditTeam.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import { AbstractTeam } from "@/components/AbstractTeam/AbstractTeam";
import { NewTeamStyle } from "../NewTeam/NewTeamStyle";
import { useAppSelector } from "@/reducers";
import { useEffect, useMemo } from "react";
import { Navigate, useParams } from "react-router-dom";
import { useGetTeamQuery } from "@/services/teamsApi";
import { startingListToPositionsList } from "@/lib/helpers";
import { pick } from "lodash";
import { useSelector } from "react-redux";
import { useGetDeadlineInfoQuery } from "@/services/weeksApi";
import { Col, Row } from "@/components/UI/Grid/Grid";
import Title from "antd/lib/typography/Title";
import { useTranslation } from "react-i18next";
import { Block } from "@/components/Block/Block";
import { NewGameStats } from "@/components/Stats/NewGameStats";
import { Team } from "@/components/Team/Team";

import teamBackground from "./../../assets/img/fpl-pitch-no-boarding.svg";
import { PlayerType } from "@/types/PlayerTypes";
import { theme } from "@/styles/theme";
import { Element, scroller } from "react-scroll";
import { useGetClubsQuery } from "@/services/clubsApi";
import { SaveOutlined } from "@ant-design/icons";
import { PlayerList } from "@/components/PlayerList/PlayerList";
import { useGetMatchesQuery } from "@/services/matchesApi";
import { useGetPlayersQuery } from "@/services/playersApi";
import { Button } from "@/components/UI/Button/Button";

const _EditTeam = (props: AbstractTeamType) => {
const { user, teams } = useAppSelector((state) => state.userState);
const application = useSelector((state: StoreState) => state.application);
const [t] = useTranslation();
const { id } = useParams();
const { data: teamResult, isSuccess: teamSucces } = useGetTeamQuery(+id || 0);
const { data: deadlineInfo, isSuccess: deadlineInfoSuccess, isLoading: deadlineInfoLoading, isError: deadlineInfoError } = useGetDeadlineInfoQuery();
const { data: matches, isSuccess: matchesSuccess, isLoading: matchesLoading } = useGetMatchesQuery();
const { data: clubs, isSuccess: clubsSuccess, isLoading: clubsLoading } = useGetClubsQuery();
const { data: players, isSuccess: playersSuccess, isLoading: playersLoading } = useGetPlayersQuery();

const getTeamInfo = () => {
if (!teamSucces) {
return;
}
const playerProps =
["id", "name", "short", "positionId", "clubId", "value", "ban", "injury", "form", "forename", "surname", "portraitUrl"];
const selectionProps: any[] = [];
const result = teamResult;
const starting = result.players
.filter((player: any) => player.selection.starting === 1)
.map((player: any) => Object.assign({ inStarting: true }, pick(player, playerProps), pick(player.selection, selectionProps)));
const bench = result.players
.filter((player: any) => player.selection.starting === 0)
.map((player: any) => Object.assign({ inStarting: false }, pick(player, playerProps), pick(player.selection, selectionProps)));
const teamName = result.team.name;
let captainId = null;
let viceCaptainId = null;

captainId = result.players.find((player: any) => player.selection.captain === 1)?.id;
viceCaptainId = result.players.find((player: any) => player.selection.captain === 2)?.id;

const budget = result.team.budget !== null
? result.team.budget
: result.players.reduce((acc: any, player: any) => acc - player.value, application.competition.budget);

const boosters = {
freeHit: result.team.freeHit,
bank: result.team.bank,
tripleCaptain: result.team.tripleCaptain,
wildCard: result.team.wildCard,
};

// const deadlineWeek = (deadlineInfo && deadlineInfo.deadlineInfo && deadlineInfo.deadlineInfo.deadlineWeek) || 0;
// if((boosters.freeHit === deadlineWeek)) {

// }

props.initTeamState(starting, bench, teamName, captainId, budget, undefined, undefined, undefined, [], [], [], viceCaptainId, boosters);
};

const updateTeam = (teamId: number) => {
props.onTeamEdit(teamId);
};

useEffect(() => {
if (deadlineInfoSuccess && teamSucces && clubsSuccess) {
getTeamInfo();
}
}, [clubsSuccess, teamSucces, deadlineInfoSuccess]);

const onPlaceHolderClick = (player: any) => {
if (player && player.positionId || player && player.positionId === 0) {
props.setActivePositionFilter(player.positionId);
}

scroller.scrollTo("all-players", {
duration: 1000,
delay: 100,
smooth: true,
offset: 50,
});
};

const {
starting,
bench,
boosters,
initializedExternally,
budget,
captainId,
viceCaptainId,
activePositionFilter,
} = props;

const totalPlayersToPick = application.competition.lineupSize + application.competition.benchSize;
const startingPicked = starting.filter(player => !!player);
const benchPicked = bench.filter(player => !!player);
const totalPlayersPicked = startingPicked.length + benchPicked.length;

const team = useMemo(() => teamResult && teamResult.team, [teamResult, id]);
const notTeamOwner = useMemo(() => team && team.userId && user.id !== team.userId, [team, user]);
const firstPlayingWeekPassed = useMemo(
() => team && team.id && deadlineInfo && deadlineInfo.deadlineInfo && deadlineInfo.deadlineInfo.deadlineWeek
&& deadlineInfo.deadlineInfo.deadlineWeek > team.weekId,
[team, deadlineInfo]);
const gameOfficialyStarted = useMemo(
() => team && team.id && deadlineInfo && deadlineInfo.deadlineInfo && deadlineInfo.deadlineInfo.deadlineWeek
&& deadlineInfo.deadlineInfo.deadlineWeek > application.competition.officialStartWeek,
[team, deadlineInfo]);
const deadlineWeek = useMemo(() => deadlineInfo && deadlineInfo.deadlineInfo && deadlineInfo.deadlineInfo.deadlineWeek, [deadlineInfo]);
const wildCardOrFreeHitEnabled = useMemo(() => boosters.wildCard === deadlineWeek || boosters.freeHit === deadlineWeek, [deadlineInfo]);
const startingByPositions = startingListToPositionsList([].concat(starting as any, bench as any), [2, 5, 5, 3]);

return (
<NewTeamStyle>
{
notTeamOwner && <Navigate to={{ pathname: "/home" }} />
}
{
team && starting && starting.length === 0 && <Navigate to={{ pathname: "/new" }} />
}
{
deadlineWeek && team && (firstPlayingWeekPassed && gameOfficialyStarted && !wildCardOrFreeHitEnabled)
&& <Navigate to={{ pathname: `/transfers/${team.id}` }} />
}
{
team && initializedExternally && players && clubs &&
<Row>
<Col md={12} sm={12} xs={24} className="left">
<Title level={2}>{t("general.footballLineup")}</Title>
<Block>
<NewGameStats
budget={budget}
totalPlayers={totalPlayersToPick}
selectedPlayers={totalPlayersPicked}
/>
<Team
widthRatio={15}
heightRatio={10}
bg={teamBackground}
selection={startingByPositions}
assetsCdn={application.competition.assetsCdn}
playerType={PlayerType.SoccerPortrait}
captainId={captainId}
viceCaptainId={viceCaptainId}
showCaptainBadge={true}
playerBadgeColor={"#fff"}
playerBadgeBgColor={theme.primaryContrast}
playerPointsColor={"#000"}
playerPointsBgColor={theme.primaryColor}
showPlayerValueInsteadOfPoints={true}
showPlayerValue={true}
onCaptainSelect={props.onCaptainSelect}
modalEnabled={true}
onRemove={(player: Player) => props.removePlayer(player)}
onPlaceholderClick={onPlaceHolderClick}
clubs={clubs}
/>
{
(team && <Button
onClick={(e: any) => updateTeam}
style={{ width: "100%", maxWidth: "100%", margin: "10px 0" }}
type="primary"
disabled={false}
loading={false}
size="large">
{/* TODO: get updating state to disable button */}
<SaveOutlined style={{ marginRight: "10px" }} />
{t("team.saveTeam")}
</Button>)
}
</Block>
</Col>
<Col md={12} sm={12} xs={24} className="right">
<Block>
<Title level={2}>{t("general.footballAllPlayers")}</Title>
<Element name="all-player">
<PlayerList
data={players}
clubs={clubs}
isLoading={playersLoading}
playerType={PlayerType.SoccerPortrait}
size={10}
matches={matches}
deadlineWeek={deadlineWeek}
hidePositions={false}
assetsCdn={application.competition.assetsCdn}
activePositionFilter={activePositionFilter}
isPickable={props.isPickAble}
onPick={props.pickPlayer}
action
showHeader={false}
/>
</Element>
</Block>
</Col>
</Row>
}
</NewTeamStyle>
);
};


export const EditTeam = () => AbstractTeam(_EditTeam, {});
14 changes: 7 additions & 7 deletions src/pages/Points/Points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ export const _TeamPoints = (props: AbstractTeamType) => {
replacePlayerPointsWithStatsPoints={true}
showCaptainBadge={true}
modalEnabled={true}
playerBadgeColor="#fff"
playerBadgeBgColor={theme.primaryColor}
playerPointsColor={"#fff"}
playerPointsBgColor="#84FF00"
playerBadgeColor={"#fff"}
playerBadgeBgColor={theme.primaryContrast}
playerPointsColor={"#000"}
playerPointsBgColor={theme.primaryColor}
bg={teamBackground}
playerType={PlayerType.SoccerPortrait} />
<Substitutes
Expand All @@ -248,10 +248,10 @@ export const _TeamPoints = (props: AbstractTeamType) => {
clubs={clubs}
assetsCdn={application.competition.assetsCdn}
playerType={PlayerType.SoccerPortrait}
playerBadgeColor={"#000"}
playerBadgeBgColor={theme.primaryColor}
playerBadgeColor={"#fff"}
playerBadgeBgColor={theme.primaryContrast}
playerPointsColor={"#000"}
playerPointsBgColor={"#84FF00"}
playerPointsBgColor={theme.primaryColor}
captainId={captainId}
viceCaptainId={viceCaptainId}
showCaptainBadge={true}
Expand Down
14 changes: 7 additions & 7 deletions src/pages/Team/Team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ export const _Team = (props: AbstractTeamType) => {
isSwapAble={props.isSwapAble}
swapPlayerId={props.swapPlayerId}
swappedFrom={props.swappedFrom}
playerBadgeColor={theme.primaryColor}
playerBadgeColor={"#fff"}
playerBadgeBgColor={theme.primaryContrast}
playerPointsColor={"#000"}
playerPointsBgColor={theme.primaryColor}
playerPointsColor="#000"
playerBadgeBgColor="#84FF00"
/>
<Substitutes
selection={props.bench || []}
Expand All @@ -152,10 +152,10 @@ export const _Team = (props: AbstractTeamType) => {
isSwapAble={props.isSwapAble}
swapPlayerId={props.swapPlayerId}
swappedFrom={props.swappedFrom}
playerBadgeColor={theme.primaryColor}
playerBadgeBgColor={theme.primaryColor}
playerPointsColor="#000"
playerPointsBgColor="#84FF00"
playerBadgeColor={"#fff"}
playerBadgeBgColor={theme.primaryContrast}
playerPointsColor={"#000"}
playerPointsBgColor={theme.primaryColor}
/>
<Button
onClick={(e: any) => props.onTeamSelectionsUpdate(teamResult.team.id, props.visibleWeekId)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Transfers/Transfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const _Transfers = (props: AbstractTeamType) => {
const budget = teamResult.team.budget !== null ?
teamResult.team.budget : getPlayersValueWithTransfers(teamResult.players);


const boosters = {
freeHit: teamResult.team.freeHit,
bank: teamResult.team.bank,
Expand Down Expand Up @@ -224,6 +223,7 @@ const _Transfers = (props: AbstractTeamType) => {
return (
(clubs && teamResult && matches && players && deadlineInfo) && (
<React.Fragment>
{application.competition.officialStartWeek}
{(notTeamOwner || state.notFound) &&
<Navigate to={"/home"} />
}
Expand Down
Loading

0 comments on commit 4f05f09

Please sign in to comment.