Skip to content

Commit 81ed600

Browse files
authored
[ui, forms]: edit submission and UI improvements (#29)
* use all available width for image * fix overview for firefox * add gallery for leaderboard * [misc] rename states, add ids, fix formatting * edit own submission (only title and description for now) * remove comments * fix dark mode with new inputs * minor css adaptions * minor css adaptions * add components for input, select, datepicker * add new version
1 parent f087a60 commit 81ed600

22 files changed

Lines changed: 293 additions & 203 deletions

‎api/pkg/group-challenge/api/api.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func configureAPIRouter(router *gin.Engine, con *pg.DB) {
4646
submissions := party.Group("/:id/submissions")
4747
{
4848
submissions.POST("", addPartySubmissionHandler)
49+
submissions.PUT("/:submissionId", editPartySubmissionHandler)
4950
submissions.DELETE("/:submissionId", deletePartySubmissionHandler)
5051
}
5152

‎api/pkg/group-challenge/api/party-api.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,44 @@ func addPartySubmissionHandler(c *gin.Context) {
339339
c.JSON(200, party)
340340
}
341341

342+
func editPartySubmissionHandler(c *gin.Context) {
343+
party, err := parseParty(c)
344+
if err != nil {
345+
log.Println("[ERROR]", err)
346+
c.Status(http.StatusBadRequest)
347+
return
348+
}
349+
submissionID, err := parseFormId(c, "submissionId")
350+
if err != nil {
351+
log.Println("[ERROR]", err)
352+
c.Status(http.StatusBadRequest)
353+
return
354+
}
355+
356+
meta := &partySubmissionMetaBody{}
357+
358+
if err := c.ShouldBindJSON(meta); err != nil {
359+
log.Println("[ERROR]", err)
360+
c.Status(http.StatusBadRequest)
361+
return
362+
}
363+
364+
partySubmission := &models.PartySubmission{
365+
ID: submissionID,
366+
Name: meta.Name,
367+
Description: meta.Description,
368+
}
369+
if err = party.EditSubmission(partySubmission, con); err != nil {
370+
log.Println("[ERROR]", err)
371+
c.Status(http.StatusInternalServerError)
372+
return
373+
}
374+
375+
party.Select(con)
376+
broadcastParty("update", party)
377+
c.JSON(200, party)
378+
}
379+
342380
func partyByIDHandler(c *gin.Context) {
343381
// TODO validation
344382
partyID, ok := c.Params.Get("id")

‎api/pkg/group-challenge/models/party-model.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ func (party *Party) AddSubmission(submission *PartySubmission, con *pg.DB) (err
7777
return
7878
}
7979

80+
func (party *Party) EditSubmission(submission *PartySubmission, con *pg.DB) (err error) {
81+
err = submission.Update(con)
82+
return
83+
}
84+
8085
func (party *Party) DeleteSubmission(submission *PartySubmission, con *pg.DB) (err error) {
8186
submissionRelation := &PartiesSubmissionsRelation{
8287
PartyID: party.ID,
@@ -127,7 +132,10 @@ func (party *Party) Update(con *pg.DB) error {
127132

128133
// Update updates the submission
129134
func (submission *PartySubmission) Update(con *pg.DB) error {
130-
_, err := con.Model(submission).Where("id = ?0", submission.ID).Update()
135+
_, err := con.Model(submission).
136+
Column("name", "description").
137+
Where("id = ?0", submission.ID).
138+
Update()
131139
return err
132140
}
133141

‎frontend/src/api/api-models.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export interface PartySubmissionFormData {
5555
description: string;
5656
}
5757

58+
export interface PartySubmissionEditFormData {
59+
name: string;
60+
description: string;
61+
}
62+
5863
export enum PartyStatusState {
5964
OPEN = 'open',
6065
LOBBY = 'lobby',

‎frontend/src/api/api.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
GCWebSocketEvent,
1616
PartyReaction,
1717
PaginationPartiesResponse,
18-
ConfigResponse,
18+
ConfigResponse, PartySubmissionEditFormData,
1919
} from './api-models';
2020
import { PartyFormData } from '../party/PartyForm';
2121
import { useSession } from '../user/session';
@@ -340,6 +340,26 @@ export async function deleteSubmission({
340340
});
341341
}
342342

343+
export async function editSubmission({
344+
partyId,
345+
submissionId,
346+
sessionToken,
347+
submission
348+
}: {
349+
partyId: string;
350+
submissionId: string;
351+
sessionToken: string;
352+
submission: PartySubmissionEditFormData;
353+
}): Promise<Response> {
354+
return await fetch(`${API_URLS.API}/parties/${partyId}/submissions/${submissionId}`, {
355+
method: 'PUT',
356+
body: JSON.stringify(submission),
357+
headers: {
358+
'X-AuthToken': sessionToken,
359+
},
360+
});
361+
}
362+
343363
export async function sendReaction({
344364
partyId,
345365
sessionToken,

‎frontend/src/components/Button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function Button(props: any) {
22
return (
33
<button
4-
className="bg-gray-800 hover:bg-gray-400 text-gray-200 font-bold py-2 px-4 rounded"
4+
className="bg-gray-800 hover:bg-gray-400 text-gray-200 font-bold py-2 px-4 rounded cursor-pointer"
55
type="button"
66
{...props}
77
>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {Controller} from "react-hook-form";
2+
import ReactDatePicker from "react-date-picker";
3+
4+
function DatePicker({ label, name, control }: { label: string; name: string; control: any }) {
5+
return (
6+
<div>
7+
<label className="block text-sm font-bold mb-2" htmlFor={name}>
8+
{label}
9+
</label>
10+
<Controller
11+
name={name}
12+
control={control}
13+
render={({ field }) => (
14+
<ReactDatePicker
15+
value={new Date(field.value)}
16+
className="bg-white shadow rounded w-full text-black"
17+
onChange={field.onChange}
18+
/>
19+
)}
20+
/>
21+
</div>
22+
);
23+
}
24+
25+
export default DatePicker;

‎frontend/src/components/Input.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function Input({ label, name, type, optional, props }: { label: string; name: string; type: string; optional: boolean; props?: any }) {
2+
return (
3+
<div>
4+
<label className="block text-sm font-bold mb-2" htmlFor={name}>
5+
{label}
6+
{optional && (
7+
<span className="text-gray-500"> (optional)</span>
8+
)}
9+
</label>
10+
<input
11+
className="bg-white dark:bg-slate-600 shadow appearance-none border border-gray-300 dark:border-slate-900 rounded w-full py-2 px-3 focus:border-blue-400 focus:outline-hidden transition-colors"
12+
type={type}
13+
{...props}
14+
/>
15+
</div>
16+
);
17+
}
18+
19+
export default Input;

‎frontend/src/components/Select.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function Select({
2+
label,
3+
name,
4+
options,
5+
props,
6+
}: {
7+
label: string;
8+
name: string;
9+
options: Map<string, string>;
10+
props?: any;
11+
}) {
12+
return (
13+
<div>
14+
<label className="block text-sm font-bold mb-2" htmlFor={name}>
15+
{label}
16+
</label>
17+
<select
18+
className="bg-white dark:bg-slate-600 shadow border border-gray-300 dark:border-slate-900 rounded w-full py-2 px-3"
19+
{...props}
20+
>
21+
{Array.from(options).map(([key, value]) => (
22+
<option key={key} value={key}>
23+
{value}
24+
</option>
25+
))}
26+
</select>
27+
</div>
28+
);
29+
}
30+
31+
export default Select;

‎frontend/src/navigation/Navigation.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function Navigation() {
2121
<header className="body-font print:hidden">
2222
<div className="container mx-auto flex flex-wrap p-5 mb-8 flex-col md:flex-row items-center justify-between border-b-2 border-gray-600">
2323
<div className="flex title-font font-medium items-center mb-4 md:mb-0 space-x-2">
24-
<Link to="/">
25-
<span className="text-xl hover:text-gray-500 hover:underline">Group Challenge</span>
24+
<Link id="home-link" to="/">
25+
<span className="text-xl hover:text-gray-500 dark:hover:text-gray-400">Group Challenge</span>
2626
</Link>
2727
<Link to="/changelog" title="Changelog">
2828
<span className="text-sm font-bold pr-4 hover:text-gray-500 hover:underline">{VERSION}</span>

0 commit comments

Comments
 (0)