Skip to content

Commit

Permalink
feat(stories): add data download (#652)
Browse files Browse the repository at this point in the history
* feat(stories): support relative links
* feat(stories): add data download
* feat(stories): remove duplicate story assets getter
  • Loading branch information
pmast authored Sep 28, 2020
1 parent 9c7fbde commit 8827e1d
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {FunctionComponent} from 'react';
import ReactMarkdown from 'react-markdown';

import {getStoryMediaUrl} from '../../../libs/get-story-media-url';
import {getStoryAssetUrl} from '../../../libs/get-story-asset-urls';

import {Slide} from '../../../types/story';

Expand All @@ -13,7 +13,7 @@ interface Props {
}

const SplashScreen: FunctionComponent<Props> = ({storyId, slide}) => {
const imageUrl = slide.images && getStoryMediaUrl(storyId, slide.images[0]);
const imageUrl = slide.images && getStoryAssetUrl(storyId, slide.images[0]);

return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
font-size: emCalc(11px)
font-family: NotesEsa
line-height: normal

a
margin: 1em 0
color: $textColor
text-decoration: none

.shortTextContent
overflow-y: hidden
Expand Down
11 changes: 8 additions & 3 deletions src/scripts/components/stories/story-content/story-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {FunctionComponent} from 'react';
import ReactMarkdown from 'react-markdown';
import cx from 'classnames';

import {getStoryMediaUrl} from '../../../libs/get-story-media-url';
import {getStoryAssetUrl} from '../../../libs/get-story-asset-urls';
import {useSlide} from '../../../hooks/use-slide';

import {StoryMode} from '../../../types/story-mode';
Expand All @@ -27,13 +27,17 @@ const StoryContent: FunctionComponent<Props> = ({mode, slide, storyId}) => {
);

const transformImageUri = (originalSrc: string) =>
getStoryMediaUrl(storyId, originalSrc);
getStoryAssetUrl(storyId, originalSrc);

const transformLinkUri = (originalSrc: string) =>
getStoryAssetUrl(storyId, originalSrc);

return (
<div className={contentClasses}>
<ReactMarkdown
source={storyText}
transformImageUri={transformImageUri}
transformLinkUri={transformLinkUri}
linkTarget="_blank"
allowedTypes={[
'heading',
Expand All @@ -45,7 +49,8 @@ const StoryContent: FunctionComponent<Props> = ({mode, slide, storyId}) => {
'image',
'imageReference',
'list',
'listItem'
'listItem',
'link'
]}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {PreviousIcon} from '../../main/icons/previous-icon';
import {NextIcon} from '../../main/icons/next-icon';
import {FullscreenExitIcon} from '../../main/icons/fullscreen-exit-icon';
import {FullscreenIcon} from '../../main/icons/fullscreen-icon';
import {getStoryMediaUrl} from '../../../libs/get-story-media-url';
import {getStoryAssetUrl} from '../../../libs/get-story-asset-urls';
import {useInterval} from '../../../hooks/use-interval';
import config from '../../../config/main';

Expand Down Expand Up @@ -90,7 +90,7 @@ const StoryMedia: FunctionComponent<Props> = ({
}}>
{images.map((image, index) => {
const imageCaption = imageCaptions?.find((_, i) => i === index);
const imageUrl = getStoryMediaUrl(storyId, image);
const imageUrl = getStoryAssetUrl(storyId, image);

return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cx from 'classnames';
import StoryTags from '../story-tags/story-tags';
import {replaceUrlPlaceholders} from '../../../libs/replace-url-placeholders';
import {DownloadButton} from '../../main/download-button/download-button';
import {getStoryMediaUrl} from '../../../libs/get-story-media-url';
import {getStoryAssetUrl} from '../../../libs/get-story-asset-urls';
import config from '../../../config/main';

import {StoryListItem as StoryListItemType} from '../../../types/story-list';
Expand Down Expand Up @@ -37,7 +37,7 @@ const StoryListItemContent: FunctionComponent<Props> = ({
id: story.id
});
const downloadId = `story-${story.id}`;
const imageUrl = getStoryMediaUrl(story.id, story.image);
const imageUrl = getStoryAssetUrl(story.id, story.image);

return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import {
isElectron,
isOffline,
getOfflineStoryMediaUrl
} from '../libs/electron/index';
import {replaceUrlPlaceholders} from '../libs/replace-url-placeholders';
} from './electron/index';
import {replaceUrlPlaceholders} from './replace-url-placeholders';
import config from '../config/main';

export function getStoryMediaUrl(
export function getStoryAssetUrl(
storyId: string,
relativePath: string
path: string
): string {
if (path.startsWith('http')) {
return path;
}

let baseUrl = replaceUrlPlaceholders(config.api.storyMediaBase, {
id: storyId
});
Expand All @@ -18,5 +22,5 @@ export function getStoryMediaUrl(
baseUrl = replaceUrlPlaceholders(getOfflineStoryMediaUrl(), {id: storyId});
}

return `${baseUrl}/${relativePath}`;
return `${baseUrl}/${path}`;
}
Loading

0 comments on commit 8827e1d

Please sign in to comment.