Add game deletion with authorization check
- Add Delete method to GameStore and Persister interface - Add delete button to game list on home page - Verify user owns game before allowing deletion - Use status constants instead of magic numbers - Remove unused variable in persister
This commit is contained in:
48
main.go
48
main.go
@@ -82,6 +82,18 @@ func main() {
|
||||
c.Redirectf("/game/%s", gi.ID())
|
||||
})
|
||||
|
||||
deleteGame := func(id string) h.H {
|
||||
return c.Action(func() {
|
||||
for _, g := range userGames {
|
||||
if g.ID == id {
|
||||
store.Delete(id)
|
||||
break
|
||||
}
|
||||
}
|
||||
c.Redirect("/")
|
||||
}).OnClick()
|
||||
}
|
||||
|
||||
c.View(func() h.H {
|
||||
return ui.LobbyView(
|
||||
nickname.Bind(),
|
||||
@@ -91,6 +103,7 @@ func main() {
|
||||
username,
|
||||
logout.OnClick(),
|
||||
userGames,
|
||||
deleteGame,
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -527,13 +540,11 @@ const gameCSS = `
|
||||
|
||||
.game-entry {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background: var(--pico-muted-background);
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
@@ -541,12 +552,41 @@ const gameCSS = `
|
||||
background: var(--pico-secondary-background);
|
||||
}
|
||||
|
||||
.game-entry-link {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.25rem 0.5rem;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.game-entry-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.game-delete-btn {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--pico-muted-color);
|
||||
font-size: 1.25rem;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: background 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.game-delete-btn:hover {
|
||||
background: #dc2626;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.opponent-name {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user