-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logger from 'electron-timber'; | ||
import { createAsyncAction } from 'typesafe-actions'; | ||
|
||
import { rest } from '@nuclear/core'; | ||
import { Configuration } from '@nuclear/core/src/rest/Nuclear/Configuration'; | ||
|
||
import { NuclearConfiguration } from '../actionTypes'; | ||
|
||
export const fetchNuclearConfigurationAction = createAsyncAction( | ||
NuclearConfiguration.FETCH_NUCLEAR_CONFIG_START, | ||
NuclearConfiguration.FETCH_NUCLEAR_CONFIG_SUCCESS, | ||
NuclearConfiguration.FETCH_NUCLEAR_CONFIG_ERROR | ||
)<undefined, Configuration, string>(); | ||
|
||
export const fetchNuclearParamsAction = createAsyncAction( | ||
NuclearConfiguration.FETCH_NUCLEAR_PARAMS_START, | ||
NuclearConfiguration.FETCH_NUCLEAR_PARAMS_SUCCESS, | ||
NuclearConfiguration.FETCH_NUCLEAR_PARAMS_ERROR | ||
)(); | ||
|
||
export const fetchNuclearConfiguration = () => async (dispatch) => { | ||
dispatch(fetchNuclearConfigurationAction.request()); | ||
try { | ||
const service = new rest.NuclearConfigurationService( | ||
process.env.NUCLEAR_SERVICES_URL, | ||
process.env.NUCLEAR_SERVICES_ANON_KEY | ||
); | ||
const config = await service.getConfiguration(); | ||
dispatch(fetchNuclearConfigurationAction.success(config)); | ||
} catch (error) { | ||
dispatch(fetchNuclearConfigurationAction.failure(error.message)); | ||
logger.error(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createReducer } from 'typesafe-actions'; | ||
|
||
export class ConfigurationStore { | ||
|
||
} | ||
|
||
const defaultState = { ...new ConfigurationStore() }; | ||
|
||
export const reducer = createReducer<ConfigurationStore>(defaultState, { | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { NuclearSupabaseService } from './NuclearSupabaseService'; | ||
|
||
enum ConfigFlag { | ||
PROMOTED_ARTISTS = 'PROMOTED_ARTISTS', | ||
} | ||
|
||
enum ParamKey { | ||
PROMOTED_ARTIST_BACKGROUND = 'PROMOTED_ARTIST_BACKGROUND', | ||
} | ||
|
||
export type Configuration = { | ||
[key in ConfigFlag]: boolean; | ||
} | ||
|
||
export type Parameters = { | ||
[key in ParamKey]: string; | ||
} | ||
|
||
export type ConfigurationDbType = { | ||
key: ConfigFlag; | ||
value: boolean; | ||
}; | ||
export type ParamDbType = { | ||
key: ConfigFlag; | ||
value: string; | ||
}; | ||
|
||
export class NuclearConfigurationService extends NuclearSupabaseService { | ||
async getConfiguration() { | ||
const dbConfiguration = await this.client | ||
.from<ConfigurationDbType>('config') | ||
.select(); | ||
|
||
return dbConfiguration?.data.reduce((acc, curr) => { | ||
acc[curr.key] = curr.value; | ||
return acc; | ||
}, {} as Configuration); | ||
} | ||
|
||
async getParams() { | ||
const dbParams = await this.client | ||
.from<ParamDbType>('params') | ||
.select(); | ||
|
||
return dbParams?.data.reduce((acc, curr) => { | ||
acc[curr.key] = curr.value; | ||
return acc; | ||
}, {} as Parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters