Skip to content

Commit

Permalink
fix: 🐛 Alternative hierarchy default fields were being overwritten on…
Browse files Browse the repository at this point in the history
… Settings.onload
  • Loading branch information
SkepticMystic committed Apr 18, 2022
1 parent 9a899d2 commit dbb7ad6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 42 deletions.
30 changes: 17 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37765,8 +37765,9 @@ function addDataviewSettings(plugin, alternativeHierarchyDetails) {
.addDropdown((dd) => {
const options = {};
fields.forEach((field) => (options[field] = field));
dd.addOptions(Object.assign(options, { "": "" }));
dd.onChange(async (field) => {
dd.addOptions(Object.assign(options, { "": "" }))
.setValue(settings.dataviewNoteField)
.onChange(async (field) => {
settings.dataviewNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
Expand Down Expand Up @@ -37945,12 +37946,13 @@ function addDendronSettings(plugin, alternativeHierarchyDetails) {
new obsidian.Setting(dendronDetails)
.setName("Dendron Note Field")
.setDesc("Which field should Breadcrumbs use for Dendron notes?")
.addDropdown((cb) => {
.addDropdown((dd) => {
dd.setValue(settings.dendronNoteField);
fields.forEach((field) => {
cb.addOption(field, field);
dd.addOption(field, field);
});
cb.setValue(settings.dendronNoteField);
cb.onChange(async (value) => {
dd.setValue(settings.dendronNoteField);
dd.onChange(async (value) => {
settings.dendronNoteField = value;
await plugin.saveSettings();
});
Expand Down Expand Up @@ -38118,11 +38120,11 @@ function addHierarchyNoteSettings(plugin, alternativeHierarchyDetails) {
.setDesc(fragWithHTML("By default, hierarchy notes use the first <code>up</code> field in your hierarchies. Choose a different one to use by default. If you don't want to choose a default, select the blank option at the bottom of the list."))
.addDropdown((dd) => {
const upFields = getFields(settings.userHiers, "up");
dd.setValue(settings.HNUpField || upFields[0]);
const options = {};
upFields.forEach((field) => (options[field] = field));
dd.addOptions(options);
dd.onChange(async (field) => {
dd.addOptions(options)
.setValue(settings.HNUpField || upFields[0])
.onChange(async (field) => {
settings.HNUpField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
Expand Down Expand Up @@ -39500,8 +39502,9 @@ function addRegexNoteSettings(plugin, alternativeHierarchyDetails) {
.addDropdown((dd) => {
const options = {};
getFields(settings.userHiers).forEach((field) => (options[field] = field));
dd.addOptions(Object.assign(options, { "": "" }));
dd.onChange(async (field) => {
dd.addOptions(Object.assign(options, { "": "" }))
.setValue(settings.regexNoteField)
.onChange(async (field) => {
settings.regexNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
Expand Down Expand Up @@ -39592,8 +39595,9 @@ function addTagNoteSettings(plugin, alternativeHierarchyDetails) {
.addDropdown((dd) => {
const options = {};
getFields(settings.userHiers).forEach((field) => (options[field] = field));
dd.addOptions(Object.assign(options, { "": "" }));
dd.onChange(async (field) => {
dd.addOptions(Object.assign(options, { "": "" }))
.setValue(settings.tagNoteField)
.onChange(async (field) => {
settings.tagNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
Expand Down
14 changes: 8 additions & 6 deletions src/Settings/DataviewNoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export function addDataviewSettings(
)
)
.addDropdown((dd: DropdownComponent) => {

const options = {};
fields.forEach((field) => (options[field] = field));
dd.addOptions(Object.assign(options, { "": "" }));
dd.onChange(async (field) => {
settings.dataviewNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
dd.addOptions(Object.assign(options, { "": "" }))
.setValue(settings.dataviewNoteField)
.onChange(async (field) => {
settings.dataviewNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
});
}
10 changes: 6 additions & 4 deletions src/Settings/DendronSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ export function addDendronSettings(
new Setting(dendronDetails)
.setName("Dendron Note Field")
.setDesc("Which field should Breadcrumbs use for Dendron notes?")
.addDropdown((cb: DropdownComponent) => {
.addDropdown((dd: DropdownComponent) => {
dd.setValue(settings.dendronNoteField);

fields.forEach((field) => {
cb.addOption(field, field);
dd.addOption(field, field);
});
cb.setValue(settings.dendronNoteField);
dd.setValue(settings.dendronNoteField);

cb.onChange(async (value) => {
dd.onChange(async (value) => {
settings.dendronNoteField = value;
await plugin.saveSettings();
});
Expand Down
14 changes: 7 additions & 7 deletions src/Settings/HierarchyNoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ export function addHierarchyNoteSettings(
)
.addDropdown((dd: DropdownComponent) => {
const upFields = getFields(settings.userHiers, "up");
dd.setValue(settings.HNUpField || upFields[0])

const options = {};
upFields.forEach(
(field) => (options[field] = field)
);
dd.addOptions(options);
dd.onChange(async (field) => {
settings.HNUpField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
dd.addOptions(options)
.setValue(settings.HNUpField || upFields[0])
.onChange(async (field) => {
settings.HNUpField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
});
}
13 changes: 7 additions & 6 deletions src/Settings/RegexNoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ export function addRegexNoteSettings(
getFields(settings.userHiers).forEach(
(field) => (options[field] = field)
);
dd.addOptions(Object.assign(options, { "": "" }));
dd.onChange(async (field) => {
settings.regexNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
dd.addOptions(Object.assign(options, { "": "" }))
.setValue(settings.regexNoteField)
.onChange(async (field) => {
settings.regexNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
});
}
14 changes: 8 additions & 6 deletions src/Settings/TagNoteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ export function addTagNoteSettings(
)
)
.addDropdown((dd: DropdownComponent) => {

const options = {};
getFields(settings.userHiers).forEach(
(field) => (options[field] = field)
);
dd.addOptions(Object.assign(options, { "": "" }));
dd.onChange(async (field) => {
settings.tagNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
dd.addOptions(Object.assign(options, { "": "" }))
.setValue(settings.tagNoteField)
.onChange(async (field) => {
settings.tagNoteField = field;
await plugin.saveSettings();
await refreshIndex(plugin);
});
});
}

0 comments on commit dbb7ad6

Please sign in to comment.