From 57c3fd4db3129500623b28542467f7509fd609ac Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Mon, 17 Aug 2026 12:53:41 +0000 Subject: [PATCH 1/2] refactor(match2): allow passing the GameRow only --- lua/wikis/chess/MatchSummary.lua | 18 +++++-------- lua/wikis/commons/MatchSummary/Base.lua | 36 ++++++++++++++++++------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/lua/wikis/chess/MatchSummary.lua b/lua/wikis/chess/MatchSummary.lua index f47768a79f8..af882e4e990 100644 --- a/lua/wikis/chess/MatchSummary.lua +++ b/lua/wikis/chess/MatchSummary.lua @@ -46,30 +46,24 @@ local KING_ICONS = { }, } ----@class ChessCustomMatchSummary: CustomMatchSummaryInterface -local CustomMatchSummary = {} + ---@class ChessMatchSummaryGameRowComponentProps: MatchSummaryGameRowComponentProps local GameRowComponentProps = {} local ChessMatchSummaryGameRow = MatchSummaryWidgets.GameRow.createComponent(GameRowComponentProps) +---@class ChessCustomMatchSummary: CustomMatchSummaryInterface +local CustomMatchSummary = { + GameRow = ChessMatchSummaryGameRow, +} + ---@param args table ---@return VNode function CustomMatchSummary.getByMatchId(args) return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) end ----@param match MatchGroupUtilMatch ----@return Renderable -function CustomMatchSummary.createGames(match) - return MatchSummaryWidgets.GamesContainer{ - children = Array.map(match.games, function (game, gameIndex) - return ChessMatchSummaryGameRow{game = game, gameIndex = gameIndex} - end) - } -end - ---@param props MatchSummaryGameRowProps ---@return Renderable? function GameRowComponentProps.createGameOverview(props) diff --git a/lua/wikis/commons/MatchSummary/Base.lua b/lua/wikis/commons/MatchSummary/Base.lua index db7f49d43e9..35087052949 100644 --- a/lua/wikis/commons/MatchSummary/Base.lua +++ b/lua/wikis/commons/MatchSummary/Base.lua @@ -31,8 +31,9 @@ local TBD = Abbreviation.make{text = 'TBD', title = 'To Be Determined'} ---@class CustomMatchSummaryInterface ---@field createBody? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated ----@field createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] ----@field createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[] +---@field createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated (but better than createBody) +---@field createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[] @deprecated +---@field GameRow Component ---@field createFooter? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] ---@class MatchSummary @@ -60,19 +61,33 @@ end -- Default body function ---@param match MatchGroupUtilMatch ----@param createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]? ----@param createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[] +---@param CustomMatchSummary CustomMatchSummaryInterface ---@param options {maxBans: integer?}? ---@return Renderable[] -function MatchSummary.createDefaultBody(match, createGames, createGame, options) +function MatchSummary.createDefaultBody(match, CustomMatchSummary, options) options = options or {} local characterBansData = MatchSummary.buildCharacterBanData(match.games, options.maxBans or 0) + local createGames = CustomMatchSummary.createGames + local createGame = CustomMatchSummary.createGame + + local nodes + if CustomMatchSummary.GameRow then + nodes = MatchSummaryWidgets.GamesContainer{ + children = Array.map(match.games, function(game, gameIndex) + return CustomMatchSummary.GameRow{game = game, gameIndex = gameIndex} + end) + } + elseif createGames then + nodes = createGames(match) + else + ---@diagnostic disable-next-line: param-type-mismatch fixed in another PR + nodes = Array.map(match.games, FnUtil.curry(createGame, match.date)) + end + return WidgetUtil.collect( - --- we assume that createGames and createGame are mutually exclusive, so we can safely call one or the other - ---@diagnostic disable-next-line: param-type-mismatch - createGames and createGames(match) or Array.map(match.games, FnUtil.curry(createGame, match.date)), + nodes, MatchSummaryWidgets.Mvp(match.extradata.mvp), MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game})), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date} @@ -191,7 +206,7 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options) MatchSummary.createHeader(matchData, options), MatchSummaryWidgets.Body{ children = WidgetUtil.collect( - createBody(matchData, CustomMatchSummary.createGames, CustomMatchSummary.createGame, options), + createBody(matchData, CustomMatchSummary, options), Html.Fragment{ children = { MatchSummaryWidgets.Casters{casters = matchData.extradata.casters}, @@ -221,7 +236,8 @@ function MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options) ( type(CustomMatchSummary.createBody) == 'function' or type(CustomMatchSummary.createGame) == 'function' or - type(CustomMatchSummary.createGames) == 'function' + type(CustomMatchSummary.createGames) == 'function' or + CustomMatchSummary.GameRow ), 'One of createBody or createGame or createGames must be implemented in Module:MatchSummary' ) From 1b89bb3f982f69d780a7392783323d46542f4230 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Tue, 18 Aug 2026 10:57:09 +0000 Subject: [PATCH 2/2] optional --- lua/wikis/commons/MatchSummary/Base.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wikis/commons/MatchSummary/Base.lua b/lua/wikis/commons/MatchSummary/Base.lua index 35087052949..8793768377b 100644 --- a/lua/wikis/commons/MatchSummary/Base.lua +++ b/lua/wikis/commons/MatchSummary/Base.lua @@ -33,7 +33,7 @@ local TBD = Abbreviation.make{text = 'TBD', title = 'To Be Determined'} ---@field createBody? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated ---@field createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated (but better than createBody) ---@field createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[] @deprecated ----@field GameRow Component +---@field GameRow? Component ---@field createFooter? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] ---@class MatchSummary