From 8555efe8bca02e230535693be9ce5e30ccdd9fc6 Mon Sep 17 00:00:00 2001 From: Sendou Date: Mon, 16 Dec 2019 00:46:01 +0200 Subject: [PATCH] cards mobile presentation --- .gitignore | 1 + .../src/components/freeagents/FATableRows.js | 2 +- .../components/freeagents/FreeAgentBrowser.js | 18 +- .../components/freeagents/FreeAgentCards.js | 161 ++++++++++++++++++ react-ui/src/hooks/useWindowDimensions.js | 4 +- 5 files changed, 176 insertions(+), 10 deletions(-) create mode 100644 react-ui/src/components/freeagents/FreeAgentCards.js diff --git a/.gitignore b/.gitignore index 954810d51..dc64f1ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ coverage build # misc +plans xrank_data tourney_maps .DS_Store diff --git a/react-ui/src/components/freeagents/FATableRows.js b/react-ui/src/components/freeagents/FATableRows.js index 87ee65591..998b6c316 100644 --- a/react-ui/src/components/freeagents/FATableRows.js +++ b/react-ui/src/components/freeagents/FATableRows.js @@ -47,7 +47,7 @@ const FATableRows = ({ freeAgent }) => { setImageError(true)} + onError={() => setImageError(true)} /> )} diff --git a/react-ui/src/components/freeagents/FreeAgentBrowser.js b/react-ui/src/components/freeagents/FreeAgentBrowser.js index f35e0fde1..8c29496cf 100644 --- a/react-ui/src/components/freeagents/FreeAgentBrowser.js +++ b/react-ui/src/components/freeagents/FreeAgentBrowser.js @@ -20,6 +20,7 @@ import { freeAgentPosts } from "../../graphql/queries/freeAgentPosts" import { userLean } from "../../graphql/queries/userLean" import { hideFreeAgentPost } from "../../graphql/mutations/hideFreeAgentPost" import useWindowDimensions from "../../hooks/useWindowDimensions" +import FreeAgentCards from "./FreeAgentCards" const FreeAgentBrowser = () => { const [successMsg, setSuccessMsg] = useState(null) @@ -31,7 +32,7 @@ const FreeAgentBrowser = () => { region: "", }) - const { containerWidth } = useWindowDimensions() + const { isMobile } = useWindowDimensions() useEffect(() => { document.title = "Free Agents - sendou.ink" @@ -262,7 +263,7 @@ const FreeAgentBrowser = () => { }) return ( - <> +
{successMsg && {successMsg}} {errorMsg && {errorMsg}} {showForm ? ( @@ -277,10 +278,7 @@ const FreeAgentBrowser = () => { {!showForm && } - + @@ -288,13 +286,17 @@ const FreeAgentBrowser = () => { <>
{freeAgentPostArray.length > 0 ? ( - + isMobile ? ( + + ) : ( + + ) ) : ( )}
- +
) } diff --git a/react-ui/src/components/freeagents/FreeAgentCards.js b/react-ui/src/components/freeagents/FreeAgentCards.js new file mode 100644 index 000000000..2f9680648 --- /dev/null +++ b/react-ui/src/components/freeagents/FreeAgentCards.js @@ -0,0 +1,161 @@ +import React, { useState } from "react" +import { Table, Card, Image, Icon, Flag, Button } from "semantic-ui-react" +import { countries } from "../../utils/lists" +import InfiniteScroll from "react-infinite-scroller" +import { Link } from "react-router-dom" + +import FATableRows from "./FATableRows" +import WpnImage from "../common/WpnImage" +import RoleIcons from "./RoleIcons" +import VCIcon from "./VCIcon" + +const FreeAgentCard = ({ freeAgent }) => { + const [expanded, setExpanded] = useState(false) + const [imageError, setImageError] = useState(false) + + const { + activity, + description, + looking_for, + past_experience, + playstyles, + can_vc, + createdAt, + discord_user, + } = freeAgent + const { + twitter_name, + weapons, + discord_id, + discriminator, + username, + country, + } = discord_user + const playstylesObj = playstyles.reduce((acc, cur) => { + acc[cur] = true + return acc + }, {}) + + const hasExtraInfo = () => { + if (!activity && !description && !looking_for && !past_experience) { + return false + } + + return true + } + + return ( + + {twitter_name && !imageError && ( + setImageError(true)} + /> + )} + + + + {username}#{discriminator} + + + + {country && ( + <> + {" "} + {countries.reduce( + (acc, cur) => (cur.code === country ? cur.name : acc), + "" + )} + + )} + + + {twitter_name && !imageError && ( + <> + + {twitter_name} + + )} + + + {weapons.map(weapon => ( + + ))} + + + | + + + {new Date(parseInt(createdAt)).toLocaleDateString()} + + + {hasExtraInfo() && !expanded && ( + + + + )} + {expanded && ( + <> + + + {activity} + + + + {past_experience} + + + + {looking_for} + + + + {description} + + + + + + )} + + ) +} + +const FreeAgentCards = ({ FAArray }) => { + const [postsToShow, setPostsToShow] = useState(3) + + const loadMorePosts = page => { + setPostsToShow(page * 3) + } + + const visiblePosts = FAArray.filter((post, index) => index < postsToShow) + + return ( + + {visiblePosts.map(fa => { + return + })} + + ) +} + +export default FreeAgentCards diff --git a/react-ui/src/hooks/useWindowDimensions.js b/react-ui/src/hooks/useWindowDimensions.js index e67a34a28..2058cbb99 100644 --- a/react-ui/src/hooks/useWindowDimensions.js +++ b/react-ui/src/hooks/useWindowDimensions.js @@ -17,10 +17,12 @@ const getContainerWidth = width => { function getWindowDimensions() { const { innerWidth: width, innerHeight: height } = window const containerWidth = getContainerWidth(width) + const isMobile = containerWidth < 723 return { width, height, - containerWidth + containerWidth, + isMobile, } }