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

fix: convert ItemType to const #312

Merged
merged 1 commit into from
Oct 26, 2023
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
22 changes: 11 additions & 11 deletions src/constants/itemType.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export enum ItemType {
APP = 'app',
DOCUMENT = 'document',
FOLDER = 'folder',
LINK = 'embeddedLink',
LOCAL_FILE = 'file',
S3_FILE = 's3File',
SHORTCUT = 'shortcut',
H5P = 'h5p',
ETHERPAD = 'etherpad',
}
export const ItemType = {
APP: 'app',
DOCUMENT: 'document',
FOLDER: 'folder',
LINK: 'embeddedLink',
LOCAL_FILE: 'file',
S3_FILE: 's3File',
SHORTCUT: 'shortcut',
H5P: 'h5p',
ETHERPAD: 'etherpad',
} as const;

export type FileItemType = typeof ItemType.S3_FILE | typeof ItemType.LOCAL_FILE;
18 changes: 9 additions & 9 deletions src/services/items/interfaces/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@ export interface Item<S = ItemSettings> {
}

export type AppItemType<S = ItemSettings> = {
type: `${ItemType.APP}`;
type: typeof ItemType.APP;
extra: AppItemExtra;
} & Item<S>;
export type DocumentItemType<S = ItemSettings> = {
type: `${ItemType.DOCUMENT}`;
type: typeof ItemType.DOCUMENT;
extra: DocumentItemExtra;
} & Item<S>;
export type FolderItemType<S = ItemSettings> = {
type: `${ItemType.FOLDER}`;
type: typeof ItemType.FOLDER;
extra: FolderItemExtra;
} & Item<S>;
export type H5PItemType<S = ItemSettings> = {
type: `${ItemType.H5P}`;
type: typeof ItemType.H5P;
extra: H5PItemExtra;
} & Item<S>;
export type EmbeddedLinkItemType<S = ItemSettings> = {
type: `${ItemType.LINK}`;
type: typeof ItemType.LINK;
extra: EmbeddedLinkItemExtra;
settings: EmbeddedLinkItemSettings;
} & Item<S>;
export type LocalFileItemType = {
type: `${ItemType.LOCAL_FILE}`;
type: typeof ItemType.LOCAL_FILE;
extra: LocalFileItemExtra;
} & Item<FileItemSettings>;
export type S3FileItemType = {
type: `${ItemType.S3_FILE}`;
type: typeof ItemType.S3_FILE;
extra: S3FileItemExtra;
} & Item<FileItemSettings>;
export type ShortcutItemType<S = ItemSettings> = {
type: `${ItemType.SHORTCUT}`;
type: typeof ItemType.SHORTCUT;
extra: ShortcutItemExtra;
} & Item<S>;
export type EtherpadItemType<S = ItemSettings> = {
type: `${ItemType.ETHERPAD}`;
type: typeof ItemType.ETHERPAD;
extra: EtherpadItemExtra;
} & Item<S>;

Expand Down
3 changes: 2 additions & 1 deletion src/services/search/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ItemType } from '@/constants';
import { UnionOfConst } from '@/types';

export const INDEX_NAME = 'itemIndex';

Expand All @@ -7,7 +8,7 @@ export type IndexItem = {
name: string;
creator: IndexMember;
description: string;
type: `${ItemType}`;
type: UnionOfConst<typeof ItemType>;
categories: string[];
content: string;
isPublishedRoot: boolean;
Expand Down
18 changes: 9 additions & 9 deletions src/utils/extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,55 @@ export const getFileExtra = <
U extends LocalFileItemExtra | ImmutableCast<LocalFileItemExtra>,
>(
extra: U,
): U[ItemType.LOCAL_FILE] => extra[ItemType.LOCAL_FILE];
): U[typeof ItemType.LOCAL_FILE] => extra[ItemType.LOCAL_FILE];

export const getFolderExtra = <
U extends FolderItemExtra | ImmutableCast<FolderItemExtra>,
>(
extra: U,
): U[ItemType.FOLDER] => extra[ItemType.FOLDER];
): U[typeof ItemType.FOLDER] => extra[ItemType.FOLDER];

export const getShortcutExtra = <
U extends ShortcutItemExtra | ImmutableCast<ShortcutItemExtra>,
>(
extra: U,
): U[ItemType.SHORTCUT] => extra[ItemType.SHORTCUT];
): U[typeof ItemType.SHORTCUT] => extra[ItemType.SHORTCUT];

export const getEtherpadExtra = <
U extends EtherpadItemExtra | ImmutableCast<EtherpadItemExtra>,
>(
extra: U,
): U[ItemType.ETHERPAD] => extra[ItemType.ETHERPAD];
): U[typeof ItemType.ETHERPAD] => extra[ItemType.ETHERPAD];

export const getS3FileExtra = <
U extends S3FileItemExtra | ImmutableCast<S3FileItemExtra>,
>(
extra: U,
): U[ItemType.S3_FILE] => extra[ItemType.S3_FILE];
): U[typeof ItemType.S3_FILE] => extra[ItemType.S3_FILE];

export const getEmbeddedLinkExtra = <
U extends EmbeddedLinkItemExtra | ImmutableCast<EmbeddedLinkItemExtra>,
>(
extra: U,
): U[ItemType.LINK] => extra[ItemType.LINK];
): U[typeof ItemType.LINK] => extra[ItemType.LINK];

export const getDocumentExtra = <
U extends DocumentItemExtra | ImmutableCast<DocumentItemExtra>,
>(
extra: U,
): U[ItemType.DOCUMENT] => extra[ItemType.DOCUMENT];
): U[typeof ItemType.DOCUMENT] => extra[ItemType.DOCUMENT];

export const getAppExtra = <
U extends AppItemExtra | ImmutableCast<AppItemExtra>,
>(
extra: U,
): U[ItemType.APP] => extra[ItemType.APP];
): U[typeof ItemType.APP] => extra[ItemType.APP];

export const getH5PExtra = <
U extends H5PItemExtra | ImmutableCast<H5PItemExtra>,
>(
extra: U,
): U[ItemType.H5P] => extra[ItemType.H5P];
): U[typeof ItemType.H5P] => extra[ItemType.H5P];

export const buildDocumentExtra = (
document: DocumentItemExtraProperties,
Expand Down
Loading