mirror of
https://github.com/liufree/obsidian-querydash.git
synced 2026-07-22 05:41:49 +00:00
commit
83407be9f2
2 changed files with 22 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "querydash",
|
||||
"name": "QueryDash",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"minAppVersion": "1.8.0",
|
||||
"description": "The new view for bases refers to an updated or additional interface that allows users to interact with base data in a different way, such as through enhanced search, sorting, and pagination features, similar to Notion. This improves usability and data management within your application. It was originally a new view for dataview, but now its functionality has been extended to bases.",
|
||||
"author": "lwx",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import {BasesView, MarkdownRenderer, QueryController, TFile,Component} from 'obsidian';
|
||||
import {BasesView, MarkdownRenderer, QueryController, TFile, Component} from 'obsidian';
|
||||
import React, {useEffect, useRef, useState} from 'react';
|
||||
import {createRoot} from 'react-dom/client';
|
||||
import {Button, Space, Card, Modal, notification} from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
||||
|
||||
dayjs.extend(isSameOrBefore);
|
||||
|
||||
export const MemoryCardViewType = 'dash-memory-card-view';
|
||||
|
|
@ -24,19 +25,21 @@ export class DashMemoryCardView extends BasesView {
|
|||
const allCards = this.data.data;
|
||||
// 按 sr-due 升序排序
|
||||
this.sortedCards = [...allCards]
|
||||
.map(card => ({card, due: card.getValue('properties.sr-due')}))
|
||||
.map(function (card) {
|
||||
return {card, due: card.getValue('note.sr-due')};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
if (!a.due && !b.due) return 0;
|
||||
if (!a.due) return 1;
|
||||
if (!b.due) return -1;
|
||||
return dayjs(a.due).valueOf() - dayjs(b.due).valueOf();
|
||||
return dayjs(a.due).isSameOrBefore(b.due) ? -1 : 1;
|
||||
})
|
||||
.map(item => item.card);
|
||||
// 找到 sr-due 最近的卡片
|
||||
let idx = 0;
|
||||
const now = dayjs();
|
||||
for (let i = 0; i < this.sortedCards.length; i++) {
|
||||
const due = this.sortedCards[i].getValue('properties.sr-due');
|
||||
const due = this.sortedCards[i].getValue('note.sr-due');
|
||||
if (due && dayjs(due).isSameOrBefore(now, 'day')) {
|
||||
idx = i;
|
||||
break;
|
||||
|
|
@ -159,41 +162,38 @@ const updateSRFrontmatter = async (
|
|||
return false;
|
||||
};
|
||||
|
||||
const MemoryCard: React.FC<MemoryCardProps> = ({markdown, app, filePath, title, frontmatter, onPrev, onNext, isPrevDisabled, isNextDisabled}) => {
|
||||
const MemoryCard: React.FC<MemoryCardProps> = ({
|
||||
markdown,
|
||||
app,
|
||||
filePath,
|
||||
title,
|
||||
frontmatter,
|
||||
onPrev,
|
||||
onNext,
|
||||
isPrevDisabled,
|
||||
isNextDisabled
|
||||
}) => {
|
||||
const mdRef = useRef<HTMLDivElement>(null);
|
||||
const [rendered, setRendered] = useState(false);
|
||||
const [fm, setFM] = useState(frontmatter);
|
||||
const [md, setMD] = useState(markdown);
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setFM(frontmatter);
|
||||
setMD(markdown);
|
||||
}, [frontmatter, markdown]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mdRef.current && !rendered) {
|
||||
// 修正:传递一个 Obsidian Component 实例,避免内存泄漏
|
||||
MarkdownRenderer.render(
|
||||
app,
|
||||
md,
|
||||
markdown,
|
||||
mdRef.current,
|
||||
filePath,
|
||||
null
|
||||
);
|
||||
setRendered(true);
|
||||
}
|
||||
}, [md, app, filePath, rendered]);
|
||||
}, [markdown, app, filePath]);
|
||||
|
||||
const refresh = async () => {
|
||||
const file = app.vault.getAbstractFileByPath(filePath);
|
||||
if (file instanceof TFile) {
|
||||
const newMD = await app.vault.read(file);
|
||||
setMD(newMD);
|
||||
const cache = app.metadataCache.getFileCache(file);
|
||||
setFM(cache?.frontmatter);
|
||||
setRendered(false);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const handleDifficulty = async (action: 'hard' | 'medium' | 'easy') => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue