Skip to content

Commit 1abb3a1

Browse files
0xmadmichiosw
authored andcommitted
feat(web): add mock remove server method
1 parent 691823e commit 1abb3a1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

internal/web/domain/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package domain
22

33
type ServerItem struct {
4+
ID string
45
Name string
56
IP string
67
}

internal/web/handlers/ui.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ func (h *UIHandler) serveIndex(w http.ResponseWriter, r *http.Request) {
3232
err := templates.IndexPage(templates.IndexPageProps{
3333
Servers: []domain.ServerItem{
3434
{
35+
ID: "1",
3536
Name: "Server Alpha",
3637
IP: "192.168.1.10",
3738
},
3839
{
40+
ID: "2",
3941
Name: "Server Beta",
4042
IP: "192.168.1.11",
4143
},
4244
{
45+
ID: "3",
4346
Name: "Server Charlie",
4447
IP: "192.168.1.12",
4548
},
@@ -67,7 +70,11 @@ func (h *UIHandler) serveSuccessPage(w http.ResponseWriter, r *http.Request) {
6770
name := r.URL.Query().Get("name")
6871
ip := r.URL.Query().Get("ip")
6972

70-
text := fmt.Sprintf("Successfully added server '%s' with IP %s.", name, ip)
73+
var text string
74+
75+
if name != "" && ip != "" {
76+
text = fmt.Sprintf("Successfully added server '%s' with IP %s.", name, ip)
77+
}
7178

7279
err := templates.SuccessPage(templates.SuccessPageProps{Text: text}).Render(r.Context(), w)
7380

internal/web/templates/blocks/servers.templ

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ templ Servers(servers []domain.ServerItem) {
6868
<section class={ serverSection() }>
6969
<div class={ serverSectionHeader() }>
7070
<h2 class={ serverTitle() }>MCP servers</h2>
71-
@components.Link(components.LinkProps{ Name: "Add server", Href: "/add" })
71+
@components.Link(components.LinkProps{Name: "Add server", Href: "/add"})
7272
</div>
7373
<ul class={ serverList() } data-testid="servers">
7474
for _, item := range servers {
@@ -84,6 +84,9 @@ templ Server(server domain.ServerItem) {
8484
<strong class={ serverListItemName() }>{ server.Name }</strong>
8585
<div class={ serverListItemIP() }>{ server.IP }</div>
8686
</div>
87-
@components.Button(components.ButtonProps{Label: "Remove", Type: "button", Class: serverListItemRemove()})
87+
<form method="POST" action="/api/remove">
88+
<input type="hidden" name="id" value={ server.ID }/>
89+
@components.Button(components.ButtonProps{Label: "Remove", Type: "submit", Class: serverListItemRemove()})
90+
</form>
8891
</li>
8992
}

0 commit comments

Comments
 (0)