Skip to content

Commit

Permalink
Wire up the sidebar oracles
Browse files Browse the repository at this point in the history
  • Loading branch information
cwegrzyn committed May 20, 2024
1 parent 0d9e64b commit f53cb5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
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
10 changes: 6 additions & 4 deletions src/oracles/oracle-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ 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();
console.log({ view });
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

0 comments on commit f53cb5d

Please sign in to comment.