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

Half-star ratings #1172

Open
eao opened this issue Jan 25, 2025 · 3 comments
Open

Half-star ratings #1172

eao opened this issue Jan 25, 2025 · 3 comments

Comments

@eao
Copy link

eao commented Jan 25, 2025

I would very much like half-star ratings. As someone who obsesses over categorization, 5 rating points is too few for my liking, and having 10 would be much nicer.

@eao
Copy link
Author

eao commented Feb 6, 2025

As a very jank workaround, if you edit the ratings in index.js to have up to 10 stars, then build from source, everything seems to work as expected. The menu isn't pretty but it works. ¯\_(ツ)_/¯

Actually it breaks everything for some reason, abort abort abort. Yet to find a proper workaround.

@eao
Copy link
Author

eao commented Feb 6, 2025

Before trying to figure it out myself, I thought I would ask ChatGPT to rewrite the relevant part of index.js to have 1-10 keycap emoji-based ratings rather than star emoji-based ratings. From initial testing it seems to work, and you can search for something you've rated, say, a 9, with "rating:9", which is easier to type than star emojis. But it's AI-generated code so no guarantees ofc. This same concept could be altered to have increments of 0.5 from 0.5 to 5.0, that is, half-stars, which would probably fit the manga rating paradigm better. Not going to make a pull request with AI code, but here is the relevant block of code for anyone interested.

Index.loadContextMenuRatings = (id) => Server.callAPI(`/api/archives/${id}/metadata`, "GET", null, `Error finding metadata for ${id}!`,
    (data) => {
        const items = {};
        const ratings = [
            { name: "Remove rating" },
            { name: "1️⃣", value: "1" },
            { name: "2️⃣", value: "2" },
            { name: "3️⃣", value: "3" },
            { name: "4️⃣", value: "4" },
            { name: "5️⃣", value: "5" },
            { name: "6️⃣", value: "6" },
            { name: "7️⃣", value: "7" },
            { name: "8️⃣", value: "8" },
            { name: "9️⃣", value: "9" },
            { name: "🔟", value: "10" }
        ];
        
        const tags = LRR.splitTagsByNamespace(data.tags);
        const hasRating = Object.keys(tags).some(x => x === "rating");
        const ratingValue = hasRating ? tags["rating"][0] : null;

        for (let i = 0; i < ratings.length; i++) {
            items[i] = { name: ratings[i].name, type: "checkbox" };

            // Match the rating numerically instead of by emoji
            if (ratings[i].value && ratingValue === ratings[i].value) {
                items[i].selected = true;
            }

            items[i].events = {
                click() {
                    if (i === 0) {
                        delete tags["rating"];
                    } else {
                        tags["rating"] = [ratings[i].value]; // Store numeric rating instead of emoji
                    }

                    Server.updateTagsFromArchive(id, Object.entries(tags)
                        .flatMap(([namespace, tagArray]) => tagArray.map(tag => LRR.buildNamespacedTag(namespace, tag))));

                    // Update the rating info without reload but refresh everything.
                    IndexTable.dataTable.ajax.reload(null, false);
                    Index.updateCarousel();
                    $(this).parents("ul.context-menu-list")
                        .find("input[type='checkbox']")
                        .toArray()
                        .filter((x) => x !== this)
                        .forEach(x => x.checked = false);
                },
            };
        }

        return items;
    },
);

@Difegue
Copy link
Owner

Difegue commented Feb 20, 2025

Hmm, I wouldn't move from star ratings in the main server to numerical now that they're implemented sadly, that'd require migration code and it'd be annoying.

Since this is all frontend though, I think you can easily keep using numerical 1-10 ratings with that code in a userscript or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants