Skip to content

Commit

Permalink
Prepare structure for live demo banner
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslansavenok committed Dec 27, 2018
1 parent 0c95159 commit 2b9d163
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 2 additions & 3 deletions assets/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const githubRepo = 'ruslansavenok/app_version_check'
const config = merge(
{
repo: {
mixFileUrl: `https://api.github.com/repos/${githubRepo}/contents/mix.exs`,
changelogUrl: `https://github.com/${githubRepo}/blob/master/CHANGELOG.md`,
updateGuideUrl: 'https://github.com/10clouds/10Books/wiki/Update-guide'
name: githubRepo,
url: `https://github.com/${githubRepo}`
}
},
window.LibTen.config
Expand Down
15 changes: 11 additions & 4 deletions assets/js/react-components/containers/NewVersionAvailable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class NewVersionAvailableBanner extends Component {
if (cachedAppVersion) {
this.handleReady(cachedAppVersion)
} else {
fetch(config.get('repo.mixFileUrl'))
fetch(
`https://api.github.com/repos/${config.get(
'repo.name'
)}/contents/mix.exs`
)
.then(res => res.json())
.then(data => {
const fileContent = atob(data.content)
Expand Down Expand Up @@ -56,16 +60,19 @@ class NewVersionAvailableBanner extends Component {
const appVersion = config.get('appVersion')
const { isVisible, latestRepoVersion } = this.state

return isVisible ? (
return isVisible && latestRepoVersion !== appVersion ? (
<MessageOverlay onCancel={this.handleCancel}>
<h2>New version is available!</h2>
You're using version <b>{appVersion}</b>, while the newest one is{' '}
<b>{latestRepoVersion}</b> Check out our{' '}
<a href={config.get('repo.changelogUrl')} target="_blank">
<a
href={config.get('repo.url') + '/blob/master/CHANGELOG.md'}
target="_blank"
>
changelog
</a>{' '}
and follow{' '}
<a href={config.get('repo.updateGuideUrl')} target="_blank">
<a href={config.get('repo.url') + 'wiki/Update-guide'} target="_blank">
this guide
</a>{' '}
to update.
Expand Down
4 changes: 2 additions & 2 deletions lib/lib_ten_web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@
</nav>
<div class="navbar__height-compensator"></div>

<div id="new-version-banner"></div>
<div id="message-banner"></div>
<script>
window.LibTen.renderReactComponent('newVersionAvailable',
document.getElementById('new-version-banner')
document.getElementById('message-banner')
);
</script>

Expand Down

0 comments on commit 2b9d163

Please sign in to comment.