Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/api/TraktScrobble.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TraktItem } from '../models/TraktItem';
import { EventDispatcher, Events } from '../services/Events';
import { EventDispatcher } from '../services/Events';
import { Messaging } from '../services/Messaging';
import { Requests } from '../services/Requests';
import { RequestException, Requests } from '../services/Requests';
import { Shared } from '../services/Shared';
import { TraktApi } from './TraktApi';

Expand Down Expand Up @@ -81,12 +81,12 @@ class _TraktScrobble extends TraktApi {
method: 'POST',
body: data,
});
await EventDispatcher.dispatch(Events.SCROBBLE_SUCCESS, null, { item, scrobbleType });
await EventDispatcher.dispatch('SCROBBLE_SUCCESS', null, { item, scrobbleType });
} catch (err) {
await EventDispatcher.dispatch(Events.SCROBBLE_ERROR, null, {
await EventDispatcher.dispatch('SCROBBLE_ERROR', null, {
item,
scrobbleType,
error: err as Error,
error: err as RequestException,
});
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/api/TraktSearch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Item } from '../models/Item';
import { TraktItem } from '../models/TraktItem';
import { EventDispatcher, Events } from '../services/Events';
import { EventDispatcher } from '../services/Events';
import { Requests } from '../services/Requests';
import { TraktApi } from './TraktApi';

Expand Down Expand Up @@ -95,9 +95,9 @@ class _TraktSearch extends TraktApi {
year,
});
}
await EventDispatcher.dispatch(Events.SEARCH_SUCCESS, null, { searchItem });
await EventDispatcher.dispatch('SEARCH_SUCCESS', null, { searchItem });
} catch (err) {
await EventDispatcher.dispatch(Events.SEARCH_ERROR, null, { error: err as Error });
await EventDispatcher.dispatch('SEARCH_ERROR', null, { error: err as Error });
}
return traktItem;
};
Expand Down
6 changes: 3 additions & 3 deletions src/api/TraktSync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as moment from 'moment';
import { Item } from '../models/Item';
import { Errors } from '../services/Errors';
import { EventDispatcher, Events } from '../services/Events';
import { EventDispatcher } from '../services/Events';
import { Requests } from '../services/Requests';
import { TraktApi } from './TraktApi';

Expand Down Expand Up @@ -94,12 +94,12 @@ class _TraktSync extends TraktApi {
}
}
}
await EventDispatcher.dispatch(Events.HISTORY_SYNC_SUCCESS, null, {
await EventDispatcher.dispatch('HISTORY_SYNC_SUCCESS', null, {
added: responseJson.added,
});
} catch (err) {
Errors.error('Failed to sync history.', err);
await EventDispatcher.dispatch(Events.HISTORY_SYNC_ERROR, null, { error: err as Error });
await EventDispatcher.dispatch('HISTORY_SYNC_ERROR', null, { error: err as Error });
}
};
}
Expand Down
17 changes: 5 additions & 12 deletions src/components/UtsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ import {
} from '@material-ui/core';
import * as React from 'react';
import { useEffect, useState } from 'react';
import { EventDispatcher, Events } from '../services/Events';
import { EventDispatcher, DialogShowData } from '../services/Events';

interface DialogData {
title: string;
message: string;
onConfirm?: () => void;
onDeny?: () => void;
}

