1- import { GameMetadataSource } from 'flashpoint-launcher' ;
2- import { InputElement } from 'flashpoint-launcher-renderer' ;
1+ import { GameDataSource , GameMetadataSource } from 'flashpoint-launcher' ;
2+ import { ConfirmDialogProps , InputElement } from 'flashpoint-launcher-renderer' ;
33import { updatePreferences } from 'flashpoint-launcher-renderer-ext/actions/preferences' ;
4- import { ConfigBox , ConfigBoxInput , ConfigSection , InputField } from 'flashpoint-launcher-renderer-ext/components' ;
5- import { useAppDispatch , useAppSelector } from 'flashpoint-launcher-renderer-ext/hooks' ;
4+ import { ConfigBox , ConfigBoxInput , ConfigSection , InputField , SimpleButton } from 'flashpoint-launcher-renderer-ext/components' ;
5+ import { useAppDispatch , useAppSelector , useConfirmDialog } from 'flashpoint-launcher-renderer-ext/hooks' ;
66import { selectRepoUrls , setRepoUrlsAction } from '../select' ;
77
88
99export function SubsectionSettings ( ) {
1010 const dispatch = useAppDispatch ( ) ;
11+ const { confirmDialog, openConfirmDialog } = useConfirmDialog ( ) ;
1112 const repoUrls = useAppSelector ( selectRepoUrls ) ;
13+ const dataSources = useAppSelector ( state => state . preferences . gameDataSources ) ;
1214 const metadataSources = useAppSelector ( state => state . preferences . gameMetadataSources ) ;
1315 const metadataSourceBoxes = metadataSources . map ( source => {
1416 return < MetadataRow source = { source } updateSource = { ( source ) => {
@@ -22,6 +24,25 @@ export function SubsectionSettings() {
2224 }
2325 } } /> ;
2426 } ) ;
27+ const dataSourceBoxes = dataSources . map ( ( data , idx ) => {
28+ return < DataRow
29+ data = { data }
30+ updateData = { ( data ) => {
31+ const newDataSources = [ ...dataSources ] ;
32+ newDataSources [ idx ] = data ;
33+ dispatch ( updatePreferences ( {
34+ gameDataSources : newDataSources
35+ } ) ) ;
36+ } }
37+ removeData = { ( ) => {
38+ const newDataSources = [ ...dataSources ] ;
39+ newDataSources . splice ( idx , 1 ) ;
40+ dispatch ( updatePreferences ( {
41+ gameDataSources : newDataSources
42+ } ) ) ;
43+ } }
44+ openConfirmDialog = { openConfirmDialog } /> ;
45+ } ) ;
2546
2647 return < div className = 'manager-page-subsection' >
2748 < div className = 'manager-page-subsection-header' > Settings</ div >
@@ -46,14 +67,118 @@ export function SubsectionSettings() {
4667 </ div >
4768 </ ConfigBox >
4869 </ ConfigSection >
70+ < ConfigSection >
71+ < ConfigBox
72+ title = 'Data Sources'
73+ description = 'List of all Flashpoint data sources to pull from'
74+ swapChildren = { true } >
75+ < div >
76+ < div className = 'manager-source-table-list' >
77+ { dataSourceBoxes }
78+ </ div >
79+ < SimpleButton
80+ value = { 'New Data Source' }
81+ onClick = { ( ) => {
82+ const newDataSources = [ ...dataSources ] ;
83+ newDataSources . push ( {
84+ type : '' ,
85+ name : '' ,
86+ arguments : '' ,
87+ } ) ;
88+ dispatch ( updatePreferences ( { gameDataSources : newDataSources } ) ) ;
89+ } } />
90+ </ div >
91+ </ ConfigBox >
92+ </ ConfigSection >
93+ { confirmDialog }
4994 </ div > ;
5095}
5196
97+ type DataRowProps = {
98+ data : GameDataSource ;
99+ updateData : ( newData : GameDataSource ) => void ;
100+ removeData : ( ) => void ;
101+ openConfirmDialog : ( props : Omit < ConfirmDialogProps , 'onResult' > ) => Promise < number > ;
102+ }
103+
52104type MetadataRowProps = {
53105 source : GameMetadataSource ;
54106 updateSource : ( newSource : GameMetadataSource ) => void ;
55107}
56108
109+ function DataRow ( { data, updateData, removeData, openConfirmDialog } : DataRowProps ) {
110+ const onUpdateType = ( event : React . ChangeEvent < InputElement > ) => {
111+ updateData ( {
112+ ...data ,
113+ type : event . target . value
114+ } ) ;
115+ } ;
116+ const onUpdateName = ( event : React . ChangeEvent < InputElement > ) => {
117+ updateData ( {
118+ ...data ,
119+ name : event . target . value
120+ } ) ;
121+ } ;
122+ const onUpdateArguments = ( event : React . ChangeEvent < InputElement > ) => {
123+ updateData ( {
124+ ...data ,
125+ arguments : event . target . value
126+ } ) ;
127+ } ;
128+
129+ return (
130+ < >
131+ < table className = 'curate-box-table' >
132+ < tbody >
133+ < tr className = 'curate-box-row' >
134+ < th className = 'curate-box-row__title' > Type</ th >
135+ < td className = 'curate-box-row__content' >
136+ < InputField
137+ text = { data . type || '' }
138+ placeholder = { 'No Type' }
139+ onChange = { onUpdateType }
140+ editable = { true } />
141+ </ td >
142+ </ tr >
143+ < tr className = 'curate-box-row' >
144+ < th className = 'curate-box-row__title' > Name</ th >
145+ < td className = 'curate-box-row__content' >
146+ < InputField
147+ text = { data . name || '' }
148+ placeholder = { 'No Name' }
149+ onChange = { onUpdateName }
150+ editable = { true } />
151+ </ td >
152+ </ tr >
153+ < tr className = 'curate-box-row' >
154+ < th className = 'curate-box-row__title' > Arguments</ th >
155+ < td className = 'curate-box-row__content' >
156+ < InputField
157+ text = { data . arguments }
158+ placeholder = { 'No Arguments' }
159+ onChange = { onUpdateArguments }
160+ editable = { true } />
161+ </ td >
162+ </ tr >
163+ </ tbody >
164+ </ table >
165+ < SimpleButton
166+ className = 'manager-data-delete-button'
167+ value = 'Delete'
168+ onClick = { async ( ) => {
169+ const res = await openConfirmDialog ( {
170+ message : 'Deleting data source, are you sure?' ,
171+ buttons : [ 'Yes' , 'No' ] ,
172+ cancelId : 1
173+ } ) ;
174+ if ( res === 0 ) {
175+ removeData ( ) ;
176+ }
177+ } } />
178+ </ >
179+ ) ;
180+ }
181+
57182function MetadataRow ( { source, updateSource } : MetadataRowProps ) {
58183 const onUpdateName = ( event : React . ChangeEvent < InputElement > ) => {
59184 updateSource ( {
@@ -113,5 +238,5 @@ function MetadataRow({ source, updateSource }: MetadataRowProps) {
113238 </ tr >
114239 </ tbody >
115240 </ table >
116- )
241+ ) ;
117242}
0 commit comments