Commit 4081ff1a authored by Cursor AI's avatar Cursor AI Committed by Jakob Moser
Browse files

Refactor: Remove query/onQueryChange props, use m.route.param directly for...

Refactor: Remove query/onQueryChange props, use m.route.param directly for search\n\n- Eliminate all query/onQueryChange props and state from page, layout, and list components\n- SearchBar and SongList now read and update the search query directly via m.route.param and m.route.set\n- Simplifies prop passing and makes search state fully URL-driven and idiomatic Mithril.js
parent 39a0422f
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -13,7 +13,8 @@ const SongList = {
        return SongListModel.onbeforeupdate(vnode, old)
    },
    view: function (vnode) {
        const { currentView, searchTerm, onSearchTermChange } = vnode.attrs
        const { currentView } = vnode.attrs
        const query = m.route.param("q") || ""
        const model = SongListModel

        if (
@@ -30,7 +31,7 @@ const SongList = {
            currentPage,
            totalPages,
            totalFilteredItems,
        } = model.getProcessedSongsForView(currentView, searchTerm)
        } = model.getProcessedSongsForView(currentView, query)

        const artistsOnPage = Object.keys(groupedSongs)

@@ -43,8 +44,12 @@ const SongList = {
                    `Möchtest du `,
                    m(ClearSearchLink, {
                        totalFavs: message.total,
                        onClear: () =>
                            onSearchTermChange && onSearchTermChange(""),
                        onClear: () => {
                            const params = Object.assign({}, m.route.param())
                            delete params.q
                            const path = m.route.get().split('?')[0]
                            m.route.set(path, params, { replace: true })
                        },
                    }),
                    `?`,
                ])
@@ -56,8 +61,12 @@ const SongList = {
                    `Möchtest du `,
                    m(ClearSearchLink, {
                        totalFavs: message.total,
                        onClear: () =>
                            onSearchTermChange && onSearchTermChange(""),
                        onClear: () => {
                            const params = Object.assign({}, m.route.param())
                            delete params.q
                            const path = m.route.get().split('?')[0]
                            m.route.set(path, params, { replace: true })
                        },
                    }),
                    `?`,
                ])
@@ -86,7 +95,7 @@ const SongList = {
                        artist,
                        songs: groupedSongs[artist],
                        currentView,
                        searchTerm,
                        query,
                        currentPage,
                        onToggleFavorite: model.toggleFavorite.bind(model),
                    }),
+0 −8
Original line number Diff line number Diff line
@@ -2,18 +2,10 @@ import Base from "./Base.mjs"
import SongList from "../../SongList.mjs"

export default {
    searchTerm: "",
    onSearchTermChange(term) {
        this.searchTerm = term
    },
    view() {
        return m(Base, {
            searchTerm: this.searchTerm,
            onSearchTermChange: this.onSearchTermChange.bind(this),
            children: m(SongList, {
                currentView: "all",
                searchTerm: this.searchTerm,
                onSearchTermChange: this.onSearchTermChange.bind(this),
            }),
        })
    },
+2 −2
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@ import Header from "../pieces/Header.mjs"

export default {
    view(vnode) {
        const { searchTerm, onSearchTermChange, children } = vnode.attrs || {}
        const { children } = vnode.attrs || {}
        return [
            m(Header, { searchTerm, onSearchTermChange }),
            m(Header),
            m("main", children),
        ]
    },
+0 −8
Original line number Diff line number Diff line
@@ -2,18 +2,10 @@ import Base from "./Base.mjs"
import SongList from "../../SongList.mjs"

export default {
    searchTerm: "",
    onSearchTermChange(term) {
        this.searchTerm = term
    },
    view() {
        return m(Base, {
            searchTerm: this.searchTerm,
            onSearchTermChange: this.onSearchTermChange.bind(this),
            children: m(SongList, {
                currentView: "favorites",
                searchTerm: this.searchTerm,
                onSearchTermChange: this.onSearchTermChange.bind(this),
            }),
        })
    },
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ import SearchBar from "./SearchBar.mjs"
import TabBar from "./TabBar.mjs"

export default {
    view(vnode) {
        return m("header", [m(SearchBar, vnode.attrs), m(TabBar)])
    view() {
        return m("header", [m(SearchBar), m(TabBar)])
    },
}
Loading