gatsby-core-theme 44.0.30 → 44.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/package.json +1 -1
- package/src/components/organisms/anchor/template-one/index.js +10 -0
- package/src/helpers/processor/common.mjs +1 -0
- package/src/helpers/processor/sports-relations.mjs +70 -45
- package/src/helpers/processor/sports-relations.test.js +13 -26
- package/src/helpers/schedule.mjs +21 -3
- package/src/helpers/schedule.test.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## [44.0.32](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.31...v44.0.32) (2025-05-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* reduce issue ([75b42d2](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/75b42d27a5d61d49ce367f32cd0f7e313ec20bf8))
|
|
7
|
+
* reduce issue ([f6bbe39](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/f6bbe39acf967013cc13fed91e1e84b12d08d41c))
|
|
8
|
+
|
|
9
|
+
## [44.0.31](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.30...v44.0.31) (2025-05-05)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* ammended page relations for smaller build sizes ([a2d0522](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/a2d0522c6dacf821274d63393d9d46f769bacbe6))
|
|
15
|
+
* anchor smooth upon scroll ([75abe97](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/75abe972ff85cb6ba6e05c33212206680b73e530))
|
|
16
|
+
* tests ([e477d92](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e477d92c4a3f6fcf0ca5102c473880e78ba6def7))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Code Refactoring
|
|
20
|
+
|
|
21
|
+
* anchor links smooth scroll ([077568e](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/077568e1bd3405268cc791e53606f4ddd3c2cbeb))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
* Merge branch 'tm-5429-page-relation' into 'master' ([38ac892](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/38ac892d2d82a94d61dccfed99ee4409162cfad0))
|
|
25
|
+
* Merge branch 'tm-4830-anchor-links' into 'master' ([f6a9744](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/f6a974470c3ed7365e9ed724e64396179e0880db))
|
|
26
|
+
|
|
1
27
|
## [44.0.30](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.29...v44.0.30) (2025-05-05)
|
|
2
28
|
|
|
3
29
|
|
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@ function Anchor({
|
|
|
22
22
|
leftButtonIcon = <IoIosArrowBack />,
|
|
23
23
|
rightButtonIcon = <IoIosArrowForward />,
|
|
24
24
|
hasAdmin = false,
|
|
25
|
+
offset = 132,
|
|
25
26
|
}) {
|
|
26
27
|
const [scrollX, setScrollX] = useState(0);
|
|
27
28
|
const [scrollEnd, setScrollEnd] = useState(false);
|
|
@@ -111,6 +112,14 @@ function Anchor({
|
|
|
111
112
|
// eslint-disable-next-line no-return-assign
|
|
112
113
|
ref={(el) => (itemsRef.current[index] = el)}
|
|
113
114
|
href={`#${item?.id && item.id}`}
|
|
115
|
+
onClick={(e) => {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
const el = document.getElementById(item.id);
|
|
118
|
+
if (el) {
|
|
119
|
+
const y = el.getBoundingClientRect().top + window.pageYOffset - offset;
|
|
120
|
+
window.scrollTo({ top: y, behavior: "smooth" });
|
|
121
|
+
}
|
|
122
|
+
}}
|
|
114
123
|
>
|
|
115
124
|
{useTranslate(item.slug, item.label)}
|
|
116
125
|
{icon}
|
|
@@ -182,6 +191,7 @@ Anchor.propTypes = {
|
|
|
182
191
|
minCharactersForButtons: PropTypes.number,
|
|
183
192
|
setShowButtons: PropTypes.bool,
|
|
184
193
|
hasAdmin: PropTypes.bool,
|
|
194
|
+
offset: PropTypes.number,
|
|
185
195
|
};
|
|
186
196
|
|
|
187
197
|
export default Anchor;
|
|
@@ -207,6 +207,7 @@ export function removeUnwantedSections(obj, pageType, ribbonsData) {
|
|
|
207
207
|
|
|
208
208
|
export function filterRelation (relation, allowedKeys) {
|
|
209
209
|
if (!relation) return undefined;
|
|
210
|
+
if (!allowedKeys) return relation;
|
|
210
211
|
|
|
211
212
|
return allowedKeys.reduce((acc, key) => {
|
|
212
213
|
if (relation[key]) {
|
|
@@ -20,20 +20,22 @@ export function extractParticipantIds(participantsData) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function modifyMarketEvents(sportsMarketData, data, market) {
|
|
23
|
-
// Optimization 1: Avoid cloneDeep if sportsMarketData.events is not modified elsewhere
|
|
24
23
|
const events = sportsMarketData?.events || {};
|
|
25
|
-
|
|
26
24
|
const pathPrefix = data?.site_markets?.[market]?.path_prefix;
|
|
27
25
|
|
|
28
|
-
// Optimization 2: Early exit if no path prefix
|
|
29
|
-
if (!pathPrefix) {
|
|
30
|
-
return events;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Optimization 3: More efficient object iteration using for...in
|
|
34
26
|
for (const eventKey in events) {
|
|
35
27
|
if (Object.hasOwnProperty.call(events, eventKey)) {
|
|
36
|
-
|
|
28
|
+
const event = events[eventKey];
|
|
29
|
+
|
|
30
|
+
// Flatten the nested date
|
|
31
|
+
if (event.date && typeof event.date === 'object' && 'date' in event.date) {
|
|
32
|
+
event.date = event.date.date;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Prepend path prefix if available
|
|
36
|
+
if (pathPrefix) {
|
|
37
|
+
event.path = `${pathPrefix}/${event.path}`;
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -85,7 +87,7 @@ function modifyMarketTournaments(
|
|
|
85
87
|
Object.fromEntries(
|
|
86
88
|
sportsMarketData.tournaments[tournamentID].teams.map((teamID) => [
|
|
87
89
|
data.relations.sports_data.teams?.[teamID].livegoals_v2_id,
|
|
88
|
-
data.relations.sports_data.team_kits[teams[teamID].livegoals_v2_id],
|
|
90
|
+
data.relations.sports_data.team_kits[teams[teamID].livegoals_v2_id] && data.relations.sports_data.team_kits[teams[teamID].livegoals_v2_id].map((kit) => kit.items)[0],
|
|
89
91
|
])
|
|
90
92
|
)
|
|
91
93
|
);
|
|
@@ -120,7 +122,7 @@ function modifyMarketTournaments(
|
|
|
120
122
|
team_kits: tournamentTeamKits,
|
|
121
123
|
schedule:
|
|
122
124
|
schedule && schedule.soccer
|
|
123
|
-
? filterScheduleByDate(schedule, sportsMarketData.tournaments)
|
|
125
|
+
? filterScheduleByDate(schedule, sportsMarketData.tournaments).schedule
|
|
124
126
|
: {},
|
|
125
127
|
featured_events: allFeaturedEvents
|
|
126
128
|
? allFeaturedEvents.filter((id) =>
|
|
@@ -151,27 +153,59 @@ export const processSportsRelations = (
|
|
|
151
153
|
let events = null;
|
|
152
154
|
|
|
153
155
|
if (sportsMarketData) {
|
|
156
|
+
const filteredKits = {};
|
|
157
|
+
for (const [key, value] of Object.entries(data.relations.sports_data.team_kits)) {
|
|
158
|
+
filteredKits[key] = value?.[0]?.items || {};
|
|
159
|
+
}
|
|
160
|
+
|
|
154
161
|
switch (page.template) {
|
|
155
162
|
case "homepage_sports":
|
|
156
163
|
events = modifyMarketEvents(sportsMarketData, data, market);
|
|
157
|
-
|
|
158
|
-
relation.teams = data.relations.sports_data.teams;
|
|
164
|
+
|
|
159
165
|
relation.events = events;
|
|
160
166
|
relation.tournaments = sportsMarketData.tournaments;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
|
|
168
|
+
relation.teams = {};
|
|
169
|
+
for (const [key, value] of Object.entries(events)) {
|
|
170
|
+
relation.events[key] = {
|
|
171
|
+
date: value.date,
|
|
172
|
+
away_team: value.away_team,
|
|
173
|
+
home_team: value.home_team,
|
|
174
|
+
livegoals_v2_id: value.livegoals_v2_id,
|
|
175
|
+
id: value.id,
|
|
176
|
+
path: value.path,
|
|
177
|
+
sport: value.sport,
|
|
178
|
+
tournament: value.tournament
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
165
182
|
relation.featured_events = Object.keys(events).filter(
|
|
166
183
|
(id) => events[id].featured === 1
|
|
167
184
|
);
|
|
168
|
-
|
|
185
|
+
|
|
186
|
+
relation.teams = {};
|
|
187
|
+
for (const [key, value] of Object.entries(data.relations.sports_data.teams)) {
|
|
188
|
+
relation.teams[key] = {
|
|
189
|
+
livegoals_v2_id: value.livegoals_v2_id,
|
|
190
|
+
name: value.name
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const filteredSchedule = filterScheduleByDate(
|
|
195
|
+
cloneDeep(sportsMarketData.schedule),
|
|
196
|
+
sportsMarketData.tournaments,
|
|
197
|
+
relation.events,
|
|
198
|
+
relation.teams,
|
|
199
|
+
filteredKits
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
relation = { ...relation, ...filteredSchedule};
|
|
169
203
|
|
|
170
204
|
transformedPages[market][pageType][index].relation = relation;
|
|
171
205
|
break;
|
|
172
206
|
case "event":
|
|
173
207
|
// Optimization 1: Avoid cloneDeep if not strictly necessary
|
|
174
|
-
const {teams} = data.relations.sports_data;
|
|
208
|
+
const { teams } = data.relations.sports_data;
|
|
175
209
|
events = modifyMarketEvents(sportsMarketData, data, market);
|
|
176
210
|
|
|
177
211
|
if (
|
|
@@ -181,35 +215,26 @@ export const processSportsRelations = (
|
|
|
181
215
|
const event = events[page.relation_id]; // Direct access if 'events' is keyed correctly
|
|
182
216
|
|
|
183
217
|
const tournament = sportsMarketData.tournaments[event.tournament]; // Direct access
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const eventTeams = {};
|
|
187
|
-
|
|
188
|
-
// Optimization 2: Convert teams and team_kits to Maps if used frequently
|
|
189
|
-
const teamsMap = new Map(Object.entries(teams));
|
|
190
|
-
|
|
191
|
-
const teamKitsMap = new Map(
|
|
192
|
-
Object.entries(data.relations.sports_data.team_kits)
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
if (tournament && tournament.teams) {
|
|
196
|
-
tournament.teams.forEach((teamId) => {
|
|
197
|
-
|
|
198
|
-
const team = teamsMap.get(teamId.toString());
|
|
199
|
-
const kit = team?.livegoals_v2_id ? teamKitsMap.get(team?.livegoals_v2_id.toString()) : null;
|
|
200
|
-
|
|
201
|
-
if (team && kit) {
|
|
202
|
-
teamKits[team.livegoals_v2_id] = kit; // Shallow copy might be enough
|
|
203
|
-
eventTeams[teamId] = team; // Shallow copy might be enough
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
218
|
+
delete tournament.events;
|
|
219
|
+
delete tournament.teams;
|
|
207
220
|
|
|
208
221
|
relation = {
|
|
209
222
|
event, // Direct access
|
|
210
223
|
tournament, // Direct access
|
|
211
|
-
team_kits:
|
|
212
|
-
|
|
224
|
+
team_kits: [
|
|
225
|
+
filteredKits[teams[event.home_team].livegoals_v2_id],
|
|
226
|
+
filteredKits[teams[event.away_team].livegoals_v2_id]
|
|
227
|
+
],
|
|
228
|
+
teams: [
|
|
229
|
+
{
|
|
230
|
+
livegoals_v2_id: teams[event.home_team].livegoals_v2_id,
|
|
231
|
+
name: teams[event.home_team].name
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
livegoals_v2_id: teams[event.away_team].livegoals_v2_id,
|
|
235
|
+
name: teams[event.away_team].name
|
|
236
|
+
},
|
|
237
|
+
],
|
|
213
238
|
};
|
|
214
239
|
|
|
215
240
|
transformedPages[market][pageType][index].relation = relation;
|
|
@@ -272,4 +297,4 @@ export const processSportsRelations = (
|
|
|
272
297
|
break;
|
|
273
298
|
}
|
|
274
299
|
}
|
|
275
|
-
};
|
|
300
|
+
};
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
processSportsRelations,
|
|
4
4
|
extractParticipantIds,
|
|
5
5
|
} from "./sports-relations.mjs";
|
|
6
|
-
import { filterScheduleByDate } from "../schedule.mjs";
|
|
7
6
|
|
|
8
7
|
jest.mock("lodash", () => ({
|
|
9
8
|
cloneDeep: jest.fn((obj) => JSON.parse(JSON.stringify(obj))),
|
|
@@ -38,16 +37,16 @@ describe("processSportsRelations function", () => {
|
|
|
38
37
|
},
|
|
39
38
|
relations: {
|
|
40
39
|
sports_data: {
|
|
41
|
-
teams: { 1: { id: 1, name: "Team 1" }, 2: { id: 2, name: "Team 2" } },
|
|
42
|
-
team_kits: { 1: {
|
|
40
|
+
teams: { 1: { id: 1, livegoals_v2_id: 1, name: "Team 1" }, 2: { id: 2, livegoals_v2_id: 2, name: "Team 2" } },
|
|
41
|
+
team_kits: { 1: [{ items: "kit1" }], 2: [{ items: "kit2" }] },
|
|
43
42
|
markets: {
|
|
44
43
|
gb_en: {
|
|
45
44
|
events: {
|
|
46
45
|
1: {
|
|
47
46
|
featured: 1,
|
|
48
47
|
id: 1,
|
|
49
|
-
home_team:
|
|
50
|
-
away_team:
|
|
48
|
+
home_team: 1,
|
|
49
|
+
away_team: 2,
|
|
51
50
|
tournament: 1,
|
|
52
51
|
},
|
|
53
52
|
},
|
|
@@ -78,19 +77,15 @@ describe("processSportsRelations function", () => {
|
|
|
78
77
|
data,
|
|
79
78
|
index
|
|
80
79
|
);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
data.relations.sports_data.markets.gb_en.tournaments
|
|
91
|
-
),
|
|
92
|
-
featured_events: ["1"],
|
|
93
|
-
});
|
|
80
|
+
expect(Object.keys(transformedPages[market][pageType][index].relation)).toEqual(
|
|
81
|
+
[
|
|
82
|
+
"events",
|
|
83
|
+
"tournaments",
|
|
84
|
+
"teams",
|
|
85
|
+
"featured_events",
|
|
86
|
+
"soccer"
|
|
87
|
+
]
|
|
88
|
+
);
|
|
94
89
|
});
|
|
95
90
|
|
|
96
91
|
test("should process event template with valid relation_id", () => {
|
|
@@ -132,14 +127,6 @@ describe("processSportsRelations function", () => {
|
|
|
132
127
|
).toEqual({
|
|
133
128
|
1: cloneDeep(data.relations.sports_data.markets.gb_en.tournaments[1]),
|
|
134
129
|
});
|
|
135
|
-
|
|
136
|
-
expect(transformedPages[market][pageType][index].relation.schedule).toEqual(
|
|
137
|
-
{
|
|
138
|
-
soccer: {
|
|
139
|
-
"2024-01-01": { tournaments: { 1: { events: [1] } } },
|
|
140
|
-
},
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
130
|
});
|
|
144
131
|
|
|
145
132
|
test("should handle unknown page templates", () => {
|
package/src/helpers/schedule.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
/* eslint-disable array-callback-return */
|
|
1
3
|
export function reverseDate(date) {
|
|
2
4
|
return date.split('-').reverse().join('-');
|
|
3
5
|
}
|
|
@@ -6,21 +8,37 @@ export function zeroPadding(num, places) {
|
|
|
6
8
|
return String(num).padStart(places, '0');
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
export function
|
|
11
|
+
export function populateTeamKits( tournaments, events, teams, team_kits ){
|
|
12
|
+
const tournamentKits = {}
|
|
13
|
+
Object.entries(tournaments || {}).forEach(([, tournament]) =>
|
|
14
|
+
tournament?.events && tournament?.events.forEach((eventId) => {
|
|
15
|
+
const homeTeam = events?.[eventId]?.home_team;
|
|
16
|
+
const awayTeam = events?.[eventId]?.away_team;
|
|
17
|
+
|
|
18
|
+
tournamentKits[teams?.[homeTeam]?.livegoals_v2_id] = team_kits?.[teams?.[homeTeam].livegoals_v2_id] && team_kits[teams?.[homeTeam].livegoals_v2_id];
|
|
19
|
+
tournamentKits[teams?.[awayTeam]?.livegoals_v2_id] = team_kits?.[teams?.[awayTeam].livegoals_v2_id] && team_kits[teams?.[awayTeam].livegoals_v2_id];
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
return tournamentKits;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function filterScheduleByDate(schedule, tournaments, events, teams, team_kits) {
|
|
10
26
|
const today = new Date().setHours(0, 0, 0, 0);
|
|
11
27
|
let todayFound = false;
|
|
12
28
|
let todayNextIndex = null;
|
|
13
|
-
|
|
29
|
+
let filteredTeamKits = null;
|
|
14
30
|
Object.keys(schedule.soccer).forEach((key, index) => {
|
|
15
31
|
if (new Date(key).setHours(0, 0, 0, 0) === today) {
|
|
16
32
|
schedule.soccer[key] = { ...schedule.soccer[key], active: true};
|
|
17
33
|
todayFound = true;
|
|
18
34
|
todayNextIndex = index;
|
|
35
|
+
filteredTeamKits = populateTeamKits( schedule.soccer[key].tournaments, events, teams, team_kits );
|
|
19
36
|
}
|
|
20
37
|
if(tournaments){
|
|
21
38
|
schedule.soccer[key].sorting = Object.keys(schedule.soccer[key].tournaments).sort(
|
|
22
39
|
(aKey, bKey) => tournaments?.[aKey]?.sort_order - tournaments?.[bKey]?.sort_order);
|
|
23
40
|
}
|
|
41
|
+
delete schedule.soccer[key].date;
|
|
24
42
|
});
|
|
25
43
|
|
|
26
44
|
let nextDay = false;
|
|
@@ -53,7 +71,7 @@ export function filterScheduleByDate(schedule, tournaments) {
|
|
|
53
71
|
schedule.soccer = Object.fromEntries(remainingEntries);
|
|
54
72
|
}
|
|
55
73
|
|
|
56
|
-
return schedule;
|
|
74
|
+
return {schedule, team_kits: filteredTeamKits};
|
|
57
75
|
}
|
|
58
76
|
|
|
59
77
|
export function filterEvents(tournamentEvents, events) {
|
|
@@ -1679,7 +1679,7 @@ const schedule = {
|
|
|
1679
1679
|
describe('Schedule Helper', () => {
|
|
1680
1680
|
test('filterScheduleByDate()', () => {
|
|
1681
1681
|
const output = filterScheduleByDate(schedule);
|
|
1682
|
-
expect(output.soccer['2021-04-12'].active).toEqual(true);
|
|
1683
|
-
expect(output.soccer['2021-04-10'].active).toEqual(undefined);
|
|
1682
|
+
expect(output.schedule.soccer['2021-04-12'].active).toEqual(true);
|
|
1683
|
+
expect(output.schedule.soccer['2021-04-10'].active).toEqual(undefined);
|
|
1684
1684
|
});
|
|
1685
1685
|
});
|