ernestwisniewski/kbin

View on GitHub
assets/controllers/settings_row_enum_controller.js

Summary

Maintainability
A
45 mins
Test Coverage
// SPDX-FileCopyrightText: 2023 /kbin contributors <https://kbin.pub/>
//
// SPDX-License-Identifier: AGPL-3.0-only

import {Controller} from '@hotwired/stimulus';

export default class extends Controller {
    /**
     * Calls the action at the given path when the value changes
     * @param actionPath {string} - The path to the action to be called
     * @param reloadRequired {boolean} - Whether the page needs to be reloaded after the action is called
     */
    change({params: {actionPath, reloadRequired}}) {
        return fetch(actionPath).then(() => {
            if (reloadRequired) {
                document.querySelector('.settings-list').classList.add('reload-required');
            }
        });
    }
}