Skip to content

refactor: icons util with color enum #1042

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

Merged
merged 1 commit into from
Apr 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
4 changes: 2 additions & 2 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
import { AppContext } from '../context/App';
import type { Notification } from '../typesGithub';
import { openExternalLink } from '../utils/comms';
import { formatForDisplay, openInBrowser } from '../utils/helpers';
import {
getNotificationTypeIcon,
getNotificationTypeIconColor,
} from '../utils/github-api';
import { formatForDisplay, openInBrowser } from '../utils/helpers';
} from '../utils/icons';
import { formatReason } from '../utils/reason';

interface IProps {
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,10 @@ export interface FormattedReason {
title: string;
description: string;
}

export enum IconColor {
GREEN = 'text-green-500',
RED = 'text-red-500',
PURPLE = 'text-purple-500',
GRAY = 'text-gray-500 dark:text-gray-300',
}
31 changes: 0 additions & 31 deletions src/utils/__snapshots__/github-api.test.ts.snap

This file was deleted.

31 changes: 31 additions & 0 deletions src/utils/__snapshots__/icons.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions src/utils/github-api.test.ts → src/utils/icons.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { StateType, Subject, SubjectType } from '../typesGithub';
import {
getNotificationTypeIcon,
getNotificationTypeIconColor,
} from './github-api';
import { getNotificationTypeIcon, getNotificationTypeIconColor } from './icons';

describe('utils/github-api.ts', () => {
describe('utils/icons.ts', () => {
describe('getNotificationTypeIcon - should get the notification type icon', () => {
expect(
getNotificationTypeIcon(
Expand Down
11 changes: 6 additions & 5 deletions src/utils/github-api.ts → src/utils/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
XIcon,
} from '@primer/octicons-react';
import type { FC } from 'react';
import { IconColor } from '../types';
import type { Subject } from '../typesGithub';

export function getNotificationTypeIcon(subject: Subject): FC<OcticonProps> {
Expand Down Expand Up @@ -92,21 +93,21 @@ export function getNotificationTypeIcon(subject: Subject): FC<OcticonProps> {
}
}

export function getNotificationTypeIconColor(subject: Subject): string {
export function getNotificationTypeIconColor(subject: Subject): IconColor {
switch (subject.state) {
case 'open':
case 'reopened':
case 'ANSWERED':
case 'success':
return 'text-green-500';
return IconColor.GREEN;
case 'closed':
case 'failure':
return 'text-red-500';
return IconColor.RED;
case 'completed':
case 'RESOLVED':
case 'merged':
return 'text-purple-500';
return IconColor.PURPLE;
default:
return 'text-gray-500 dark:text-gray-300';
return IconColor.GRAY;
}
}