Skip to content

Commit

Permalink
Fetch Nuclear configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Jul 26, 2022
1 parent dc9e2fb commit fa48858
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
NUCLEAR_SERVICES_URL=https://qjrujsisccsvyvjnqtnq.supabase.co
NUCLEAR_SERVICES_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFqcnVqc2lzY2Nzdnl2am5xdG5xIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTY1OTY0NjEsImV4cCI6MTk3MjE3MjQ2MX0.WQWcwBAQFNE259f2o8ruFln_UMLTFEn5aUD7KHrs9Aw
10 changes: 10 additions & 0 deletions packages/app/app/actions/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions packages/app/app/actions/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
34 changes: 34 additions & 0 deletions packages/app/app/actions/nuclear/configuration.ts
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);
}
};
3 changes: 3 additions & 0 deletions packages/app/app/containers/DashboardContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));
Expand All @@ -48,6 +50,7 @@ const DashboardContainer: React.FC = () => {
loadTopTags();
loadTopTracks();
loadPromotedArtists();
fetchNuclearConfiguration();

if (!dashboard.editorialCharts.isReady && !dashboard.editorialCharts.isLoading) {
loadEditorialCharts();
Expand Down
11 changes: 11 additions & 0 deletions packages/app/app/reducers/nuclear/configuration.ts
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, {

});
50 changes: 50 additions & 0 deletions packages/core/src/rest/Nuclear/Configuration.ts
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);
}
}
3 changes: 3 additions & 0 deletions packages/core/src/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ export { NuclearIdentityService };

import { NuclearPromotionService } from './Nuclear/Promotion';
export { NuclearPromotionService };

import { NuclearConfigurationService } from './Nuclear/Configuration';
export { NuclearConfigurationService };

0 comments on commit fa48858

Please sign in to comment.