forked from cozy/cozy-drive
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cozy#91 from goldoraf/master
Shared album public page
- Loading branch information
Showing
22 changed files
with
454 additions
and
392 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './photos' | ||
export * from './selection' |
This file was deleted.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,54 @@ | ||
/* global cozy */ | ||
import React, { Component } from 'react' | ||
|
||
// Extreme fallback: returns a direct download link to the raw image | ||
const getPhotoLink = async (photoId) => { | ||
return await cozy.client.files.getDownloadLinkById(photoId) | ||
.then(path => `${cozy.client._url}${path}`) | ||
} | ||
|
||
export default class ImageLoader extends Component { | ||
state = { | ||
loading: true, | ||
fallback: null | ||
} | ||
|
||
onLoad = () => { | ||
this.setState({ loading: false }) | ||
if (this.props.onLoad) this.props.onLoad() | ||
} | ||
|
||
onError = () => { | ||
if (!this.img) return // if we already unmounted | ||
if (this.state.fallback && this.img.src === this.state.fallback) return | ||
// extreme fallback | ||
getPhotoLink(this.props.photo._id) | ||
.then(url => { | ||
this.img.src = url | ||
this.setState({ loading: false, fallback: url }) | ||
if (this.props.onLoad) this.props.onLoad() | ||
}) | ||
} | ||
|
||
componentWillUnmount () { | ||
// this is needed because when opening 2 times in a row the same photo in the viewer, | ||
// the second time the onLoad is not fired... This will fire the onError (see above) | ||
this.img.src = '' | ||
} | ||
|
||
render () { | ||
const { photo, src, alt, className, style = {} } = this.props | ||
const { loading } = this.state | ||
return ( | ||
<img | ||
ref={img => { this.img = img }} | ||
className={className} | ||
onLoad={this.onLoad} | ||
onError={this.onError} | ||
style={Object.assign({}, style, loading === true ? { display: 'none' } : {})} | ||
alt={alt || photo.name} | ||
src={src} | ||
/> | ||
) | ||
} | ||
} |
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.