feat(core): new "is journal" page property (#8525)

close AF-1450, AF-1451, AF-14552
This commit is contained in:
CatsJuice
2024-10-18 10:03:08 +00:00
parent 714a87c2c0
commit 8f92be926b
19 changed files with 494 additions and 49 deletions
@@ -1,4 +1,5 @@
import { LiveData, Service } from '@toeverything/infra';
import dayjs from 'dayjs';
import type { JournalStore } from '../store/journal';
@@ -7,15 +8,31 @@ export class JournalService extends Service {
super();
}
allJournalDates$ = this.store.allJournalDates$;
journalDate$(docId: string) {
return LiveData.from(this.store.watchDocJournalDate(docId), undefined);
}
journalToday$(docId: string) {
return LiveData.computed(get => {
const date = get(this.journalDate$(docId));
if (!date) return false;
return dayjs(date).isSame(dayjs(), 'day');
});
}
setJournalDate(docId: string, date: string) {
this.store.setDocJournalDate(docId, date);
}
removeJournalDate(docId: string) {
this.store.removeDocJournalDate(docId);
}
getJournalsByDate(date: string) {
return this.store.getDocsByJournalDate(date);
}
journalsByDate$(date: string) {
return this.store.docsByJournalDate$(date);
}
}
@@ -11,6 +11,17 @@ export class JournalStore extends Store {
super();
}
allJournalDates$ = LiveData.computed(get => {
return new Set(
get(this.docsService.list.docs$)
.filter(doc => {
const journal = get(doc.properties$.selector(p => p.journal));
return !!journal && isJournalString(journal);
})
.map(doc => get(doc.properties$.selector(p => p.journal)))
);
});
watchDocJournalDate(docId: string): Observable<string | undefined> {
return LiveData.computed(get => {
const doc = get(this.docsService.list.doc$(docId));
@@ -35,9 +46,21 @@ export class JournalStore extends Store {
doc.setProperty('journal', date);
}
removeDocJournalDate(docId: string) {
this.setDocJournalDate(docId, '');
}
getDocsByJournalDate(date: string) {
return this.docsService.list.docs$.value.filter(
doc => doc.properties$.value.journal === date
);
}
docsByJournalDate$(date: string) {
return LiveData.computed(get => {
return get(this.docsService.list.docs$).filter(doc => {
const journal = get(doc.properties$.selector(p => p.journal));
return journal === date;
});
});
}
}