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

Wire up the sidebar oracles #31

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/oracles/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export async function runOracleCommand(
datastore: Datastore,
editor: Editor,
_view: MarkdownView,
chosenOracle?: Oracle,
): Promise<void> {
if (!datastore.ready) {
console.warn("data not ready");
Expand Down Expand Up @@ -101,17 +102,22 @@ export async function runOracleCommand(
return;
}

const oracles: Oracle[] = [...datastore.oracles.values()];
const oracle = await CustomSuggestModal.select(
app,
oracles,
formatOraclePath,
(match, el) => {
const ruleset = oracleRuleset(match.item);
el.createEl("small", { text: ruleset, cls: "forged-suggest-hint" });
},
prompt ? `Select an oracle to answer '${prompt}'` : "Select an oracle",
);
let oracle: Oracle;
if (chosenOracle) {
oracle = chosenOracle;
} else {
const oracles: Oracle[] = [...datastore.oracles.values()];
oracle = await CustomSuggestModal.select(
app,
oracles,
formatOraclePath,
(match, el) => {
const ruleset = oracleRuleset(match.item);
el.createEl("small", { text: ruleset, cls: "forged-suggest-hint" });
},
prompt ? `Select an oracle to answer '${prompt}'` : "Select an oracle",
);
}
console.log(oracle);
const rollContext = new OracleRoller(datastore.oracles);
new OracleRollerModal(
Expand Down
9 changes: 5 additions & 4 deletions src/oracles/oracle-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ export class OracleModal extends Modal {
.setTooltip("Roll this Oracle")
.onClick(() => {
const { workspace } = this.plugin.app;
const editor = workspace.activeEditor?.editor;
const view = workspace.getActiveViewOfType(MarkdownView);
console.log({ editor, view });
if (editor && view) {
const view = workspace.getActiveFileView();
if (view && view instanceof MarkdownView) {
const editor = view.editor;
runOracleCommand(
this.plugin.app,
this.plugin.datastore,
editor,
view,
oracle,
);
this.close();
}
});
const table = contentEl.createEl("table");
Expand Down
Loading