Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

Refactor enums to constants with union types (#5773)

authored by yoginth.com and committed by

GitHub a5d9ccca c8432ca8

+29 -19
+2 -2
apps/web/src/hooks/useImageCropUpload.tsx
··· 4 4 import { 5 5 DEFAULT_AVATAR, 6 6 STATIC_IMAGES_URL, 7 - type TRANSFORMS 7 + type Transform 8 8 } from "@hey/data/constants"; 9 9 import { ERRORS } from "@hey/data/errors"; 10 10 import imageKit from "@hey/helpers/imageKit"; ··· 19 19 src: string; 20 20 setSrc: (src: string) => void; 21 21 aspect: number; 22 - transform: TRANSFORMS; 22 + transform: Transform; 23 23 label: "avatar" | "cover"; 24 24 } 25 25
+21 -15
packages/data/constants.ts
··· 57 57 export const MAX_IMAGE_UPLOAD = 8; 58 58 59 59 // Named transforms for ImageKit 60 - export enum TRANSFORMS { 61 - AVATAR_BIG = "tr:w-350,h-350", 62 - AVATAR_SMALL = "tr:w-100,h-100", 63 - AVATAR_TINY = "tr:w-50,h-50", 64 - EXPANDED_AVATAR = "tr:w-1000,h-1000", 65 - COVER = "tr:w-1350,h-350", 66 - ATTACHMENT = "tr:w-1000" 67 - } 60 + export const TRANSFORMS = { 61 + AVATAR_BIG: "tr:w-350,h-350", 62 + AVATAR_SMALL: "tr:w-100,h-100", 63 + AVATAR_TINY: "tr:w-50,h-50", 64 + EXPANDED_AVATAR: "tr:w-1000,h-1000", 65 + COVER: "tr:w-1350,h-350", 66 + ATTACHMENT: "tr:w-1000" 67 + } as const; 68 68 69 - export enum BANNER_IDS { 70 - PRO = "108325599858337195593675454288445399104045325554183036578573525280972584660299" 71 - } 69 + export type Transform = (typeof TRANSFORMS)[keyof typeof TRANSFORMS]; 72 70 73 - export enum PERMISSIONS { 74 - SUBSCRIPTION = "0x4BE5b4519814A57E6f9AaFC6afBB37eAEeE35aA3", 75 - STAFF = "0xA7f2835e54998c6d7d4A0126eC0ebE91b5E43c69" 76 - } 71 + export const BANNER_IDS = { 72 + PRO: "108325599858337195593675454288445399104045325554183036578573525280972584660299" 73 + } as const; 74 + 75 + export type BannerId = (typeof BANNER_IDS)[keyof typeof BANNER_IDS]; 76 + 77 + export const PERMISSIONS = { 78 + SUBSCRIPTION: "0x4BE5b4519814A57E6f9AaFC6afBB37eAEeE35aA3", 79 + STAFF: "0xA7f2835e54998c6d7d4A0126eC0ebE91b5E43c69" 80 + } as const; 81 + 82 + export type Permission = (typeof PERMISSIONS)[keyof typeof PERMISSIONS];
+6 -2
packages/helpers/getAvatar.ts
··· 1 - import { DEFAULT_AVATAR, TRANSFORMS } from "@hey/data/constants"; 1 + import { 2 + DEFAULT_AVATAR, 3 + TRANSFORMS, 4 + type Transform 5 + } from "@hey/data/constants"; 2 6 import imageKit from "./imageKit"; 3 7 import sanitizeDStorageUrl from "./sanitizeDStorageUrl"; 4 8 ··· 11 15 12 16 const getAvatar = ( 13 17 entity: EntityWithAvatar | null | undefined, 14 - namedTransform = TRANSFORMS.AVATAR_SMALL 18 + namedTransform: Transform = TRANSFORMS.AVATAR_SMALL 15 19 ): string => { 16 20 if (!entity) { 17 21 return DEFAULT_AVATAR;