-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(electron): add offline stories (#299)
- Loading branch information
Showing
15 changed files
with
150 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/scripts/components/download-button/download-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, {FunctionComponent} from 'react'; | ||
import {isElectron, downloadUrl, deleteId} from '../../libs/electron/index'; | ||
|
||
interface Props { | ||
url: string; | ||
id: string; | ||
} | ||
|
||
export const DownloadButton: FunctionComponent<Props> = ({url, id}) => { | ||
const onDownload = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
isElectron() && downloadUrl(url); | ||
}; | ||
|
||
if (!isElectron()) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div> | ||
<button onClick={onDownload}>Download</button> | ||
<button | ||
onClick={event => { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
deleteId(id); | ||
}}> | ||
Delete | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Returns the url template for offline usage | ||
export function getOfflineStoryMediaUrl(): string { | ||
if (!window.cfs) { | ||
console.error('Calling electron function from a non-electron environment'); | ||
return ''; | ||
} | ||
|
||
return window.cfs.getDownloadsPath('downloads', 'story-{id}'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
isElectron, | ||
isOffline, | ||
getOfflineStoryMediaUrl | ||
} from '../libs/electron/index'; | ||
import {replaceUrlPlaceholders} from '../libs/replace-url-placeholders'; | ||
import config from '../config/main'; | ||
|
||
export function getStoryMediaUrl( | ||
storyId: string, | ||
relativePath: string | ||
): string { | ||
let baseUrl = replaceUrlPlaceholders(config.api.storyMediaBase, { | ||
id: storyId | ||
}); | ||
|
||
if (isElectron() && isOffline()) { | ||
baseUrl = replaceUrlPlaceholders(getOfflineStoryMediaUrl(), {id: storyId}); | ||
} | ||
|
||
return `${baseUrl}/${relativePath}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.