From 33fbaf7b6f9f0e117a6e3d5d035c2280a931a6f6 Mon Sep 17 00:00:00 2001 From: frostime Date: Fri, 13 Sep 2024 12:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20rm:=20=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=9F=BA=E4=BA=8E=20reservation=20=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ package.json | 2 +- plugin.json | 2 +- src/components/toolbar-menu.ts | 25 +++++-------------------- src/func/index.ts | 8 ++++---- src/func/reserve/index.ts | 28 +++++++++++++++++++++++++--- src/global-status.ts | 13 +------------ 7 files changed, 42 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eee4e00..66ced68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [2024-09-13] v1.6.8 + +- 🔨 refactor: Dock 栏改为基于查询的方案获取预约信息 +- 🔥 rm: 去掉一些基于 reservation 对象的代码,为后面弃用 reservation 对象做准备 + ## [2024-09-09] v1.6.7 - 🐛 fix: 修复打开日记却没有正确插入预约块的问题 diff --git a/package.json b/package.json index c00661a..bb834fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "siyuan-dailynote-today", - "version": "1.6.7", + "version": "1.6.8", "description": "", "main": ".src/index.js", "keywords": [], diff --git a/plugin.json b/plugin.json index 384301a..dafa19f 100644 --- a/plugin.json +++ b/plugin.json @@ -6,7 +6,7 @@ "en_US": "Daily Note Today" }, "url": "https://github.com/frostime/siyuan-dailynote-today", - "version": "1.6.7", + "version": "1.6.8", "minAppVersion": "3.0.0", "description": { "zh_CN": "自动创建日记 + 快速打开日记 + 日程 TODO 管理 + 移动块功能", diff --git a/src/components/toolbar-menu.ts b/src/components/toolbar-menu.ts index efa6f72..26a9879 100644 --- a/src/components/toolbar-menu.ts +++ b/src/components/toolbar-menu.ts @@ -1,7 +1,7 @@ -import { IMenuItemOption, Menu, showMessage } from "siyuan"; +import { IMenuItemOption, Menu } from "siyuan"; import { currentDiaryStatus, openDiary } from "../func"; import notebooks from "../global-notebooks"; -import { reservation, settings } from "../global-status"; +import { settings } from "../global-status"; import { i18n, isMobile } from "../utils"; import { eventBus } from "../event-bus"; import { iconDiary } from "./svg"; @@ -25,19 +25,8 @@ export class ToolbarMenuItem { //注册事件总线,以防 moveBlocks 完成后新的日记被创建,而状态没有更新 eventBus.subscribe('moveBlocks', UpdateDailyNoteStatusListener); - //1. 由于 SiYuan 要求 topbar 必须在 await 前, 所以这里姑且放一个 dummy icon - //实测发现不需要提前创建, 也可以 - // this.ele = this.plugin.addTopBar({ - // icon: iconDiary.icon32, - // title: i18n.Name, - // position: 'left', - // callback: () => { } - // }); - // this.ele.style.display = 'none'; // FW icon, 不显示 - // setting 异步加载完成后, 发送 event bus eventBus.subscribe(eventBus.EventSettingLoaded, () => { this.addTopBarIcon(); }); - } release() { @@ -69,17 +58,13 @@ export class ToolbarMenuItem { menu.addItem({ label: i18n.Setting.name, icon: 'iconSettings', - click: () => {eventBus.publish('OpenSetting', '');} - }); - menu.addItem({ - label: i18n.ContextMenu.PruneResv, - icon: 'iconTrashcan', - click: async () => {await reservation.doPrune(); showMessage(i18n.Msg.PruneResv);} + click: () => { eventBus.publish('OpenSetting', ''); } }); + menu.addItem({ label: i18n.Setting.update.title, icon: 'iconRefresh', - click: () => {eventBus.publish(eventBus.EventUpdateAll, '');} + click: () => { eventBus.publish(eventBus.EventUpdateAll, ''); } }); let rect = this.ele.getBoundingClientRect(); diff --git a/src/func/index.ts b/src/func/index.ts index ea0edf9..7ec2807 100644 --- a/src/func/index.ts +++ b/src/func/index.ts @@ -1,13 +1,13 @@ /** * Copyright (c) 2023 frostime all rights reserved. */ -import { reservation, settings } from '@/global-status'; +import { settings } from '@/global-status'; import { autoOpenDailyNote, checkDuplicateDiary } from './dailynote'; import type DailyNoteTodayPlugin from '@/index'; import type { EventBus } from 'siyuan'; import { debouncer } from '@/utils'; -import { updateTodayReservation } from './reserve'; +import { isTodayReserved, updateTodayReservation } from './reserve'; import { updateStyleSheet } from './style'; import notebooks from '@/global-notebooks'; @@ -107,7 +107,7 @@ export class RoutineEventHandler { const HighlightResv = settings.get('HighlightResv'); if (!HighlightResv) return; - reservation.isTodayReserved().then(yes => { + isTodayReserved().then(yes => { if (!yes) { updateStyleSheet(''); return; @@ -159,7 +159,7 @@ export class RoutineEventHandler { if (this.flag.hasAutoInsertResv === true) return; //如果今天没有预约,就不插入 - let hasResv = await reservation.isTodayReserved(); + let hasResv = await isTodayReserved(); if (!hasResv) return; let succeed = updateTodayReservation(notebooks.default); diff --git a/src/func/reserve/index.ts b/src/func/reserve/index.ts index c895e3c..222c2f0 100644 --- a/src/func/reserve/index.ts +++ b/src/func/reserve/index.ts @@ -1,8 +1,16 @@ +/* + * Copyright (c) 2024 by frostime. All Rights Reserved. + * @Author : frostime + * @Date : 2024-09-09 22:18:54 + * @FilePath : /src/func/reserve/index.ts + * @LastEditTime : 2024-09-13 11:55:40 + * @Description : + */ import { confirm } from 'siyuan'; import { DebugKit, i18n } from "@/utils"; import * as serverApi from '@/serverApi'; -import { reservation, settings } from '@/global-status'; -import { Retrieve, RetvFactory } from './retrieve'; +import { settings } from '@/global-status'; +import { Retrieve, retrieveResvFromBlocks, RetvFactory } from './retrieve'; export * from './retrieve'; export * from './reserve'; @@ -32,7 +40,7 @@ export async function updateDocReservation(docId: string, refresh: boolean = fal DebugKit.info('调用 updateDocReservation', ...arguments); - let resvBlockIds = await reservation.getTodayReservations(); + let resvBlockIds = await getTodayReservations(); if (resvBlockIds.length == 0) { return; } @@ -63,3 +71,17 @@ export async function updateDocReservation(docId: string, refresh: boolean = fal } } } + + +/** + * @returns 获取今天的预约块 ID 列表 + */ +export const getTodayReservations = async (): Promise => { + let reservations: Reservation[] = await retrieveResvFromBlocks('today'); + return reservations.map(r => r.id); +} + +export const isTodayReserved = async (): Promise => { + let resv = await getTodayReservations(); + return resv.length > 0; +} diff --git a/src/global-status.ts b/src/global-status.ts index f97c5d4..0368994 100644 --- a/src/global-status.ts +++ b/src/global-status.ts @@ -3,7 +3,7 @@ * @Author : frostime * @Date : 2024-05-21 14:14:08 * @FilePath : /src/global-status.ts - * @LastEditTime : 2024-09-09 21:46:44 + * @LastEditTime : 2024-09-13 11:59:51 * @Description : */ import { eventBus } from './event-bus'; @@ -252,17 +252,6 @@ class ReservationManger { this.reserved.set(blockId, date_str); } - async isTodayReserved(): Promise { - let resv = await this.getTodayReservations(); - return resv.length > 0; - } - - //获取今天的预约 - async getTodayReservations(): Promise { - let reservations: Reservation[] = await retrieveResvFromBlocks('today'); - return reservations.map(r => r.id); - } - //清理已经过期的预约 doPurgeExpired() { let date = new Date();