73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
|
|
export type StoryShareMeta = {
|
||
|
|
instanceId?: string;
|
||
|
|
publicShareId?: string;
|
||
|
|
shareId?: string;
|
||
|
|
shareConfigured?: boolean;
|
||
|
|
sharePublished?: boolean;
|
||
|
|
};
|
||
|
|
|
||
|
|
export type StoryShareState = 'public' | 'draft' | 'preview';
|
||
|
|
|
||
|
|
export const getStoryPublicShareId = (story?: StoryShareMeta) =>
|
||
|
|
story?.publicShareId || story?.shareId;
|
||
|
|
|
||
|
|
export const getStoryShareState = (story?: StoryShareMeta): StoryShareState => {
|
||
|
|
const publicShareId = getStoryPublicShareId(story);
|
||
|
|
|
||
|
|
if (story?.sharePublished || publicShareId) {
|
||
|
|
return 'public';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (story?.shareConfigured) {
|
||
|
|
return 'draft';
|
||
|
|
}
|
||
|
|
|
||
|
|
return 'preview';
|
||
|
|
};
|
||
|
|
|
||
|
|
export const getStoryShareStatusText = (story?: StoryShareMeta) => {
|
||
|
|
switch (getStoryShareState(story)) {
|
||
|
|
case 'public':
|
||
|
|
return 'Public share is live';
|
||
|
|
case 'draft':
|
||
|
|
return 'Share draft is ready';
|
||
|
|
default:
|
||
|
|
return 'Preview available';
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
export const getStoryShareActionLabel = (story?: StoryShareMeta) => {
|
||
|
|
switch (getStoryShareState(story)) {
|
||
|
|
case 'public':
|
||
|
|
return 'Copy Link';
|
||
|
|
case 'draft':
|
||
|
|
return 'Draft Preview';
|
||
|
|
default:
|
||
|
|
return 'Preview';
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
export const getStoryShareMenuLabel = (story?: StoryShareMeta) => {
|
||
|
|
switch (getStoryShareState(story)) {
|
||
|
|
case 'public':
|
||
|
|
return 'Copy share link';
|
||
|
|
case 'draft':
|
||
|
|
return 'Open draft preview';
|
||
|
|
default:
|
||
|
|
return 'Open preview';
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
export const getStorySharePath = (story?: StoryShareMeta) => {
|
||
|
|
const publicShareId = getStoryPublicShareId(story);
|
||
|
|
if (publicShareId) {
|
||
|
|
return `/share/${publicShareId}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (story?.instanceId) {
|
||
|
|
return `/share/preview/${story.instanceId}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
return undefined;
|
||
|
|
};
|