This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
forked from mozilla/send
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converting some things to choo/component
- Loading branch information
1 parent
a576d54
commit 037c797
Showing
16 changed files
with
272 additions
and
383 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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
npm run build | ||
rm -rf src/main/assets | ||
mkdir -p src/main/assets | ||
cp -R ../../dist/* src/main/assets | ||
sed -i '' 's/url(/url(\/android_asset/g' src/main/assets/app.*.css |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,58 +1,101 @@ | ||
const html = require('choo/html'); | ||
const Component = require('choo/component'); | ||
|
||
module.exports = function(state, emit) { | ||
if (!state.capabilities.account) { | ||
return null; | ||
} | ||
const user = state.user; | ||
if (!user.loggedIn) { | ||
return html`<button | ||
class="p-2 border rounded border-white text-white hover:bg-white hover:text-blue md:text-blue md:border-blue md:hover:text-white md:hover:bg-blue" | ||
onclick=${login}> | ||
${state.translate('signInMenuOption')} | ||
</button>`; | ||
} | ||
return html`<div class="relative h-8"> | ||
<input | ||
type="image" | ||
alt="${user.email}" | ||
class="w-8 h-8 rounded-full text-white" | ||
src="${user.avatar}" | ||
onclick=${avatarClick}/> | ||
<ul | ||
id="accountMenu" | ||
class="invisible list-reset absolute pin-t pin-r mt-10 pt-2 pb-2 bg-white shadow-md whitespace-no-wrap outline-none z-50" | ||
onblur="${hideMenu}" | ||
tabindex="-1"> | ||
<li class="p-2 text-grey-dark">${user.email}</li> | ||
<li> | ||
<a class="block px-4 py-2 text-grey-darkest hover:bg-blue hover:text-white cursor-pointer" onclick=${logout}> | ||
${state.translate('logOut')} | ||
</a> | ||
</li> | ||
</ul> | ||
</div>`; | ||
|
||
function avatarClick(event) { | ||
class Account extends Component { | ||
constructor(name, state, emit) { | ||
super(name); | ||
this.state = state; | ||
this.emit = emit; | ||
this.enabled = state.capabilities.account; | ||
this.local = state.components[name] = {}; | ||
this.setState(); | ||
} | ||
|
||
avatarClick(event) { | ||
event.preventDefault(); | ||
const menu = document.getElementById('accountMenu'); | ||
menu.classList.toggle('invisible'); | ||
menu.focus(); | ||
} | ||
|
||
function hideMenu(event) { | ||
hideMenu(event) { | ||
event.stopPropagation(); | ||
const menu = document.getElementById('accountMenu'); | ||
menu.classList.add('invisible'); | ||
} | ||
|
||
function login(event) { | ||
login(event) { | ||
event.preventDefault(); | ||
emit('login'); | ||
this.emit('login'); | ||
} | ||
|
||
function logout(event) { | ||
logout(event) { | ||
event.preventDefault(); | ||
emit('logout'); | ||
this.emit('logout'); | ||
} | ||
|
||
changed() { | ||
return this.local.loggedIn !== this.state.user.loggedIn; | ||
} | ||
|
||
setState() { | ||
const changed = this.changed(); | ||
if (changed) { | ||
this.local.loggedIn = this.state.user.loggedIn; | ||
} | ||
return changed; | ||
} | ||
}; | ||
|
||
update() { | ||
return this.setState(); | ||
} | ||
|
||
createElement() { | ||
if (!this.enabled) { | ||
return null; | ||
} | ||
const user = this.state.user; | ||
const translate = this.state.translate; | ||
if (!this.local.loggedIn) { | ||
return html` | ||
<div> | ||
<button | ||
class="p-2 border rounded border-white text-white hover:bg-white hover:text-blue md:text-blue md:border-blue md:hover:text-white md:hover:bg-blue" | ||
onclick="${e => this.login(e)}" | ||
> | ||
${translate('signInMenuOption')} | ||
</button> | ||
</div> | ||
`; | ||
} | ||
return html` | ||
<div class="relative h-8"> | ||
<input | ||
type="image" | ||
alt="${user.email}" | ||
class="w-8 h-8 rounded-full text-white" | ||
src="${user.avatar}" | ||
onclick="${e => this.avatarClick(e)}" | ||
/> | ||
<ul | ||
id="accountMenu" | ||
class="invisible list-reset absolute pin-t pin-r mt-10 pt-2 pb-2 bg-white shadow-md whitespace-no-wrap outline-none z-50" | ||
onblur="${e => this.hideMenu(e)}" | ||
tabindex="-1" | ||
> | ||
<li class="p-2 text-grey-dark">${user.email}</li> | ||
<li> | ||
<a | ||
class="block px-4 py-2 text-grey-darkest hover:bg-blue hover:text-white cursor-pointer" | ||
onclick="${e => this.logout(e)}" | ||
> | ||
${translate('logOut')} | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
`; | ||
} | ||
} | ||
|
||
module.exports = Account; |
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,28 @@ | ||
const html = require('choo/html'); | ||
const Promo = require('./promo'); | ||
const Header = require('./header'); | ||
const Footer = require('./footer'); | ||
|
||
function banner(state) { | ||
if (state.promo && !state.route.startsWith('/unsupported/')) { | ||
return state.cache(Promo, 'promo').render(); | ||
} | ||
} | ||
|
||
module.exports = function body(main) { | ||
return function(state, emit) { | ||
const b = html` | ||
<body | ||
class="flex flex-col items-center font-sans bg-blue-lightest md:h-screen md:bg-grey-lightest" | ||
> | ||
${banner(state, emit)} ${state.cache(Header, 'header').render()} | ||
${main(state, emit)} ${state.cache(Footer, 'footer').render()} | ||
</body> | ||
`; | ||
if (state.layout) { | ||
// server side only | ||
return state.layout(state, b); | ||
} | ||
return b; | ||
}; | ||
}; |
Oops, something went wrong.