Skip to content

Commit

Permalink
(chore) Ban enums
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Aug 9, 2024
1 parent d73cfaf commit f74ff54
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export default [
"@typescript-eslint/no-empty-object-type": 0,
"@typescript-eslint/no-empty-interface": 0,
"react/jsx-curly-brace-presence": ["warn", "never"],
"no-restricted-syntax": [
"error",
{
selector: "TSEnumDeclaration",
message: "Don't declare enums",
},
],
eqeqeq: ["warn", "smart"],
"no-unreachable": ["warn"],

Expand Down
12 changes: 6 additions & 6 deletions src/features/comment/CommentHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ export default function CommentHeader({
return <Header>{content}</Header>;
}

enum StubType {
None,
Deleted,
ModRemoved,
}
const StubType = {
None: 0,
Deleted: 1,
ModRemoved: 2,
} as const;

export function isStubComment(
comment: Comment,
canModerate: ModeratorRole | undefined,
): StubType {
): (typeof StubType)[keyof typeof StubType] {
if (comment.deleted) return StubType.Deleted;

if (comment.removed && !canModerate) return StubType.ModRemoved;
Expand Down
14 changes: 8 additions & 6 deletions src/features/community/list/AlphabetJump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ const alphabetUpperCase = Array.from({ length: 26 }, (_, i) =>
String.fromCharCode(65 + i),
);

enum SpecialSection {
Home = 0,
Favorited = 1,
Moderated = 2,
}
const SpecialSection = {
Home: 0,
Favorited: 1,
Moderated: 2,
} as const;

type SpecialSectionType = (typeof SpecialSection)[keyof typeof SpecialSection];

type JumpItem = SpecialSection | string;
type JumpItem = SpecialSectionType | string;

const SECTIONS = [
<IonIcon icon={menuOutline} key={0} />,
Expand Down
4 changes: 2 additions & 2 deletions src/features/moderation/ModeratableItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ModeratableItemBanner, {
ItemModState,
ItemModStateType,
useItemModState,
getModStateBackgroundColor,
} from "./banner/ModeratableItemBanner";
Expand All @@ -11,7 +11,7 @@ import { styled } from "@linaria/react";
import { isPost } from "../../helpers/lemmy";

const ModeratableItemContainer = styled.div<{
modState?: ItemModState;
modState?: ItemModStateType;
highlighted?: boolean;
}>`
width: 100%;
Expand Down
26 changes: 14 additions & 12 deletions src/features/moderation/banner/ModeratableItemBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ import ReportBanner from "./ReportBanner";
import { maxWidthCss } from "../../shared/AppContent";
import { styled } from "@linaria/react";

export const ItemModState = {
None: 0,
Flagged: 1,
RemovedByMod: 2,
} as const;

export type ItemModStateType = (typeof ItemModState)[keyof typeof ItemModState];

export const Banner = styled.div<{
modState: ItemModState.Flagged | ItemModState.RemovedByMod;
modState: typeof ItemModState.Flagged | typeof ItemModState.RemovedByMod;
}>`
${maxWidthCss}
Expand All @@ -31,7 +39,7 @@ export const Banner = styled.div<{
`;

interface RemovedByBannerProps {
modState: ItemModState;
modState: ItemModStateType;
itemView: CommentView | PostView;
}

Expand All @@ -49,13 +57,7 @@ export default function ModeratableItemBanner({
}
}

export enum ItemModState {
None,
Flagged,
RemovedByMod,
}

export function useItemModState(item: Comment | Post): ItemModState {
export function useItemModState(item: Comment | Post): ItemModStateType {
const hasPostReports = useAppSelector(
(state) => !!reportsByPostIdSelector(state)[item.id]?.length,
);
Expand All @@ -75,7 +77,7 @@ export function useItemModState(item: Comment | Post): ItemModState {
}

export function getModStateBackgroundColor(
modState: ItemModState,
modState: ItemModStateType,
): string | undefined {
switch (modState) {
case ItemModState.Flagged:
Expand All @@ -88,7 +90,7 @@ export function getModStateBackgroundColor(
}

export function getModStateBannerBgColor(
modState: ItemModState,
modState: ItemModStateType,
): string | undefined {
switch (modState) {
case ItemModState.Flagged:
Expand All @@ -101,7 +103,7 @@ export function getModStateBannerBgColor(
}

export function getModStateBannerColor(
modState: ItemModState,
modState: ItemModStateType,
): string | undefined {
switch (modState) {
case ItemModState.Flagged:
Expand Down

0 comments on commit f74ff54

Please sign in to comment.