1
|
|
|
import { graphql, useStaticQuery } from "gatsby" |
2
|
|
|
import React, { FunctionComponent, useState } from "react" |
3
|
|
|
import Select from "react-select" |
4
|
|
|
|
5
|
|
|
import Spinner from "../components/Spinner" |
6
|
|
|
import SEO from "../components/seo" |
7
|
|
|
import Layout from "../layouts/index" |
8
|
|
|
import { PlayerListProps } from "../types/pages.types" |
9
|
|
|
|
10
|
|
|
const ShareForm = () => { |
11
|
|
|
const templateUrl = `https://footbalisto.be/share/instagram/` |
12
|
|
|
|
13
|
|
|
const [playerSelected, setPlayerSelected] = useState<string>(``) |
14
|
|
|
const [score, setScore] = useState<string>(``) |
15
|
|
|
const [match, setMatch] = useState<string>(``) |
16
|
|
|
const [imageUrl, setImageUrl] = useState<string>(``) |
17
|
|
|
const [imageLoading, setImageLoading] = useState<boolean>(false) |
18
|
|
|
|
19
|
|
|
const { playerEdges }: PlayerListProps = useStaticQuery(graphql` |
20
|
|
|
query { |
21
|
|
|
playerEdges: allNodePlayer(filter: { field_vv_id: { ne: null } }) { |
22
|
|
|
edges { |
23
|
|
|
node { |
24
|
|
|
path { |
25
|
|
|
alias |
26
|
|
|
} |
27
|
|
|
field_firstname |
28
|
|
|
field_lastname |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
`) |
34
|
|
|
|
35
|
|
|
const players = playerEdges.edges.map(({ node }) => ({ |
36
|
|
|
value: node.path.alias, |
37
|
|
|
label: `${node.field_firstname} ${node.field_lastname}`, |
38
|
|
|
})) |
39
|
|
|
|
40
|
|
|
const handlePlayerChange = (inputValue: { value: string; label: string } | null) => { |
41
|
|
|
if (inputValue?.value) { |
42
|
|
|
setPlayerSelected(inputValue.value.replace(`/player/`, ``)) |
43
|
|
|
} else { |
44
|
|
|
setPlayerSelected(``) |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
const handleMatchChange = (event: { target: { value: React.SetStateAction<string> } }) => { |
49
|
|
|
setMatch(event.target.value) |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
const handleScoreChange = (event: { target: { value: React.SetStateAction<string> } }) => { |
53
|
|
|
setScore(event.target.value) |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
const handleGenerateImage = (event: React.MouseEvent<HTMLButtonElement>) => { |
57
|
|
|
event.preventDefault() |
58
|
|
|
if (match !== `` && score !== `` && playerSelected !== ``) { |
59
|
|
|
setImageUrl(``) |
60
|
|
|
setImageUrl(`${templateUrl}${playerSelected}?score=${score}&match=${match}`) |
61
|
|
|
setImageLoading(true) |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
const handleImageLoaded = () => { |
66
|
|
|
setImageLoading(false) |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return ( |
70
|
|
|
<div> |
71
|
|
|
<form> |
72
|
|
|
<p> |
73
|
|
|
<label htmlFor="calendar__player">Speler:</label> |
74
|
|
|
<Select |
75
|
|
|
options={players} |
76
|
|
|
name="player" |
77
|
|
|
id="calendar__player" |
78
|
|
|
className="select__input" |
79
|
|
|
onChange={handlePlayerChange} |
80
|
|
|
/> |
81
|
|
|
</p> |
82
|
|
|
<p> |
83
|
|
|
<label htmlFor="calendar__game">Wedstrijd:</label> |
84
|
|
|
<input |
85
|
|
|
id="calendar__game" |
86
|
|
|
onChange={handleMatchChange} |
87
|
|
|
className={`input__input`} |
88
|
|
|
placeholder="KCVV Elewijt - KFC Eppegem" |
89
|
|
|
value={match} |
90
|
|
|
required={true} |
91
|
|
|
/> |
92
|
|
|
</p> |
93
|
|
|
<p> |
94
|
|
|
<label htmlFor="calendar__score">Score:</label> |
95
|
|
|
<input |
96
|
|
|
id="calendar__score" |
97
|
|
|
onChange={handleScoreChange} |
98
|
|
|
className={`input__input`} |
99
|
|
|
placeholder="2 — 0" |
100
|
|
|
value={score} |
101
|
|
|
required={true} |
102
|
|
|
/> |
103
|
|
|
</p> |
104
|
|
|
<p> |
105
|
|
|
<button onClick={handleGenerateImage} className="btn"> |
106
|
|
|
Creëer afbeelding. |
107
|
|
|
</button> |
108
|
|
|
</p> |
109
|
|
|
</form> |
110
|
|
|
|
111
|
|
|
<p> |
112
|
|
|
{imageLoading && <Spinner />} |
113
|
|
|
{imageUrl && <img src={imageUrl} onLoad={handleImageLoaded} />} |
114
|
|
|
</p> |
115
|
|
|
</div> |
116
|
|
|
) |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
const CreateSharePage = () => ( |
120
|
|
|
<Layout> |
121
|
|
|
<SEO |
122
|
|
|
lang="nl-BE" |
123
|
|
|
title="Creëer instagram goal story" |
124
|
|
|
description="Creëer een nieuwe instagram story voor een doelpunt." |
125
|
|
|
path="calendar" |
126
|
|
|
/> |
127
|
|
|
|
128
|
|
|
<div className={`limited-width_wrapper`}> |
129
|
|
|
<header> |
130
|
|
|
<h1>Creëer afbeelding</h1> |
131
|
|
|
</header> |
132
|
|
|
<main> |
133
|
|
|
<ShareForm /> |
134
|
|
|
</main> |
135
|
|
|
</div> |
136
|
|
|
</Layout> |
137
|
|
|
) |
138
|
|
|
|
139
|
|
|
export default CreateSharePage |
140
|
|
|
|