Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: functions over arrow fns #1264

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions src/utils/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { Constants } from '../constants';
import { getPlatformFromHostname } from '../helpers';
import type { AuthMethod, AuthResponse, AuthTokenResponse } from './types';

export const authGitHub = (
export function authGitHub(
authOptions = Constants.DEFAULT_AUTH_OPTIONS,
): Promise<AuthResponse> => {
): Promise<AuthResponse> {
return new Promise((resolve, reject) => {
// Build the OAuth consent page URL
const authWindow = new BrowserWindow({
Expand Down Expand Up @@ -83,12 +83,12 @@ export const authGitHub = (
handleCallback(url as Link);
});
});
};
}

export const getUserData = async (
export async function getUserData(
token: Token,
hostname: Hostname,
): Promise<GitifyUser> => {
): Promise<GitifyUser> {
const response: UserDetails = (await getAuthenticatedUser(hostname, token))
.data;

Expand All @@ -97,12 +97,12 @@ export const getUserData = async (
login: response.login,
name: response.name,
};
};
}

export const getToken = async (
export async function getToken(
authCode: AuthCode,
authOptions = Constants.DEFAULT_AUTH_OPTIONS,
): Promise<AuthTokenResponse> => {
): Promise<AuthTokenResponse> {
const url =
`https://${authOptions.hostname}/login/oauth/access_token` as Link;
const data = {
Expand All @@ -116,7 +116,7 @@ export const getToken = async (
hostname: authOptions.hostname,
token: response.data.access_token,
};
};
}

export function addAccount(
auth: AuthState,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { openNotification } from './links';
import { isWindows } from './platform';
import { getGitifySubjectDetails } from './subject';

export const setTrayIconColor = (notifications: AccountNotifications[]) => {
export function setTrayIconColor(notifications: AccountNotifications[]) {
const allNotificationsCount = getNotificationCount(notifications);

updateTrayIcon(allNotificationsCount);
};
}

export function getNotificationCount(notifications: AccountNotifications[]) {
return notifications.reduce(
Expand Down
6 changes: 3 additions & 3 deletions src/utils/remove-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { AccountNotifications, SettingsState } from '../types';
import type { Notification } from '../typesGitHub';
import { getAccountUUID } from './auth/utils';

export const removeNotification = (
export function removeNotification(
settings: SettingsState,
notification: Notification,
notifications: AccountNotifications[],
): AccountNotifications[] => {
): AccountNotifications[] {
if (settings.delayNotificationState) {
return notifications;
}
Expand All @@ -31,4 +31,4 @@ export const removeNotification = (
}

return notifications;
};
}
6 changes: 3 additions & 3 deletions src/utils/remove-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { AccountNotifications } from '../types';
import type { Notification } from '../typesGitHub';
import { getAccountUUID } from './auth/utils';

export const removeNotifications = (
export function removeNotifications(
notification: Notification,
notifications: AccountNotifications[],
): AccountNotifications[] => {
): AccountNotifications[] {
const repoSlug = notification.repository.full_name;

const accountIndex = notifications.findIndex(
Expand All @@ -26,4 +26,4 @@ export const removeNotifications = (
}

return notifications;
};
}
12 changes: 6 additions & 6 deletions src/utils/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export function getTheme(): Theme {
return Theme.LIGHT;
}

export const setLightMode = () => {
export function setLightMode() {
document.querySelector('html').classList.remove('dark');
};
}

export const setDarkMode = () => {
export function setDarkMode() {
document.querySelector('html').classList.add('dark');
};
}

export const setTheme = (mode?: Theme) => {
export function setTheme(mode?: Theme) {
switch (mode) {
case Theme.LIGHT:
setLightMode();
Expand All @@ -33,4 +33,4 @@ export const setTheme = (mode?: Theme) => {
setLightMode();
}
}
};
}