@@ -10,6 +10,7 @@ import {
1010} from '../../frontend/feFootballMatchHeader' ;
1111import { safeParseURL } from '../../lib/parse' ;
1212import { error , fromValibot , ok , type Result } from '../../lib/result' ;
13+ import type { RenderingTarget } from '../../types/renderingTarget' ;
1314import type { Tabs } from './Tabs' ;
1415
1516export type HeaderData = {
@@ -19,7 +20,10 @@ export type HeaderData = {
1920} ;
2021
2122export const parse =
22- ( selected : HeaderData [ 'tabs' ] [ 'selected' ] ) =>
23+ (
24+ selected : HeaderData [ 'tabs' ] [ 'selected' ] ,
25+ renderingTarget : RenderingTarget ,
26+ ) =>
2327 ( json : unknown ) : Result < string , HeaderData > => {
2428 const feData = fromValibot (
2529 safeParse ( feFootballMatchHeaderSchema , json ) ,
@@ -39,6 +43,7 @@ export const parse =
3943 selected ,
4044 feData . value ,
4145 parsedMatch . value . kind ,
46+ renderingTarget ,
4247 ) ;
4348
4449 if ( ! maybeTabs . ok ) {
@@ -58,18 +63,37 @@ type MatchURLError = {
5863 kind : 'live' | 'report' | 'info' ;
5964} ;
6065
66+ const getInfoUrl = (
67+ feData : FEFootballMatchHeader ,
68+ renderingTarget : RenderingTarget ,
69+ ) : Result < MatchURLError , URL > => {
70+ const parsedInfoURL = safeParseURL ( feData . infoURL ) ;
71+
72+ if ( ! parsedInfoURL . ok ) {
73+ return error ( { kind : 'info' } ) ;
74+ }
75+
76+ if ( renderingTarget === 'Apps' ) {
77+ const path = `football/match/${ feData . footballMatch . id } ` ;
78+ return ok ( new URL ( path , parsedInfoURL . value . origin ) ) ;
79+ }
80+
81+ return ok ( parsedInfoURL . value ) ;
82+ } ;
83+
6184const createTabs = (
6285 selected : HeaderData [ 'tabs' ] [ 'selected' ] ,
6386 feData : FEFootballMatchHeader ,
6487 matchKind : FootballMatch [ 'kind' ] ,
88+ renderingTarget : RenderingTarget ,
6589) : Result < MatchURLError , HeaderData [ 'tabs' ] > => {
6690 const reportURL =
6791 feData . reportURL !== undefined
6892 ? safeParseURL ( feData . reportURL )
6993 : undefined ;
7094 const liveURL =
7195 feData . liveURL !== undefined ? safeParseURL ( feData . liveURL ) : undefined ;
72- const infoURL = safeParseURL ( feData . infoURL ) ;
96+ const infoURL = getInfoUrl ( feData , renderingTarget ) ;
7397
7498 if ( reportURL !== undefined && ! reportURL . ok ) {
7599 return error ( { kind : 'report' } ) ;
0 commit comments