-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial janky way to change CSS per jam
- Loading branch information
1 parent
6e4e11f
commit 08a2435
Showing
8 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, {useEffect, useState} from "react"; | ||
import {useMatch} from "react-router-dom"; | ||
|
||
type Jam = { | ||
jamId: String, | ||
styles: Map<String, String>, | ||
} | ||
|
||
export const JamSpecificStyling: React.FC = () => { | ||
const jamId = useMatch("/:jamId/:postId?")?.params.jamId!!; | ||
const [activeTheme, setActiveTheme] = useState<Jam>() | ||
|
||
// TODO: Cache and avoid refetch | ||
// TODO: TTL for styles? | ||
useEffect(() => { | ||
if (!jamId) return | ||
|
||
fetch(`${import.meta.env.VITE_API_URL}/jams`) | ||
.then(res => res.json() as Promise<Jam[]>) | ||
.then(s => s.find(x => x.jamId === jamId)) | ||
.then(jam => setActiveTheme(jam)) | ||
|
||
}, [jamId]) | ||
|
||
if (!activeTheme) return | ||
|
||
localStorage.setItem(`theme_${jamId}`, JSON.stringify(activeTheme)) | ||
|
||
const styles = Object.entries(activeTheme['styles']) | ||
styles.map(style => document.documentElement.style.setProperty(style[0], style[1])) | ||
|
||
return (<></>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters