2019-12-22 04:16:52 +01:00
import html from 'choo/html' ;
2019-12-24 00:39:03 +01:00
import { editModal } from './editModal' ;
2019-12-22 04:16:52 +01:00
2019-12-24 00:39:03 +01:00
export const userShelvesView = ( shelvesController , emit ) => {
2019-12-22 04:16:52 +01:00
const { _ _ } = shelvesController . i18n ;
if ( ! shelvesController . isLoggedIn ) {
return [
html ` <section>
< h2 > $ { _ _ ( 'shelves.no_shelf_selected' ) } < / h 2 >
< article class = "card" >
< header >
< p > $ { _ _ ( 'shelves.not_logged_in' ) } < / p >
< / h e a d e r >
< footer >
< button > $ { _ _ ( 'global.menu_login' ) } < / b u t t o n >
< / f o o t e r >
< / a r t i c l e >
< / s e c t i o n > ` ,
] ;
}
if ( shelvesController . state . myShelves . length <= 0 ) {
2019-12-24 00:51:26 +01:00
shelvesController . getUserShelves ( ) . then ( ( ) => {
2019-12-22 04:16:52 +01:00
emit ( 'render' ) ;
} ) ;
}
// Should add a scale of publicity: private, friends only, friends & followers, public
return [
html ` <section>
< h2 > $ { _ _ ( 'shelves.title' ) } < / h 2 >
2019-12-24 00:39:03 +01:00
$ { shelvesController . state . myShelves . map ( shelf => {
const deleteButton = html ` <button class="small pseudo">
$ { _ _ ( 'interaction.delete' ) } < i class = "icon-delete" > < / i >
< / b u t t o n > ` ;
2019-12-22 04:16:52 +01:00
return html ` <article class="card">
< header >
< h3 >
< a href = "/shelves?shelf=${shelf.id}" > $ { shelf . name } < / a >
< / h 3 >
$ { shelf . isDeletable === true
? [
2019-12-24 00:39:03 +01:00
editModal ( shelf , shelvesController ) ,
[ deleteButton ] , // editModal outputs a modal, which returns an array, so any subsequent html items must also be in an array for Choo to handle it correctly.
2019-12-22 04:16:52 +01:00
]
2019-12-24 00:39:03 +01:00
: null
}
2019-12-22 04:16:52 +01:00
< / h e a d e r >
< / a r t i c l e > ` ;
} ) }
< / s e c t i o n > ` ,
] ;
}