interface DialogState extends DialogData {
interface DialogState extends DialogShowData {
isOpen: boolean;
}

Expand All @@ -41,14 +34,14 @@ export const UtsDialog: React.FC = () => {

useEffect(() => {
const startListeners = () => {
EventDispatcher.subscribe(Events.DIALOG_SHOW, null, showDialog);
EventDispatcher.subscribe('DIALOG_SHOW', null, showDialog);
};

const stopListeners = () => {
EventDispatcher.unsubscribe(Events.DIALOG_SHOW, null, showDialog);
EventDispatcher.unsubscribe('DIALOG_SHOW', null, showDialog);
};

const showDialog = (data: DialogData) => {
const showDialog = (data: DialogShowData) => {
setDialog({
isOpen: true,
title: data.title,
Expand Down
14 changes: 4 additions & 10 deletions src/components/UtsSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import { Snackbar } from '@material-ui/core';
import { Alert, Color } from '@material-ui/lab';
import * as React from 'react';
import { useEffect, useState } from 'react';
import { EventDispatcher, Events } from '../services/Events';

interface SnackbarData {
messageName: string;
messageArgs: string[];
severity: Color;
}
import { EventDispatcher, SnackbarShowData } from '../services/Events';

interface SnackBarState {
isOpen: boolean;
Expand All @@ -32,14 +26,14 @@ export const UtsSnackbar: React.FC = () => {

useEffect(() => {
const startListeners = () => {
EventDispatcher.subscribe(Events.SNACKBAR_SHOW, null, showSnackbar);
EventDispatcher.subscribe('SNACKBAR_SHOW', null, showSnackbar);
};

const stopListeners = () => {
EventDispatcher.unsubscribe(Events.SNACKBAR_SHOW, null, showSnackbar);
EventDispatcher.unsubscribe('SNACKBAR_SHOW', null, showSnackbar);
};

const showSnackbar = (data: SnackbarData) => {
const showSnackbar = (data: SnackbarShowData) => {
setSnackbar({
isOpen: true,
message: browser.i18n.getMessage(data.messageName, data.messageArgs || []),
Expand Down
12 changes: 6 additions & 6 deletions src/components/WrongItemDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as React from 'react';
import { Item } from '../models/Item';
import { BrowserStorage } from '../services/BrowserStorage';
import { Errors } from '../services/Errors';
import { EventDispatcher, Events, WrongItemDialogData } from '../services/Events';
import { EventDispatcher, WrongItemDialogShowData } from '../services/Events';
import { StreamingServiceId, streamingServices } from '../streaming-services/streaming-services';
import { UtsCenter } from './UtsCenter';

Expand Down Expand Up @@ -68,13 +68,13 @@ export const WrongItemDialog: React.FC = () => {
}
correctUrls[dialog.serviceId][dialog.item.id] = url;
await BrowserStorage.set({ correctUrls }, true);
await EventDispatcher.dispatch(Events.WRONG_ITEM_CORRECTED, dialog.serviceId, {
await EventDispatcher.dispatch('WRONG_ITEM_CORRECTED', dialog.serviceId, {
item: dialog.item,
url,
});
} catch (err) {
Errors.error('Failed to correct item.', err);
await EventDispatcher.dispatch(Events.SNACKBAR_SHOW, null, {
await EventDispatcher.dispatch('SNACKBAR_SHOW', null, {
messageName: 'correctWrongItemFailed',
severity: 'error',
});
Expand Down Expand Up @@ -104,14 +104,14 @@ export const WrongItemDialog: React.FC = () => {

React.useEffect(() => {
const startListeners = () => {
EventDispatcher.subscribe(Events.WRONG_ITEM_DIALOG_SHOW, null, openDialog);
EventDispatcher.subscribe('WRONG_ITEM_DIALOG_SHOW', null, openDialog);
};

const stopListeners = () => {
EventDispatcher.unsubscribe(Events.WRONG_ITEM_DIALOG_SHOW, null, openDialog);
EventDispatcher.unsubscribe('WRONG_ITEM_DIALOG_SHOW', null, openDialog);
};

const openDialog = (data: WrongItemDialogData) => {
const openDialog = (data: WrongItemDialogShowData) => {
setDialog({
isOpen: true,
isLoading: false,
Expand Down
10 changes: 5 additions & 5 deletions src/modules/history/HistoryApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Redirect, Route, Router, Switch } from 'react-router-dom';
import { ErrorBoundary } from '../../components/ErrorBoundary';
import { UtsDialog } from '../../components/UtsDialog';
import { UtsSnackbar } from '../../components/UtsSnackbar';
import { EventDispatcher, Events } from '../../services/Events';
import { EventDispatcher } from '../../services/Events';
import { Session } from '../../services/Session';
import { HistoryHeader } from './components/HistoryHeader';
import { AboutPage } from './pages/AboutPage';
Expand All @@ -21,13 +21,13 @@ export const HistoryApp: React.FC = () => {

useEffect(() => {
const startListeners = () => {
EventDispatcher.subscribe(Events.LOGIN_SUCCESS, null, onLogin);
EventDispatcher.subscribe(Events.LOGOUT_SUCCESS, null, onLogout);
EventDispatcher.subscribe('LOGIN_SUCCESS', null, onLogin);
EventDispatcher.subscribe('LOGOUT_SUCCESS', null, onLogout);
};

const stopListeners = () => {
EventDispatcher.unsubscribe(Events.LOGIN_SUCCESS, null, onLogin);
EventDispatcher.unsubscribe(Events.LOGOUT_SUCCESS, null, onLogout);
EventDispatcher.unsubscribe('LOGIN_SUCCESS', null, onLogin);
EventDispatcher.unsubscribe('LOGOUT_SUCCESS', null, onLogout);
};

const onLogin = () => {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/history/components/history/HistoryListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { green, red } from '@material-ui/core/colors';
import SyncIcon from '@material-ui/icons/Sync';
import * as React from 'react';
import { Item } from '../../../../models/Item';
import { EventDispatcher, Events } from '../../../../services/Events';
import { EventDispatcher } from '../../../../services/Events';
import { StreamingServiceId } from '../../../../streaming-services/streaming-services';
import { HistoryListItemCard } from './HistoryListItemCard';

Expand All @@ -18,14 +18,14 @@ export const HistoryListItem: React.FC<HistoryListItemProps> = (props: HistoryLi
const { dateFormat, item, serviceId, serviceName } = props;

const onCheckboxChange = async () => {
await EventDispatcher.dispatch(Events.STREAMING_SERVICE_HISTORY_CHANGE, null, {
await EventDispatcher.dispatch('STREAMING_SERVICE_HISTORY_CHANGE', null, {
index: item.index,
checked: !item.isSelected,
});
};

const openWrongItemDialog = async () => {
await EventDispatcher.dispatch(Events.WRONG_ITEM_DIALOG_SHOW, null, {
await EventDispatcher.dispatch('WRONG_ITEM_DIALOG_SHOW', null, {
serviceId,
item,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { FormControlLabel, Switch, TextField } from '@material-ui/core';
import * as React from 'react';
import { SyncOption } from '../../../../services/BrowserStorage';
import { EventDispatcher, Events } from '../../../../services/Events';
import { EventDispatcher } from '../../../../services/Events';

interface HistoryOptionsListItemProps {
option: SyncOption;
}

export const HistoryOptionsListItem: React.FC<HistoryOptionsListItemProps> = ({ option }) => {
const onSwitchChange = async (): Promise<void> => {
await EventDispatcher.dispatch(Events.HISTORY_OPTIONS_CHANGE, null, {
await EventDispatcher.dispatch('HISTORY_OPTIONS_CHANGE', null, {
id: option.id,
value: !option.value,
});
};

const onNumberInputChange = async (event: React.ChangeEvent<HTMLInputElement>): Promise<void> => {
await EventDispatcher.dispatch(Events.HISTORY_OPTIONS_CHANGE, null, {
await EventDispatcher.dispatch('HISTORY_OPTIONS_CHANGE', null, {
id: option.id,
value: parseInt(event.currentTarget.value),
});
Expand Down
10 changes: 5 additions & 5 deletions src/modules/history/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { UtsCenter } from '../../../components/UtsCenter';
import { EventDispatcher, Events } from '../../../services/Events';
import { EventDispatcher } from '../../../services/Events';
import { Session } from '../../../services/Session';

export const LoginPage: React.FC = () => {
Expand All @@ -17,13 +17,13 @@ export const LoginPage: React.FC = () => {

useEffect(() => {
const startListeners = () => {
EventDispatcher.subscribe(Events.LOGIN_SUCCESS, null, onLoginSuccess);
EventDispatcher.subscribe(Events.LOGIN_ERROR, null, onLoginError);
EventDispatcher.subscribe('LOGIN_SUCCESS', null, onLoginSuccess);
EventDispatcher.subscribe('LOGIN_ERROR', null, onLoginError);
};

const stopListeners = () => {
EventDispatcher.unsubscribe(Events.LOGIN_SUCCESS, null, onLoginSuccess);
EventDispatcher.unsubscribe(Events.LOGIN_ERROR, null, onLoginError);
EventDispatcher.unsubscribe('LOGIN_SUCCESS', null, onLoginSuccess);
EventDispatcher.unsubscribe('LOGIN_ERROR', null, onLoginError);
};

const onLoginSuccess = () => {
Expand Down
29 changes: 14 additions & 15 deletions src/modules/options/OptionsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
import { Errors } from '../../services/Errors';
import {
EventDispatcher,
Events,
OptionEventData,
StreamingServiceOptionEventData,
OptionsChangeData,
StreamingServiceOptionsChangeData,
} from '../../services/Events';
import { StreamingServiceId, streamingServices } from '../../streaming-services/streaming-services';
import { OptionsActions } from './components/OptionsActions';
Expand All @@ -43,26 +42,26 @@ export const OptionsApp: React.FC = () => {

useEffect(() => {
const startListeners = () => {
EventDispatcher.subscribe(Events.OPTIONS_CLEAR, null, resetOptions);
EventDispatcher.subscribe(Events.OPTIONS_CHANGE, null, onOptionChange);
EventDispatcher.subscribe('OPTIONS_CLEAR', null, resetOptions);
EventDispatcher.subscribe('OPTIONS_CHANGE', null, onOptionChange);
EventDispatcher.subscribe(
Events.STREAMING_SERVICE_OPTIONS_CHANGE,
'STREAMING_SERVICE_OPTIONS_CHANGE',
null,
onStreamingServiceOptionChange
);
};

const stopListeners = () => {
EventDispatcher.unsubscribe(Events.OPTIONS_CLEAR, null, resetOptions);
EventDispatcher.unsubscribe(Events.OPTIONS_CHANGE, null, onOptionChange);
EventDispatcher.unsubscribe('OPTIONS_CLEAR', null, resetOptions);
EventDispatcher.unsubscribe('OPTIONS_CHANGE', null, onOptionChange);
EventDispatcher.unsubscribe(
Events.STREAMING_SERVICE_OPTIONS_CHANGE,
'STREAMING_SERVICE_OPTIONS_CHANGE',
null,
onStreamingServiceOptionChange
);
};

const onOptionChange = (data: OptionEventData<keyof StorageValuesOptions>) => {
const onOptionChange = (data: OptionsChangeData<keyof StorageValuesOptions>) => {
const optionsToSave = {} as StorageValuesOptions;
const options = {
...content.options,
Expand Down Expand Up @@ -98,7 +97,7 @@ export const OptionsApp: React.FC = () => {
})
.catch(async (err) => {
Errors.error('Failed to save option.', err);
await EventDispatcher.dispatch(Events.SNACKBAR_SHOW, null, {
await EventDispatcher.dispatch('SNACKBAR_SHOW', null, {
messageName: 'saveOptionFailed',
severity: 'error',
});
Expand All @@ -109,7 +108,7 @@ export const OptionsApp: React.FC = () => {
};

const onStreamingServiceOptionChange = (
data: StreamingServiceOptionEventData<StreamingServiceId>
data: StreamingServiceOptionsChangeData<StreamingServiceId>
) => {
const optionsToSave = {} as StorageValuesOptions;
const options = {
Expand Down Expand Up @@ -161,7 +160,7 @@ export const OptionsApp: React.FC = () => {
})
.catch(async (err) => {
Errors.error('Failed to save option.', err);
await EventDispatcher.dispatch(Events.SNACKBAR_SHOW, null, {
await EventDispatcher.dispatch('SNACKBAR_SHOW', null, {
messageName: 'saveOptionFailed',
severity: 'error',
});
Expand All @@ -185,13 +184,13 @@ export const OptionsApp: React.FC = () => {
isLoading: false,
options,
});
await EventDispatcher.dispatch(Events.SNACKBAR_SHOW, null, {
await EventDispatcher.dispatch('SNACKBAR_SHOW', null, {
messageName: 'saveOptionSuccess',
severity: 'success',
});
} catch (err) {
Errors.error('Failed to save option.', err);
await EventDispatcher.dispatch(Events.SNACKBAR_SHOW, null, {
await EventDispatcher.dispatch('SNACKBAR_SHOW', null, {
messageName: 'saveOptionFailed',
severity: 'error',
});
Expand Down
Loading