From 8f6a33e823b1e6376cf02355427ff6ebcfb7280a Mon Sep 17 00:00:00 2001 From: Thibault Reidy Date: Mon, 6 Nov 2023 10:51:37 +0100 Subject: [PATCH] feat: add Graasp platforms perfix helper function (graasp/graasp#672) --- src/constants/index.ts | 1 + src/constants/prefix.ts | 5 +++++ src/utils/shortLink.ts | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/constants/prefix.ts create mode 100644 src/utils/shortLink.ts diff --git a/src/constants/index.ts b/src/constants/index.ts index 3c73e5dc..aa49d8e4 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -11,3 +11,4 @@ export * from './mimeTypes'; export * from './permissionLevel'; export * from './ui'; export * from './triggers'; +export * from './prefix'; diff --git a/src/constants/prefix.ts b/src/constants/prefix.ts new file mode 100644 index 00000000..bd14bb0f --- /dev/null +++ b/src/constants/prefix.ts @@ -0,0 +1,5 @@ +// Graasp view (builder, player, library) constants +export const BUILDER_ITEMS_PREFIX = '/items'; +export const PLAYER_ITEMS_PREFIX = ''; +export const LIBRARY_ITEMS_PREFIX = '/collections'; +export const CLIENT_PREFIX = [BUILDER_ITEMS_PREFIX, PLAYER_ITEMS_PREFIX, LIBRARY_ITEMS_PREFIX]; \ No newline at end of file diff --git a/src/utils/shortLink.ts b/src/utils/shortLink.ts new file mode 100644 index 00000000..7e5031f1 --- /dev/null +++ b/src/utils/shortLink.ts @@ -0,0 +1,16 @@ +import { CLIENT_PREFIX, Context } from '@/constants'; + +export function getPlatformPrefix(shortLinkView: Context) { + const [BUILDER_PREFIX, PLAYER_PREFIX, LIBRARY_PREFIX] = CLIENT_PREFIX; + + switch (shortLinkView) { + case Context.Builder: + return BUILDER_PREFIX; + case Context.Library: + return LIBRARY_PREFIX; + case Context.Player: + return PLAYER_PREFIX; + default: + throw new Error(`The given context '${shortLinkView}' is not valid`); + } + } \ No newline at end of file