Skip to content

Commit

Permalink
feat: add Graasp platforms perfix helper function (graasp/graasp#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT committed Nov 6, 2023
1 parent 9408ef1 commit 8f6a33e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './mimeTypes';
export * from './permissionLevel';
export * from './ui';
export * from './triggers';
export * from './prefix';
5 changes: 5 additions & 0 deletions src/constants/prefix.ts
Original file line number Diff line number Diff line change
@@ -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];
16 changes: 16 additions & 0 deletions src/utils/shortLink.ts
Original file line number Diff line number Diff line change
@@ -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`);
}
}

0 comments on commit 8f6a33e

Please sign in to comment.