Skip to content

Commit

Permalink
Use jamId across the UI for user data/search
Browse files Browse the repository at this point in the history
  • Loading branch information
Willdotwhite committed Mar 18, 2024
1 parent 25f9648 commit 6e4e11f
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
8 changes: 5 additions & 3 deletions api/src/main/kotlin/com/gmtkgamejam/models/posts/PostItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlin.math.abs
@Serializable
data class PostItem (
val id: String,
val jamId: String,

var author: String,
var authorId: String,
Expand All @@ -26,11 +27,11 @@ data class PostItem (
var languages: Set<String>,

// Reported by the flag icon for inappropriate content
var reportCount: Int,
var reportCount: Int,

// Optional flag for users to report the linked profile as
// unabled to be contacted by discord CTA
var unableToContactCount: Int,
var unableToContactCount: Int,

// Managed by DB
val createdAt: String,
Expand All @@ -44,6 +45,7 @@ data class PostItem (
val currentDatetime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
return PostItem(
abs(ThreadLocalRandom.current().nextLong()).toString(), // We need to handle as string, otherwise we lose precision in JS
dto.jamId,
dto.author,
dto.authorId,
dto.description.take(2000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class PostItemCreateDto(
var jamId: String,
var author: String,
var authorId: String,
var description: String,
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/kotlin/com/gmtkgamejam/routing/PostRoutes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ fun Application.configurePostRouting() {
fun getFilterFromParameters(params: Parameters): List<Bson> {
val filters = mutableListOf(PostItem::deletedAt eq null)

params["jamId"]?.also { filters.add(PostItem::jamId eq it) }

params["description"]?.split(',')
?.filter(String::isNotBlank) // Filter out empty `&description=`
?.map { it -> it.trim() }
Expand Down
30 changes: 30 additions & 0 deletions db/seed/data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"id": "2243524637046795535",
"jamId": "gmtk",
"author": "Test User 1",
"authorId": "7525165619697425159",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -56,6 +57,7 @@
},
{
"id": "8171413695520383328",
"jamId": "gmtk",
"author": "Test User 2",
"authorId": "8139724221518853204",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -111,6 +113,7 @@
},
{
"id": "3467599556049129825",
"jamId": "gmtk",
"author": "Test User 3",
"authorId": "2495234518290306087",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -151,6 +154,7 @@
},
{
"id": "3932819677974080201",
"jamId": "gmtk",
"author": "Test User 4",
"authorId": "8691402460769307573",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -205,6 +209,7 @@
},
{
"id": "8202447307439347147",
"jamId": "gmtk",
"author": "Test User 5",
"authorId": "8355868993643553359",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -252,6 +257,7 @@
},
{
"id": "2293478098918011717",
"jamId": "gmtk",
"author": "Test User 6",
"authorId": "5234965564238203591",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -310,6 +316,7 @@
},
{
"id": "7449354821526072398",
"jamId": "gmtk",
"author": "Test User 7",
"authorId": "5103981228782787972",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -370,6 +377,7 @@
},
{
"id": "2454663018965217634",
"jamId": "gmtk",
"author": "Test User 8",
"authorId": "960422998614462019",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -416,6 +424,7 @@
},
{
"id": "7573926876511685595",
"jamId": "gmtk",
"author": "Test User 9",
"authorId": "7592981617433289892",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -462,6 +471,7 @@
},
{
"id": "4341578822851919246",
"jamId": "gmtk",
"author": "Test User 10",
"authorId": "4173239783510318730",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -514,6 +524,7 @@
},
{
"id": "8746179433740655746",
"jamId": "gmtk",
"author": "Test User 11",
"authorId": "2374044450843482362",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -579,6 +590,7 @@
},
{
"id": "4896829798315797209",
"jamId": "gmtk",
"author": "Test User 12",
"authorId": "9104132345420036839",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -635,6 +647,7 @@
},
{
"id": "4962844889132790492",
"jamId": "gmtk",
"author": "Test User 13",
"authorId": "8126111049071629371",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -689,6 +702,7 @@
},
{
"id": "8585595655877013872",
"jamId": "gmtk",
"author": "Test User 14",
"authorId": "3173848038308850600",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -749,6 +763,7 @@
},
{
"id": "4206074477782941536",
"jamId": "gmtk",
"author": "Test User 15",
"authorId": "6103318388117282578",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -803,6 +818,7 @@
},
{
"id": "3868187556758833759",
"jamId": "gmtk",
"author": "Test User 16",
"authorId": "7461885373977111808",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -860,6 +876,7 @@
},
{
"id": "3252170414744956313",
"jamId": "gmtk",
"author": "Test User 17",
"authorId": "1688692907457697720",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -920,6 +937,7 @@
},
{
"id": "9191944119323227396",
"jamId": "gmtk",
"author": "Test User 18",
"authorId": "1941497001212565",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -975,6 +993,7 @@
},
{
"id": "500861117951611425",
"jamId": "gmtk",
"author": "Test User 19",
"authorId": "1595781473651861512",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1025,6 +1044,7 @@
},
{
"id": "6251770971902106349",
"jamId": "gmtk",
"author": "Test User 20",
"authorId": "4223760050836342079",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1083,6 +1103,7 @@
},
{
"id": "8623983800042609927",
"jamId": "gmtk",
"author": "Test User 21",
"authorId": "4519010433780847870",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1141,6 +1162,7 @@
},
{
"id": "504420189039268734",
"jamId": "gmtk",
"author": "Test User 22",
"authorId": "2448315933278673380",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1188,6 +1210,7 @@
},
{
"id": "5537605479699170422",
"jamId": "gmtk",
"author": "Test User 23",
"authorId": "9183954359650323425",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1231,6 +1254,7 @@
},
{
"id": "4114392334298773536",
"jamId": "gmtk",
"author": "Test User 24",
"authorId": "3734153961355537818",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1287,6 +1311,7 @@
},
{
"id": "653486846944298853",
"jamId": "gmtk",
"author": "Test User 25",
"authorId": "4027892243559839512",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1337,6 +1362,7 @@
},
{
"id": "8430709049753892661",
"jamId": "gmtk",
"author": "Test User 26",
"authorId": "8834250178710357253",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1399,6 +1425,7 @@
},
{
"id": "3328673452336283938",
"jamId": "gmtk",
"author": "Test User 27",
"authorId": "5747534483382173442",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1450,6 +1477,7 @@
},
{
"id": "7457471871161589268",
"jamId": "gmtk",
"author": "Test User 28",
"authorId": "7555042980585316193",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1489,6 +1517,7 @@
},
{
"id": "1234562409671519908",
"jamId": "gmtk",
"author": "Test User 29",
"authorId": "6534515069908910238",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down Expand Up @@ -1534,6 +1563,7 @@
},
{
"id": "8117932506732235548",
"jamId": "gmtk",
"author": "Test User 30",
"authorId": "3255922032817942029",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse maximus finibus mauris vel dapibus. Aenean sodales sapien nec ullamcorper porta.\nProin quis est eu magna euismod elementum. Aenean volutpat lacinia urna vitae elementum.",
Expand Down
6 changes: 3 additions & 3 deletions ui/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export const AppRoutes: React.FC = () => {
<Route path="/login/authorized" element={<Callback/>}/>
<Route path="/logout" element={<Logout/>}/>

<Route path=":jamId/" element={<JamHome/>}/>
<Route path=":jamId/:postId" element={<Post/>}/>
<Route path=":jamId/my-post" element={<MyPostWrapper/>}/>
<Route path="/:jamId" element={<JamHome/>}/>
<Route path="/:jamId/:postId" element={<Post/>}/>
<Route path="/:jamId/my-post" element={<MyPostWrapper/>}/>

{/* TODO: replace with a proper Not Found page */}
<Route path="*" element={<p>u wot m8</p>}/>
Expand Down
1 change: 1 addition & 0 deletions ui/src/common/models/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Post {
id: string;
jamId: string;
author: string;
authorId: string;
description: string;
Expand Down
6 changes: 4 additions & 2 deletions ui/src/pages/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react";
import {Link, useNavigate, useSearchParams} from "react-router-dom";
import {Link, useMatch, useNavigate, useSearchParams} from "react-router-dom";
import {useUserInfo} from "../../api/userInfo.ts";
import {login} from "../../api/login.ts";
// Probably a better way to manage these
Expand Down Expand Up @@ -94,13 +94,15 @@ const ToggleBookmarks: React.FC = () => {
}

const MyPostButton: React.FC = () => {
const jamId = useMatch("/:jamId/:postId?")?.params.jamId;

const userInfo = useUserInfo();
const myPostQuery = useMyPostQuery();

return (
<Link
className={`header-button ${userInfo.isLoading ? "cursor-not-allowed" : "cursor-pointer"}`}
to="/my-post"
to={`${jamId}/my-post`}
>
<div className="flex items-center h-full">
<img src={myPostIcon} alt={myPostQuery?.data ? "Edit post" : "Create post"} className="h-full inline-block ml-2 my-1 mr-2" style={{ width: "20px", height: "20px" }}/>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/pages/jamhome/JamHome.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import {SearchFormWrapper} from "./components/SearchFormWrapper.tsx";
import {useSearchParams} from "react-router-dom";
import {useParams, useSearchParams} from "react-router-dom";
import {useEffect, useState} from "react";
import {PostTile} from "../../common/components/PostTile.tsx";
import {Onboarding} from "./components/Onboarding.tsx";
Expand All @@ -12,6 +12,8 @@ export const JamHome: React.FC = () => {
const [searchParams, setSearchParams] = useSearchParams();
const [posts, setPosts] = useState<Post[]>([]);
const [isViewingBookmarks, setIsViewingBookmarks] = useState<boolean>(searchParams.get('bookmarked') === "true");

const { jamId } = useParams()
const { token } = useAuth() ?? {};

// Trigger API call every time query string changes
Expand All @@ -21,6 +23,7 @@ export const JamHome: React.FC = () => {
const path = isOnlyBookmarked ? "posts/favourites" : "posts"
setIsViewingBookmarks(isOnlyBookmarked)
searchParams.delete('bookmarked')
searchParams.set("jamId", jamId!! || "any")

const url = new URL(path + "?" + searchParams.toString(), import.meta.env.VITE_API_URL)
const init: RequestInit = {method: "GET", headers: {"Content-Type": "application/json"}}
Expand Down
3 changes: 3 additions & 0 deletions ui/src/pages/mypost/MyPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {Post} from "../../common/models/post.ts";

export const MyPost: React.FC<{
params: FormikProps<Post>,
jamId: string,
author: string,
authorId: string,
hasPost: boolean
}> = ({
params,
jamId,
author,
authorId,
hasPost
Expand All @@ -27,6 +29,7 @@ export const MyPost: React.FC<{
<FieldDescription description={values.description} />

{/* This is jank, improve this later with a look up on submit */}
<Field name="jamId" value={jamId} type="hidden" />
<Field name="author" value={author} type="hidden" />
<Field name="authorId" value={authorId} type="hidden" />

Expand Down
Loading

0 comments on commit 6e4e11f

Please sign in to comment.