Manage how selection changes the appbar
This commit is contained in:
parent
8006e98dbc
commit
f62eb6da64
@ -23,12 +23,15 @@ export function uploadImages(evt, files) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AllImagesView(vm, params, key, opts) {
|
export function AllImagesView(vm, params, key, { appbar }) {
|
||||||
const model = prop({}, pouchDocHash);
|
const model = prop({}, pouchDocHash);
|
||||||
|
const appbarState = prop({});
|
||||||
const images = container([], pouchDocArrayHash);
|
const images = container([], pouchDocArrayHash);
|
||||||
const hoverId = prop(null);
|
|
||||||
const selectedIds = container(new Set(), hashSet);
|
const selectedIds = container(new Set(), hashSet);
|
||||||
const selectMode = computed(sIds => sIds.size > 0, [selectedIds]);
|
const appBarTitle = computed(s => (s.size > 0 ? `${s.size} selected` : 'Photos'), [selectedIds]);
|
||||||
|
const hasSelectedIDs = computed(sIds => sIds.size > 0, [selectedIds]);
|
||||||
|
const selectMode = computed((s, abS) => s && abS.selectMode, [hasSelectedIDs, appbarState]);
|
||||||
|
|
||||||
const sections = computed(
|
const sections = computed(
|
||||||
imageArr => {
|
imageArr => {
|
||||||
@ -48,16 +51,6 @@ export function AllImagesView(vm, params, key, opts) {
|
|||||||
[images]
|
[images]
|
||||||
);
|
);
|
||||||
|
|
||||||
ImageType.find(
|
|
||||||
{
|
|
||||||
['sizes.thumbnail']: { $exists: true }
|
|
||||||
},
|
|
||||||
true
|
|
||||||
).then(la => {
|
|
||||||
opts.appbar.renderButtons(renderAppBarButtons);
|
|
||||||
subscribeToRender(vm, [images], [la.subscribe(res => images.splice(0, images.length, ...res))]);
|
|
||||||
});
|
|
||||||
|
|
||||||
function renderAppBarButtons() {
|
function renderAppBarButtons() {
|
||||||
return [
|
return [
|
||||||
el('button', [el('label', { for: 'uploadButton' }, 'Upload')]),
|
el('button', [el('label', { for: 'uploadButton' }, 'Upload')]),
|
||||||
@ -117,7 +110,44 @@ export function AllImagesView(vm, params, key, opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToRender(vm, [selectedIds, images, hoverId, selectMode]);
|
function pushAppBarState() {
|
||||||
|
appbar.pushState({
|
||||||
|
title: appBarTitle,
|
||||||
|
buttons: renderAppBarButtons,
|
||||||
|
selectMode: hasSelectedIDs()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function popAppBarState() {
|
||||||
|
appbar.popState();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageType.find(
|
||||||
|
{
|
||||||
|
['sizes.thumbnail']: { $exists: true }
|
||||||
|
},
|
||||||
|
true
|
||||||
|
).then(la => {
|
||||||
|
pushAppBarState();
|
||||||
|
subscribeToRender(
|
||||||
|
vm,
|
||||||
|
[selectedIds, images, selectMode],
|
||||||
|
[
|
||||||
|
la.subscribe(res => images.splice(0, images.length, ...res)),
|
||||||
|
appbar.subscribe(({ newState, oldState }) => {
|
||||||
|
appbarState(newState);
|
||||||
|
}),
|
||||||
|
hasSelectedIDs.subscribe(selected => {
|
||||||
|
console.log('hasSelectedIDs subscription');
|
||||||
|
if (selected && !selectMode()) {
|
||||||
|
pushAppBarState();
|
||||||
|
} else if (!selected && appbarState().selectMode) {
|
||||||
|
popAppBarState();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
function renderSection([title, _images]) {
|
function renderSection([title, _images]) {
|
||||||
return AlbumTemplate({
|
return AlbumTemplate({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user