Skip to content

Commit

Permalink
🔥 rm: 去掉一些基于 reservation 对象的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Sep 13, 2024
1 parent 9f22172 commit 33fbaf7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [2024-09-13] v1.6.8

- 🔨 refactor: Dock 栏改为基于查询的方案获取预约信息
- 🔥 rm: 去掉一些基于 reservation 对象的代码,为后面弃用 reservation 对象做准备

## [2024-09-09] v1.6.7

- 🐛 fix: 修复打开日记却没有正确插入预约块的问题
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siyuan-dailynote-today",
"version": "1.6.7",
"version": "1.6.8",
"description": "",
"main": ".src/index.js",
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 管理 + 移动块功能",
Expand Down
25 changes: 5 additions & 20 deletions src/components/toolbar-menu.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/func/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 25 additions & 3 deletions src/func/reserve/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -63,3 +71,17 @@ export async function updateDocReservation(docId: string, refresh: boolean = fal
}
}
}


/**
* @returns 获取今天的预约块 ID 列表
*/
export const getTodayReservations = async (): Promise<BlockId[]> => {
let reservations: Reservation[] = await retrieveResvFromBlocks('today');
return reservations.map(r => r.id);
}

export const isTodayReserved = async (): Promise<boolean> => {
let resv = await getTodayReservations();
return resv.length > 0;
}
13 changes: 1 addition & 12 deletions src/global-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -252,17 +252,6 @@ class ReservationManger {
this.reserved.set(blockId, date_str);
}

async isTodayReserved(): Promise<boolean> {
let resv = await this.getTodayReservations();
return resv.length > 0;
}

//获取今天的预约
async getTodayReservations(): Promise<string[]> {
let reservations: Reservation[] = await retrieveResvFromBlocks('today');
return reservations.map(r => r.id);
}

//清理已经过期的预约
doPurgeExpired() {
let date = new Date();
Expand Down

0 comments on commit 33fbaf7

Please sign in to comment.