From 23eebe31f7d1bdb83e493fcbd15992eb229fffe4 Mon Sep 17 00:00:00 2001 From: nukeop <12746779+nukeop@users.noreply.github.com> Date: Wed, 5 Feb 2025 23:56:32 +0100 Subject: [PATCH] Resolve the next part of type issues --- packages/app/app/actions/importfavs.ts | 3 ++- packages/app/app/actions/plugins.tsx | 3 ++- packages/app/app/actions/scrobbling.ts | 8 ++++---- packages/app/app/actions/toasts.ts | 2 +- .../PluginsView/UserPluginsSection/index.tsx | 4 ++-- .../Settings/Integrations/LastFmSocialIntegration.tsx | 2 +- packages/app/app/components/Settings/index.tsx | 2 +- packages/app/app/reducers/plugins.ts | 7 ++++--- packages/app/app/reducers/scrobbling.ts | 11 +++++++++-- 9 files changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/app/app/actions/importfavs.ts b/packages/app/app/actions/importfavs.ts index 8d8d2d90b2..1452d7f563 100644 --- a/packages/app/app/actions/importfavs.ts +++ b/packages/app/app/actions/importfavs.ts @@ -4,6 +4,7 @@ import { rest, store } from '@nuclear/core'; import globals from '../globals'; import * as FavoritesActions from './favorites'; import { ImportFavs } from './actionTypes'; +import { ScrobblingState } from '../reducers/scrobbling'; const MAX_TRACKS_PER_PAGE = 1000; export function FavImportInit() { @@ -40,7 +41,7 @@ function FmSuccessFinal(count) { } export function fetchAllFmFavorites() { - const storage = store.get('lastFm'); + const storage = store.get('lastFm') as ScrobblingState; if (storage) { return async dispatch => { dispatch({ type: ImportFavs.LASTFM_FAV_IMPORT_START }); diff --git a/packages/app/app/actions/plugins.tsx b/packages/app/app/actions/plugins.tsx index 1a13344463..311c13608b 100644 --- a/packages/app/app/actions/plugins.tsx +++ b/packages/app/app/actions/plugins.tsx @@ -6,6 +6,7 @@ import UserPlugin from '../structs/userPlugin'; import { error } from './toasts'; import { createApi } from '@nuclear/core'; import { find, forEach, isNil } from 'lodash'; +import { PluginsState } from '../reducers/plugins'; export const CREATE_PLUGINS = 'CREATE_PLUGINS'; export const SELECT_STREAM_PROVIDER = 'SELECT_STREAM_PROVIDER'; @@ -158,7 +159,7 @@ export function serializePlugins(plugins) { export function deserializePlugins() { return dispatch => { - const plugins = store.get('plugins') || []; + const plugins = (store.get('plugins') || []) as PluginsState['userPlugins']; forEach(plugins, plugin => { dispatch(loadUserPlugin(plugin.path)); }); diff --git a/packages/app/app/actions/scrobbling.ts b/packages/app/app/actions/scrobbling.ts index 8283b727c4..8ce8577c8c 100644 --- a/packages/app/app/actions/scrobbling.ts +++ b/packages/app/app/actions/scrobbling.ts @@ -4,12 +4,13 @@ import { rest } from '@nuclear/core'; import { Scrobbling } from './actionTypes'; import globals from '../globals'; +import { ScrobblingState } from '../reducers/scrobbling'; const lastfm = new rest.LastFmApi(globals.lastfmApiKey, globals.lastfmApiSecret); export function lastFmReadSettings() { return dispatch => { - const settings = store.get('lastFm') || {}; + const settings = (store.get('lastFm') as ScrobblingState); if (settings) { dispatch({ type: Scrobbling.LASTFM_READ_SETTINGS, @@ -17,8 +18,7 @@ export function lastFmReadSettings() { lastFmName: settings.lastFmName, lastFmAuthToken: settings.lastFmAuthToken, lastFmSessionKey: settings.lastFmSessionKey, - lastFmScrobblingEnabled: settings.lastFmScrobblingEnabled, - lastFmFavImportStatus: settings.lastFmFavImportStatus + lastFmScrobblingEnabled: settings.lastFmScrobblingEnabled } }); } else { @@ -50,7 +50,7 @@ export function lastFmConnectAction() { }; } -export function lastFmLoginAction(authToken) { +export function lastFmLoginAction(authToken: string) { return dispatch => { dispatch({ type: 'FAV_IMPORT_INIT', diff --git a/packages/app/app/actions/toasts.ts b/packages/app/app/actions/toasts.ts index 335f872c63..93aa560233 100644 --- a/packages/app/app/actions/toasts.ts +++ b/packages/app/app/actions/toasts.ts @@ -53,7 +53,7 @@ function generateNotification(title: string, details: string, icon?: Node | Rea }, type))); - const timeout = get(settings, 'notificationTimeout') ?? 3; + const timeout = get(settings, 'notificationTimeout') as number ?? 3; setTimeout(() => dispatch(removeNotification(id)), timeout * 1000); }; } diff --git a/packages/app/app/components/PluginsView/UserPluginsSection/index.tsx b/packages/app/app/components/PluginsView/UserPluginsSection/index.tsx index ae6e3a0462..956f6475c8 100644 --- a/packages/app/app/components/PluginsView/UserPluginsSection/index.tsx +++ b/packages/app/app/components/PluginsView/UserPluginsSection/index.tsx @@ -16,8 +16,8 @@ type UserPlugin = { description: string; image: string | null; author: string; - loading: boolean; - error: boolean; + loading?: boolean; + error?: boolean; } type UserPluginsSectionProps = { diff --git a/packages/app/app/components/Settings/Integrations/LastFmSocialIntegration.tsx b/packages/app/app/components/Settings/Integrations/LastFmSocialIntegration.tsx index f20b753ac2..7f6ce549d8 100644 --- a/packages/app/app/components/Settings/Integrations/LastFmSocialIntegration.tsx +++ b/packages/app/app/components/Settings/Integrations/LastFmSocialIntegration.tsx @@ -16,7 +16,7 @@ type LastFmSocialIntegrationProps = { enableScrobbling: Function; disableScrobbling: Function; lastFmConnectAction: React.MouseEventHandler; - lastFmLoginAction: React.MouseEventHandler; + lastFmLoginAction: (authToken: string) => void; lastFmLogOut: React.MouseEventHandler; }; scrobbling: ReturnType; diff --git a/packages/app/app/components/Settings/index.tsx b/packages/app/app/components/Settings/index.tsx index 379ab2863c..14e1f00667 100644 --- a/packages/app/app/components/Settings/index.tsx +++ b/packages/app/app/components/Settings/index.tsx @@ -31,7 +31,7 @@ export type SettingsProps = { enableScrobbling: Function; disableScrobbling: Function; lastFmConnectAction: React.MouseEventHandler; - lastFmLoginAction: React.MouseEventHandler; + lastFmLoginAction: (authToken: string) => void; lastFmLogOut: React.MouseEventHandler; }; mastodonActions: { diff --git a/packages/app/app/reducers/plugins.ts b/packages/app/app/reducers/plugins.ts index d1f728f764..c6ba9aa213 100644 --- a/packages/app/app/reducers/plugins.ts +++ b/packages/app/app/reducers/plugins.ts @@ -19,6 +19,9 @@ type UserPlugin = { name: string; description: string; image: string; + author: string; + loading?: boolean; + error?: boolean; } type PluginKey = keyof typeof config.plugins; @@ -32,9 +35,7 @@ export type PluginsState = { selected: { [key in PluginKey]?: string; }; - userPlugins: { - [key: string]: UserPlugin; - }; + userPlugins: Record; } const initialState: PluginsState = { diff --git a/packages/app/app/reducers/scrobbling.ts b/packages/app/app/reducers/scrobbling.ts index 81add8b388..754b429160 100644 --- a/packages/app/app/reducers/scrobbling.ts +++ b/packages/app/app/reducers/scrobbling.ts @@ -1,13 +1,20 @@ import { Scrobbling } from '../actions/actionTypes'; -const initialState = { +export type ScrobblingState = { + lastFmName: string | null; + lastFmAuthToken: string | null; + lastFmSessionKey: string | null; + lastFmScrobblingEnabled: boolean; +}; + +const initialState: ScrobblingState = { lastFmName: null, lastFmAuthToken: null, lastFmSessionKey: null, lastFmScrobblingEnabled: false }; -export default function ScrobblingReducer(state=initialState, action) { +export default function ScrobblingReducer(state=initialState, action): ScrobblingState { switch (action.type) { case Scrobbling.LASTFM_CONNECT: return Object.assign({}, state, {