# Rows the server updates (MoviePlz)

A list where each row's buttons go to the server and the server sends back that row, changed, from MoviePlz's list of things friends asked you to watch.

[MoviePlz](https://github.com/tonsoflaz2/movieplz) is an open-source app for sharing a movie collection with friends, built with HAM and served by a Laravel app. Its server renders each screen as HAM. This recipe is its TBW ("to be watched") list, with invented titles: the titles a friend suggested that you've now seen, each with Edit, Add to my collection and Remove.

## Step 1: The list as the server sends it

The server renders one row per title: a poster tile (an icon on a tinted square where there's no poster), the title, its kind and year, and who suggested it, with three buttons under it. Each row has an `id`, `tbw-item-7`, so the server can talk about it later.

```ham
<app>
    <config primary_color="red"/>
    <screen>
        <app-bar title="TBW"/>
        <main>
            <column style="w-full p-16 gap-10">
                <text style="muted">
                    Everything your friends have asked you to watch.
                </text>
                <text style="font-lg font-bold mt-8">Seen, not in your collection yet · 2</text>
                <column id="tbw-item-7"
                        style="w-full rounded-xl bg-red-50 dark:bg-red-950">
                    <flex column_widths="60px 1">
                        <column style="h-90 w-60 items-center justify-center rounded-l-xl bg-red-200 dark:bg-red-900">
                            <icon name="movie size-24 red"/>
                        </column>
                        <column style="px-12 py-10 gap-2">
                            <text style="font-bold">The Lighthouse Keeper</text>
                            <text style="muted font-sm">Film · 2021</text>
                            <text style="muted font-xs">Suggested by Ana</text>
                        </column>
                    </flex>
                    <row style="px-12 pb-12 gap-8">
                        <button variant="outlined"
                                size="sm">Edit</button>
                        <button variant="filled"
                                size="sm">Add to my collection</button>
                        <button variant="text"
                                size="sm">Remove</button>
                    </row>
                </column>
                <column id="tbw-item-9"
                        style="w-full rounded-xl bg-red-50 dark:bg-red-950">
                    <flex column_widths="60px 1">
                        <column style="h-90 w-60 items-center justify-center rounded-l-xl bg-red-200 dark:bg-red-900">
                            <icon name="tv size-24 red"/>
                        </column>
                        <column style="px-12 py-10 gap-2">
                            <text style="font-bold">Harbor Lights</text>
                            <text style="muted font-sm">Series · 2019</text>
                            <text style="muted font-xs">Suggested by Sam and Jo</text>
                        </column>
                    </flex>
                    <row style="px-12 pb-12 gap-8">
                        <button variant="outlined"
                                size="sm">Edit</button>
                        <button variant="filled"
                                size="sm">Add to my collection</button>
                        <button variant="text"
                                size="sm">Remove</button>
                    </row>
                </column>
            </column>
        </main>
    </screen>
</app>
```

## Step 2: Each button asks the server

Three attributes hand a button to the server, as htmx does:

- `action="/host/library/7/keep"` with `method="POST"` is the request.
- `target="#tbw-item-7"` says where the answer goes, and `swap="outer"` replaces the whole row with it.

So Add to my collection posts, and the server answers with the same row in its new state ("In your collection"). Edit fetches the row's edit form into the same place. The server owns the data and the markup, and the phone swaps what comes back.

Remove asks first, without the server: `var-removing` and two `@@show` blocks swap the buttons for a "Remove it?" question, and only Yes, remove posts.

MoviePlz's own markup: [the list](https://github.com/tonsoflaz2/movieplz/blob/main/resources/views/ham/host/tbw.blade.php) and [a row](https://github.com/tonsoflaz2/movieplz/blob/main/resources/views/ham/host/partials/_tbw_item.blade.php).

```ham
<app>
    <config primary_color="red"/>
    <screen>
        <app-bar title="TBW"/>
        <main>
            <column style="w-full p-16 gap-10">
                <text style="muted">
                    Everything your friends have asked you to watch.
                </text>
                <text style="font-lg font-bold mt-8">Seen, not in your collection yet · 2</text>
                <column id="tbw-item-7"
                        var-removing="false"
                        style="w-full rounded-xl bg-red-50 dark:bg-red-950">
                    <flex column_widths="60px 1">
                        <column style="h-90 w-60 items-center justify-center rounded-l-xl bg-red-200 dark:bg-red-900">
                            <icon name="movie size-24 red"/>
                        </column>
                        <column style="px-12 py-10 gap-2">
                            <text style="font-bold">The Lighthouse Keeper</text>
                            <text style="muted font-sm">Film · 2021</text>
                            <text style="muted font-xs">Suggested by Ana</text>
                        </column>
                    </flex>
                    <row @@show="!$removing"
                         style="px-12 pb-12 gap-8">
                        <button action="/host/library/7/edit.ham"
                                target="#tbw-item-7"
                                swap="outer"
                                variant="outlined"
                                size="sm">Edit</button>
                        <button action="/host/library/7/keep"
                                method="POST"
                                target="#tbw-item-7"
                                swap="outer"
                                variant="filled"
                                size="sm">Add to my collection</button>
                        <button @click="$removing = true"
                                variant="text"
                                size="sm">Remove</button>
                    </row>
                    <column @@show="$removing"
                            style="px-12 pb-12 gap-8">
                        <text style="font-sm">
                            Remove The Lighthouse Keeper from your library?
                        </text>
                        <row style="gap-8">
                            <button action="/host/library/7/remove"
                                    method="POST"
                                    target="#tbw-item-7"
                                    swap="outer"
                                    variant="filled"
                                    size="sm">Yes, remove</button>
                            <button @click="$removing = false"
                                    variant="outlined"
                                    size="sm">Cancel</button>
                        </row>
                    </column>
                </column>
                <column id="tbw-item-9"
                        var-removing="false"
                        style="w-full rounded-xl bg-red-50 dark:bg-red-950">
                    <flex column_widths="60px 1">
                        <column style="h-90 w-60 items-center justify-center rounded-l-xl bg-red-200 dark:bg-red-900">
                            <icon name="tv size-24 red"/>
                        </column>
                        <column style="px-12 py-10 gap-2">
                            <text style="font-bold">Harbor Lights</text>
                            <text style="muted font-sm">Series · 2019</text>
                            <text style="muted font-xs">Suggested by Sam and Jo</text>
                        </column>
                    </flex>
                    <row @@show="!$removing"
                         style="px-12 pb-12 gap-8">
                        <button action="/host/library/9/edit.ham"
                                target="#tbw-item-9"
                                swap="outer"
                                variant="outlined"
                                size="sm">Edit</button>
                        <button action="/host/library/9/keep"
                                method="POST"
                                target="#tbw-item-9"
                                swap="outer"
                                variant="filled"
                                size="sm">Add to my collection</button>
                        <button @click="$removing = true"
                                variant="text"
                                size="sm">Remove</button>
                    </row>
                    <column @@show="$removing"
                            style="px-12 pb-12 gap-8">
                        <text style="font-sm">Remove Harbor Lights from your library?</text>
                        <row style="gap-8">
                            <button action="/host/library/9/remove"
                                    method="POST"
                                    target="#tbw-item-9"
                                    swap="outer"
                                    variant="filled"
                                    size="sm">Yes, remove</button>
                            <button @click="$removing = false"
                                    variant="outlined"
                                    size="sm">Cancel</button>
                        </row>
                    </column>
                </column>
            </column>
        </main>
    </screen>
</app>
```

All of HAM, for AI tools: https://hypeapps.dev/llms.txt
