refactor: non-null filters
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/953/head
parent
07a20fb454
commit
e5e35ce357
|
@ -900,7 +900,7 @@ export default defineComponent({
|
|||
|
||||
// Run WebDAV query
|
||||
for await (let delIds of dav.recognizeDeleteFaceImages(user, name, photos)) {
|
||||
const fileIds = delIds.map((id) => map.get(id)?.fileid ?? 0).filter((id) => id);
|
||||
const fileIds = delIds.map((id) => map.get(id)?.fileid).filter(utils.truthy);
|
||||
this.deleteSelectedPhotosById(fileIds, selection);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -90,7 +90,7 @@ export default defineComponent({
|
|||
|
||||
// Process file ids returned from generator
|
||||
const processFileIds = (fileIds: number[]) => {
|
||||
const successIds = fileIds.filter((f) => f);
|
||||
const successIds = fileIds.filter(Boolean);
|
||||
successIds.forEach((f) => processedIds.add(f));
|
||||
this.opsDone += fileIds.length;
|
||||
opsSuccess += successIds.length;
|
||||
|
|
|
@ -118,7 +118,12 @@ export default defineComponent({
|
|||
// Run WebDAV query
|
||||
const photos = Array.from(map.values());
|
||||
for await (let delIds of dav.recognizeMoveFaceImages(user, name, target, photos)) {
|
||||
this.moved(delIds.filter((id) => id).map((id) => map.get(id)!));
|
||||
this.moved(
|
||||
delIds
|
||||
.filter(utils.truthy)
|
||||
.map((id) => map.get(id))
|
||||
.filter(utils.truthy),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
|
|
@ -71,7 +71,7 @@ export default defineComponent({
|
|||
this.show = true;
|
||||
|
||||
for await (const fids of gen) {
|
||||
this.photosDone += fids.filter((f) => f).length;
|
||||
this.photosDone += fids.filter(Boolean).length;
|
||||
utils.bus.emit('memories:timeline:soft-refresh', null);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ export default defineComponent({
|
|||
}
|
||||
|
||||
return path
|
||||
.filter((x) => x)
|
||||
.filter(Boolean) // non-empty
|
||||
.map((text, idx, arr) => {
|
||||
const path = arr.slice(0, idx + 1);
|
||||
return { text, path, idx };
|
||||
|
|
|
@ -2,7 +2,7 @@ import { NAPI, nativex } from './api';
|
|||
import { has } from './basic';
|
||||
|
||||
import { API } from '@services/API';
|
||||
import { bus, setRenewingTimeout } from '@services/utils';
|
||||
import { bus, setRenewingTimeout, truthy } from '@services/utils';
|
||||
|
||||
import type { IDay, IPhoto } from '@typings';
|
||||
|
||||
|
@ -193,7 +193,7 @@ export async function getLocalDay(dayId: number): Promise<IPhoto[]> {
|
|||
export async function deleteLocalPhotos(photos: IPhoto[], dry: boolean = false): Promise<number> {
|
||||
if (!has()) return 0;
|
||||
|
||||
const auids = photos.map((p) => p.auid).filter((a) => !!a) as string[];
|
||||
const auids = photos.map((p) => p.auid).filter(truthy);
|
||||
|
||||
// Delete local photos
|
||||
const res = await fetch(API.Q(NAPI.IMAGE_DELETE(auids), { dry }));
|
||||
|
|
|
@ -257,7 +257,7 @@ export async function* deletePhotos(photos: IPhoto[], confirm: boolean = true) {
|
|||
await nativex.deleteLocalPhotos(photos);
|
||||
|
||||
// Remove purely local files
|
||||
const deleted = photos.filter((p) => p.flag & utils.constants.FLAG_IS_LOCAL);
|
||||
const deleted = photos.filter(utils.isLocalPhoto);
|
||||
|
||||
// Yield for the fully local files
|
||||
if (deleted.length > 0) {
|
||||
|
|
|
@ -30,7 +30,7 @@ function decodeFragment(hash: string): Fragment[] {
|
|||
return hash
|
||||
.substring(1) // remove # at start
|
||||
.split('&') // get all parts
|
||||
.filter((frag) => frag) // remove empty parts
|
||||
.filter(Boolean) // remove empty parts
|
||||
.map((frag, i, arr) => {
|
||||
const values = frag?.split('/');
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue