Skip to content

Commit

Permalink
Initial janky way to change CSS per jam
Browse files Browse the repository at this point in the history
  • Loading branch information
Willdotwhite committed Mar 20, 2024
1 parent 6e4e11f commit 73a136d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/src/main/kotlin/com/gmtkgamejam/models/jams/Jam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class Jam(
val jamId: String
val jamId: String,
val styles: Map<String, String>,
)
5 changes: 5 additions & 0 deletions ui/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Logout} from "./pages/logout/Logout.tsx";
import Footer from "./pages/components/Footer.tsx";
import {About} from "./pages/about/About.tsx";
import {Index} from "./pages/index/Index.tsx";
import {JamSpecificStyling} from "./common/components/JamSpecificStyling.tsx";

const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -21,9 +22,13 @@ const queryClient = new QueryClient({
});

export const AppRoutes: React.FC = () => {

// document.documentElement.style.setProperty('--tile-secondary', '#A0BE11')

return (
<BrowserRouter>
<ReactQuerySiteWrapper>
<JamSpecificStyling />
<Header />
<div style={{
width: '100%',
Expand Down
26 changes: 26 additions & 0 deletions ui/src/common/components/JamSpecificStyling.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, {useEffect, useState} from "react";
import {useMatch} from "react-router-dom";

export const JamSpecificStyling: React.FC = () => {
const jamId = useMatch("/:jamId/:postId?")?.params.jamId!!;
const [activeTheme, setActiveTheme] = useState()
console.log(jamId)

useEffect(() => {
if (!jamId) return

fetch(`${import.meta.env.VITE_API_URL}/jams`)
.then(res => res.json())
.then(s => s.find(x => x['jamId'] === jamId))
.then(jam => setActiveTheme(jam))
.then(jam => localStorage.setItem(`theme_${jamId}`, JSON.stringify(jam)))

}, [jamId])

if (!activeTheme) return

const styles = Object.entries(activeTheme['styles'])
styles.map(style => document.documentElement.style.setProperty(style[0], style[1]))

return (<></>)
}
3 changes: 2 additions & 1 deletion ui/src/common/components/PostTile.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@layer components {
.c-post-tile {
@apply bg-grey-500 border-2 border-neutral-900 rounded-xl p-4 flex flex-col gap-1 lg:min-h-[560px];
background-color: var(--tile-secondary);
@apply border-2 border-neutral-900 rounded-xl p-4 flex flex-col gap-1 lg:min-h-[560px];

.post-tile__header {
@apply flex justify-between min-w-0;
Expand Down
5 changes: 5 additions & 0 deletions ui/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@

/* Utilities */
@import "tailwindcss/utilities";


:root {
--tile-secondary: theme('colors.grey-500');
}
1 change: 1 addition & 0 deletions ui/src/pages/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const ToggleBookmarks: React.FC = () => {
}

const MyPostButton: React.FC = () => {
// TODO: Get from storage somewhere
const jamId = useMatch("/:jamId/:postId?")?.params.jamId;

const userInfo = useUserInfo();
Expand Down

0 comments on commit 73a136d

Please sign in to comment.