1
0
mirror of https://github.com/koloml/philomena-tagging-assistant.git synced 2026-06-24 02:32:21 +00:00

Refactoring how preferences classes provide access to fields inside

Instead of constantly implementing these weird methods to read or update
values, there will be fields inside the preferences which contain
methods to read or update them.
This commit is contained in:
2026-03-07 06:41:28 +04:00
parent dc29c6ca69
commit 9024883949
14 changed files with 188 additions and 112 deletions

View File

@@ -17,8 +17,8 @@ export class BlockCommunication extends BaseComponent {
protected init() {
Promise.all([
BlockCommunication.#preferences.resolveReplaceLinks(),
BlockCommunication.#preferences.resolveReplaceLinkText(),
BlockCommunication.#preferences.replaceLinks.get(),
BlockCommunication.#preferences.replaceLinkText.get(),
]).then(([replaceLinks, replaceLinkText]) => {
this.#onReplaceLinkSettingResolved(
replaceLinks,

View File

@@ -54,7 +54,7 @@ export class FullscreenViewer extends BaseComponent {
this.#sizeSelectorElement.addEventListener('click', event => event.stopPropagation());
FullscreenViewer.#preferences
.resolveFullscreenViewerPreviewSize()
.fullscreenViewerSize.get()
.then(this.#onSizeResolved.bind(this))
.then(this.#watchForSizeSelectionChanges.bind(this));
}
@@ -202,7 +202,7 @@ export class FullscreenViewer extends BaseComponent {
}
lastActiveSize = targetSize;
void FullscreenViewer.#preferences.setFullscreenViewerPreviewSize(targetSize);
void FullscreenViewer.#preferences.fullscreenViewerSize.set(targetSize as FullscreenViewerSize);
});
}

View File

@@ -26,7 +26,7 @@ export class ImageShowFullscreenButton extends BaseComponent {
this.on('click', this.#onButtonClicked.bind(this));
if (ImageShowFullscreenButton.#preferences) {
ImageShowFullscreenButton.#preferences.resolveFullscreenViewerEnabled()
ImageShowFullscreenButton.#preferences.fullscreenViewer.get()
.then(isEnabled => {
this.#isFullscreenButtonEnabled = isEnabled;
this.#updateFullscreenButtonVisibility();

View File

@@ -214,7 +214,7 @@ export class MaintenancePopup extends BaseComponent {
let maybeTagsAndAliasesAfterUpdate;
const shouldAutoRemove = await MaintenancePopup.#preferences.resolveStripBlacklistedTags();
const shouldAutoRemove = await MaintenancePopup.#preferences.stripBlacklistedTags.get();
try {
maybeTagsAndAliasesAfterUpdate = await MaintenancePopup.#scrapedAPI.updateImageTags(
@@ -359,13 +359,11 @@ export class MaintenancePopup extends BaseComponent {
lastActiveProfileId = settings.activeProfile;
this.#preferences
.resolveActiveProfileAsObject()
this.#preferences.activeProfile.asObject()
.then(callback);
});
this.#preferences
.resolveActiveProfileAsObject()
this.#preferences.activeProfile.asObject()
.then(profileOrNull => {
if (profileOrNull) {
lastActiveProfileId = profileOrNull.id;

View File

@@ -179,7 +179,7 @@ export class TagDropdownWrapper extends BaseComponent {
});
await profile.save();
await TagDropdownWrapper.#preferences.setActiveProfileId(profile.id);
await TagDropdownWrapper.#preferences.activeProfile.set(profile.id);
}
async #onToggleInExistingClicked() {
@@ -219,7 +219,7 @@ export class TagDropdownWrapper extends BaseComponent {
lastActiveProfile = settings.activeProfile ?? null;
this.#preferences
.resolveActiveProfileAsObject()
.activeProfile.asObject()
.then(onActiveProfileChange);
});
@@ -232,7 +232,7 @@ export class TagDropdownWrapper extends BaseComponent {
});
this.#preferences
.resolveActiveProfileAsObject()
.activeProfile.asObject()
.then(activeProfile => {
lastActiveProfile = activeProfile?.id ?? null;
onActiveProfileChange(activeProfile);

View File

@@ -44,7 +44,7 @@ export class TagsListBlock extends BaseComponent {
}
init() {
this.#preferences.resolveGroupSeparation().then(this.#onTagSeparationChange.bind(this));
this.#preferences.groupSeparation.get().then(this.#onTagSeparationChange.bind(this));
this.#preferences.subscribe(settings => {
this.#onTagSeparationChange(Boolean(settings.groupSeparation))
});
@@ -103,7 +103,7 @@ export class TagsListBlock extends BaseComponent {
#onToggleGroupingClicked(event: Event) {
event.preventDefault();
void this.#preferences.setGroupSeparation(!this.#shouldDisplaySeparation);
void this.#preferences.groupSeparation.set(!this.#shouldDisplaySeparation);
}
#handleTagGroupChanges(tagGroup: TagGroup) {