diff --git a/.env b/.env index 8049f9beeb..a65a393d6a 100644 --- a/.env +++ b/.env @@ -7,5 +7,5 @@ JAMENDO_CLIENT_ID=836523a7 LAST_FM_API_KEY=2b75dcb291e2b0c9a2c994aca522ac14 LAST_FM_API_SECRET=2ee49e35f08b837d43b2824198171fc8 SOUNDCLOUD_API_KEY=22e8f71d7ca75e156d6b2f0e0a5172b3 -NUCLEAR_PROMOTION_URL=https://qjrujsisccsvyvjnqtnq.supabase.co -NUCLEAR_PROMOTION_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFqcnVqc2lzY2Nzdnl2am5xdG5xIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTY1OTY0NjEsImV4cCI6MTk3MjE3MjQ2MX0.WQWcwBAQFNE259f2o8ruFln_UMLTFEn5aUD7KHrs9Aw \ No newline at end of file +NUCLEAR_SERVICES_URL=https://qjrujsisccsvyvjnqtnq.supabase.co +NUCLEAR_SERVICES_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFqcnVqc2lzY2Nzdnl2am5xdG5xIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTY1OTY0NjEsImV4cCI6MTk3MjE3MjQ2MX0.WQWcwBAQFNE259f2o8ruFln_UMLTFEn5aUD7KHrs9Aw \ No newline at end of file diff --git a/packages/app/app/actions/actionTypes.ts b/packages/app/app/actions/actionTypes.ts index 927fc0df21..6cbf6be1c4 100644 --- a/packages/app/app/actions/actionTypes.ts +++ b/packages/app/app/actions/actionTypes.ts @@ -130,6 +130,16 @@ export enum NuclearIdentity { SIGN_OUT = 'SIGN_OUT' } +export enum NuclearConfiguration { + FETCH_NUCLEAR_CONFIG_START = 'FETCH_NUCLEAR_CONFIG_START', + FETCH_NUCLEAR_CONFIG_SUCCESS = 'FETCH_NUCLEAR_CONFIG_SUCCESS', + FETCH_NUCLEAR_CONFIG_ERROR = 'FETCH_NUCLEAR_CONFIG_ERROR', + + FETCH_NUCLEAR_PARAMS_START = 'FETCH_NUCLEAR_PARAMS_START', + FETCH_NUCLEAR_PARAMS_SUCCESS = 'FETCH_NUCLEAR_PARAMS_SUCCESS', + FETCH_NUCLEAR_PARAMS_ERROR = 'FETCH_NUCLEAR_PARAMS_ERROR', +} + export enum Equalizer { CHANGE_VALUE = 'CHANGE_VALUE', SELECT_PRESET = 'SELECT_PRESET', diff --git a/packages/app/app/actions/dashboard.ts b/packages/app/app/actions/dashboard.ts index be19c5e9b0..3cd6d5b7aa 100644 --- a/packages/app/app/actions/dashboard.ts +++ b/packages/app/app/actions/dashboard.ts @@ -163,8 +163,8 @@ export const loadPromotedArtists = () => async (dispatch) => { dispatch(loadPromotedArtistsAction.request()); try { const service = new rest.NuclearPromotionService( - process.env.NUCLEAR_PROMOTION_URL, - process.env.NUCLEAR_PROMOTION_ANON_KEY + process.env.NUCLEAR_SERVICES_URL, + process.env.NUCLEAR_SERVICES_ANON_KEY ); const artists = await service.getPromotedArtists(); dispatch(loadPromotedArtistsAction.success(artists?.data)); diff --git a/packages/app/app/actions/nuclear/configuration.ts b/packages/app/app/actions/nuclear/configuration.ts new file mode 100644 index 0000000000..9e481e698e --- /dev/null +++ b/packages/app/app/actions/nuclear/configuration.ts @@ -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 +)(); + +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); + } +}; diff --git a/packages/app/app/containers/DashboardContainer/index.tsx b/packages/app/app/containers/DashboardContainer/index.tsx index 9cda07274c..f85fa26f75 100644 --- a/packages/app/app/containers/DashboardContainer/index.tsx +++ b/packages/app/app/containers/DashboardContainer/index.tsx @@ -6,6 +6,7 @@ import * as DashboardActions from '../../actions/dashboard'; import * as FavoritesActions from '../../actions/favorites'; import * as QueueActions from '../../actions/queue'; import * as PlayerActions from '../../actions/player'; +import * as NuclearConfigActions from '../../actions/nuclear/configuration'; import Dashboard from '../../components/Dashboard'; import { dashboardSelector } from '../../selectors/dashboard'; @@ -28,6 +29,7 @@ const DashboardContainer: React.FC = () => { const loadTopTracks = () => dispatch(DashboardActions.loadTopTracks()); const loadEditorialCharts = () => dispatch(DashboardActions.loadEditorialCharts()); const loadPromotedArtists = () => dispatch(DashboardActions.loadPromotedArtists()); + const fetchNuclearConfiguration = () => dispatch(NuclearConfigActions.fetchNuclearConfiguration()); const artistInfoSearchByName = (artistName: string) => dispatch(SearchActions.artistInfoSearchByName(artistName, history)); const albumInfoSearchByName = (albumName: string, artistName: string) => dispatch(SearchActions.albumInfoSearchByName(albumName, artistName, history)); @@ -48,6 +50,7 @@ const DashboardContainer: React.FC = () => { loadTopTags(); loadTopTracks(); loadPromotedArtists(); + fetchNuclearConfiguration(); if (!dashboard.editorialCharts.isReady && !dashboard.editorialCharts.isLoading) { loadEditorialCharts(); diff --git a/packages/app/app/reducers/nuclear/configuration.ts b/packages/app/app/reducers/nuclear/configuration.ts new file mode 100644 index 0000000000..a4df4e51ee --- /dev/null +++ b/packages/app/app/reducers/nuclear/configuration.ts @@ -0,0 +1,11 @@ +import { createReducer } from 'typesafe-actions'; + +export class ConfigurationStore { + +} + +const defaultState = { ...new ConfigurationStore() }; + +export const reducer = createReducer(defaultState, { + +}); diff --git a/packages/core/src/rest/Nuclear/Configuration.ts b/packages/core/src/rest/Nuclear/Configuration.ts new file mode 100644 index 0000000000..7c8067c9fc --- /dev/null +++ b/packages/core/src/rest/Nuclear/Configuration.ts @@ -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('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('params') + .select(); + + return dbParams?.data.reduce((acc, curr) => { + acc[curr.key] = curr.value; + return acc; + }, {} as Parameters); + } +} diff --git a/packages/core/src/rest/index.ts b/packages/core/src/rest/index.ts index b427360fe9..4b7310e56d 100644 --- a/packages/core/src/rest/index.ts +++ b/packages/core/src/rest/index.ts @@ -32,3 +32,6 @@ export { NuclearIdentityService }; import { NuclearPromotionService } from './Nuclear/Promotion'; export { NuclearPromotionService }; + +import { NuclearConfigurationService } from './Nuclear/Configuration'; +export { NuclearConfigurationService };