Skip to content

Commit

Permalink
refactor: Refresh supported versions whenever the app goes online (#2820
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tassoevan committed Jan 30, 2024
1 parent 4b4f2ee commit 5cea4d8
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 166 deletions.
9 changes: 5 additions & 4 deletions src/outlookCalendar/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { selectPersistableValues } from '../app/selectors';
import { handle } from '../ipc/main';
import type { Server } from '../servers/common';
import { dispatch, request, select } from '../store';
import * as urls from '../urls';
import {
OUTLOOK_CALENDAR_SET_CREDENTIALS,
OUTLOOK_CALENDAR_ASK_CREDENTIALS,
Expand Down Expand Up @@ -70,7 +71,7 @@ async function listEventsFromRocketChatServer(
) {
try {
const response = await axios.get(
`${serverUrl}api/v1/calendar-events.list`,
urls.server(serverUrl).calendarEvents.list,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -96,7 +97,7 @@ async function createEventOnRocketChatServer(
) {
try {
await axios.post(
`${serverUrl}api/v1/calendar-events.import`,
urls.server(serverUrl).calendarEvents.import,
{
externalId: event.id,
subject: event.subject,
Expand Down Expand Up @@ -126,7 +127,7 @@ async function updateEventOnRocketChatServer(
) {
try {
await axios.post(
`${serverUrl}api/v1/calendar-events.update`,
urls.server(serverUrl).calendarEvents.update,
{
eventId: rocketChatEventId,
subject: event.subject,
Expand Down Expand Up @@ -155,7 +156,7 @@ async function deleteEventOnRocketChatServer(
) {
try {
await axios.post(
`${serverUrl}api/v1/calendar-events.delete`,
urls.server(serverUrl).calendarEvents.delete,
{
eventId: rocketChatEventId,
},
Expand Down
3 changes: 2 additions & 1 deletion src/servers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '../ui/actions';
import { getRootWindow } from '../ui/main/rootWindow';
import { getWebContentsByServerUrl } from '../ui/main/serverView';
import * as urls from '../urls';
import {
SERVER_URL_RESOLUTION_REQUESTED,
SERVER_URL_RESOLVED,
Expand Down Expand Up @@ -84,7 +85,7 @@ export const resolveServerUrl = async (
if (
!/(^https?:\/\/)|(\.)|(^([^:]+:[^@]+@)?localhost(:\d+)?$)/.test(input)
) {
return resolveServerUrl(`https://${input}.rocket.chat`);
return resolveServerUrl(urls.rocketchat.subdomain(input));
}

if (error?.name === 'AbortError') {
Expand Down
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

0 comments on commit 5cea4d8

Please sign in to comment.