Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin event bus click-flashcard-action #10318

Closed
IAliceBobI opened this issue Feb 5, 2024 · 10 comments
Closed

Add plugin event bus click-flashcard-action #10318

IAliceBobI opened this issue Feb 5, 2024 · 10 comments
Assignees
Milestone

Comments

@IAliceBobI
Copy link

In what scenarios do you need this feature?

通过接收用户对每个闪卡做出的动作,可以动态调整优先级,以及其他统计分析。

Describe the optimal solution

发出闪卡复习事件,带上点击的是底部哪个按钮。

Describe the candidate solution

No response

Other information

No response

@Vanessa219
Copy link
Member

这样可以不?

IEventBusMap {
    "click-flashcard-action": {
        type: string
    }
}

@IAliceBobI
Copy link
Author

@Vanessa219

type是0~4吗。

另外再带上:

type DueCard = {
    deckID: string;
    cardID: string;
    blockID: string;
    state: number;
    nextDues: { "1": string, "2": string, "3": string, "4": string };
}


IEventBusMap {
    "click-flashcard-action": {
        type: string,
        card: DueCard,
    }
}

@Vanessa219
Copy link
Member

type:

           if (event.detail === "1" || event.detail === "j") {
                type = "1";
            } else if (event.detail === "2" || event.detail === "k") {
                type = "2";
            } else if (event.detail === "3" || event.detail === "l") {
                type = "3";
            } else if (event.detail === "4" || event.detail === ";") {
                type = "4";
            } else if (event.detail === " " || event.detail === "enter") {
                type = "-1";
            } else if (event.detail === "p") {
                type = "-2";
            } else if (event.detail === "0") {
                type = "-3";
            }

以下几个好像没有,还是指的是什么?

    blockID: string;
    state: number;
    nextDues: { "1": string, "2": string, "3": string, "4": string };

@IAliceBobI
Copy link
Author

@Vanessa219 其实就是 ICard 接口。

export interface ICard {
    deckID: string
    cardID: string
    blockID: string
    nextDues: IObject
}

@IAliceBobI
Copy link
Author

@Vanessa219

/api/riff/getRiffDueCards 返回的结果就是:

type DueCard = {
    deckID: string;
    cardID: string;
    blockID: string;
    state: number;
    nextDues: { "1": string, "2": string, "3": string, "4": string };
}

type GetDueCardRet = {
    cards: DueCard[],
    unreviewedCount: number,
    unreviewedNewCardCount: number,
    unreviewedOldCardCount: number,
};

type DueCard = {
deckID: string;
cardID: string; 卡id
blockID: string; 内容块id
state: number; 上次的难易程度
nextDues: { "1": string, "2": string, "3": string, "4": string }; 每个难易程度 要延迟几天。
}

IEventBusMap {
"click-flashcard-action": {
type: string, 本次点击的难易程度,包括跳过。
card: DueCard,
}
}

@Vanessa219 Vanessa219 self-assigned this Feb 6, 2024
@Vanessa219 Vanessa219 added this to the 2.12.8 milestone Feb 6, 2024
@Vanessa219 Vanessa219 changed the title 希望在闪卡复习UI中,点击几个按钮时,能发出事件。 Add plugin event bus click-flashcard-action Feb 6, 2024
Vanessa219 added a commit that referenced this issue Feb 6, 2024
Vanessa219 added a commit to siyuan-note/petal that referenced this issue Feb 6, 2024
Vanessa219 added a commit to siyuan-note/plugin-sample that referenced this issue Feb 6, 2024
Vanessa219 added a commit that referenced this issue Feb 6, 2024
@Vanessa219
Copy link
Member

我提交了,你看一下可不可以了。

@IAliceBobI
Copy link
Author

IAliceBobI commented Feb 6, 2024

@Vanessa219

const emitEvent = (app: App, cards: ICard[], type: string) => {
    app.plugins.forEach(item => {
        item.eventBus.emit("click-flashcard-action", {
            type,
            cards
        });
    });
};

就发一个ICard吧。我需要拿到当前复习后点击按钮的那个card。发太多了,我不知道点击的是哪个。

@IAliceBobI
Copy link
Author

@Vanessa219

const emitEvent = (app: App, cards: ICard[], type: string) => {
    app.plugins.forEach(item => {
        item.eventBus.emit("click-flashcard-action", {
            type,
            card,     <----- 就发一个,不然不知道点击的是哪个。
        });
    });
};

Vanessa219 added a commit to siyuan-note/petal that referenced this issue Feb 8, 2024
Vanessa219 added a commit that referenced this issue Feb 8, 2024
@Vanessa219
Copy link
Member

再试试

@IAliceBobI
Copy link
Author

@Vanessa219 感谢!测试了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants