Skip to content

Commit

Permalink
Merge Redux actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Jan 23, 2024
1 parent ed05f08 commit 8181f7a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
17 changes: 7 additions & 10 deletions src/servers/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
WEBVIEW_SERVER_VERSION_UPDATED,
SUPPORTED_VERSION_DIALOG_DISMISS,
WEBVIEW_SIDEBAR_CUSTOM_THEME_CHANGED,
WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED,
} from '../ui/actions';
import { SERVERS_LOADED } from './actions';
import type { Server } from './common';
Expand Down Expand Up @@ -64,8 +63,7 @@ type ServersActionTypes =
| ActionOf<typeof WEBVIEW_SERVER_UNIQUE_ID_UPDATED>
| ActionOf<typeof WEBVIEW_SERVER_IS_SUPPORTED_VERSION>
| ActionOf<typeof WEBVIEW_SERVER_VERSION_UPDATED>
| ActionOf<typeof SUPPORTED_VERSION_DIALOG_DISMISS>
| ActionOf<typeof WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED>;
| ActionOf<typeof SUPPORTED_VERSION_DIALOG_DISMISS>;

const upsert = (state: Server[], server: Server): Server[] => {
const index = state.findIndex(({ url }) => url === server.url);
Expand Down Expand Up @@ -120,13 +118,12 @@ export const servers: Reducer<Server[], ServersActionTypes> = (
}

case WEBVIEW_SERVER_SUPPORTED_VERSIONS_UPDATED: {
const { url, supportedVersions } = action.payload;
return upsert(state, { url, supportedVersions });
}

case WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED: {
const { url, supportedVersionsSource } = action.payload;
return upsert(state, { url, supportedVersionsSource });
const { url, supportedVersions, source } = action.payload;
return upsert(state, {
url,
supportedVersions,
supportedVersionsSource: source,
});
}

case SUPPORTED_VERSION_DIALOG_DISMISS: {
Expand Down
10 changes: 1 addition & 9 deletions src/servers/supportedVersions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { dispatch, listen, select } from '../../store';
import {
WEBVIEW_SERVER_SUPPORTED_VERSIONS_UPDATED,
WEBVIEW_SERVER_VERSION_UPDATED,
WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED,
WEBVIEW_READY,
WEBVIEW_SERVER_UNIQUE_ID_UPDATED,
WEBVIEW_SERVER_RELOADED,
Expand Down Expand Up @@ -297,19 +296,12 @@ const dispatchSupportedVersionsUpdated = (
supportedVersions: SupportedVersions,
{ source }: { source: 'server' | 'cloud' | 'builtin' }
): void => {
dispatch({
type: WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED,
payload: {
url,
supportedVersionsSource: source,
},
});

dispatch({
type: WEBVIEW_SERVER_SUPPORTED_VERSIONS_UPDATED,
payload: {
url,
supportedVersions,
source,
},
});
};
Expand Down
7 changes: 1 addition & 6 deletions src/ui/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export const WEBVIEW_SERVER_UNIQUE_ID_UPDATED =
'webview/server-workspace-uid-updated';
export const WEBVIEW_SERVER_IS_SUPPORTED_VERSION =
'webview/server-is-supported-version';
export const WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED =
'webview/server-supported-versions-source-updated';
export const WEBVIEW_SERVER_VERSION_UPDATED = 'webview/version-updated';
export const SUPPORTED_VERSION_DIALOG_DISMISS =
'supported-versions-dialog/dismiss';
Expand Down Expand Up @@ -189,6 +187,7 @@ export type UiActionTypeToPayloadMap = {
[WEBVIEW_SERVER_SUPPORTED_VERSIONS_UPDATED]: {
url: Server['url'];
supportedVersions: Server['supportedVersions'];
source: Server['supportedVersionsSource'];
};
[WEBVIEW_SERVER_UNIQUE_ID_UPDATED]: {
url: Server['url'];
Expand All @@ -203,10 +202,6 @@ export type UiActionTypeToPayloadMap = {
version: Server['version'];
};
[SUPPORTED_VERSION_DIALOG_DISMISS]: { url: Server['url'] };
[WEBVIEW_SERVER_SUPPORTED_VERSIONS_SOURCE_UPDATED]: {
url: Server['url'];
supportedVersionsSource: Server['supportedVersionsSource'];
};
[WEBVIEW_SERVER_RELOADED]: {
url: Server['url'];
};
Expand Down

0 comments on commit 8181f7a

Please sign in to comment.