// The Android Sync page: what this phone sends to its groups, on the Android
// application only (docs/MESHBAY_DESIGN.md §9.12, §9.13). Loaded on demand,
// like the sections it holds: no other client has it.
//
// Where everything goes is chosen once, at the top, and every section below
// sends into its own folder there.
import { html, useState, useEffect } from './vendor/htm-preact.js';
import { t } from './i18n.js';
import { ask } from './ask.js';
import * as platform from './platform.js';
import { PhotoSyncSection } from './photo-sync-settings.js';
import { DocSyncSection } from './phone-sync-settings.js';
import { DriveSyncSection } from './drive-sync-settings.js';
import { runDriveSync } from './drive-sync.js';
import { runPhotoSync } from './photo-sync.js';
import { runDocSync, KINDS } from './phone-sync.js';
import {
destination, privateGroups, probeGroup, photosTabShows,
} from './sync-destination.js';
/** The folder each kind this phone has goes into, named as the phone names it. */
function kindDirs(folder, account) {
const suffixes = [
...(platform.photoSync.available ? ['photos'] : []),
...Object.values(KINDS).filter((k) => k.sync.available).map((k) => k.suffix),
...(platform.driveSync.available ? ['drive'] : []),
];
return suffixes.map((s) => `${folder}/${account}-${s}`);
}
export function AndroidSyncPage({ user, groups }) {
const [dest, setDest] = useState(undefined); // undefined while asked, null when none
useEffect(() => { destination.get().then(setDest).catch(() => setDest(null)); }, []);
if (dest === undefined) {
return html`
${t('androidsync.title')}
`;
}
const mine = dest && dest.account === user.username ? dest : null;
const place = mine ? `${mine.groupId}\n${mine.folder}` : 'none';
const moved = (next) => {
setDest(next);
// Each kind that is on starts again in the new place, now.
if (platform.photoSync.available) runPhotoSync();
for (const kind of Object.keys(KINDS)) if (KINDS[kind].sync.available) runDocSync(kind);
if (platform.driveSync.available) runDriveSync();
};
return html`