-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): Refactor our config for proper typechecking (#29)
This pr refactors our config file to abstract it via a `config.ts` file, instead of importing `config.yaml` you will now import `config.ts`, This file ensures our yaml is properly typechecked and allows us to provide real types, meaning we can have a single source of truth for things like enum values. While writing this pr, I noticed that we do not use the same casing throughout our config so I refactored things so they are logical, additionally I went through and simplified some conmponents making sure their usage of our config reflects the actual config layout. The new standard for our config is `snake_case` as it is common in `yaml`. I formatted `config.ts` with a bunch of spaces around our file validation as if you mess up the config it shows the validation line instead of the config error line sadly (I have no way of really fixing this), but this makes the error less confusing for non developers. This pr closes: #25
- Loading branch information
1 parent
1e21113
commit ecc80b0
Showing
14 changed files
with
746 additions
and
305 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,24 @@ | ||
// CSS | ||
import styles from '../styles/components/EventBanner.module.scss'; | ||
// Config | ||
import config from '../config.yaml'; | ||
import { website_config } from '../config'; | ||
import ReactMarkdown from 'react-markdown'; | ||
|
||
interface Props { | ||
color?: string; | ||
contextKey?: keyof typeof config; | ||
} | ||
|
||
export default function EventBanner({ | ||
color = 'event-banner', | ||
contextKey = 'bannerInfo', | ||
}: Props) { | ||
const bannerInfo = config[contextKey]; | ||
export default function EventBanner({ color = 'event-banner' }: Props) { | ||
const { banner_text } = website_config; | ||
if (banner_text == undefined) return null; | ||
if (banner_text.length == 0) return null; | ||
|
||
if (contextKey === 'bannerInfo') { | ||
const bannerInfoTyped = bannerInfo as typeof config.bannerInfo; | ||
if (!bannerInfoTyped || bannerInfoTyped.hidden) { | ||
return null; | ||
} | ||
|
||
const eventMarkdown = bannerInfoTyped.text; | ||
|
||
if (!eventMarkdown) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.EventBanner} style={{ backgroundColor: color }}> | ||
{/* Event Content */} | ||
<div className={styles.EventContent}> | ||
<ReactMarkdown className={styles.Markdown}> | ||
{eventMarkdown} | ||
</ReactMarkdown> | ||
</div> | ||
return ( | ||
<div className={styles.EventBanner} style={{ backgroundColor: color }}> | ||
{/* Event Content */} | ||
<div className={styles.EventContent}> | ||
<ReactMarkdown className={styles.Markdown}>{banner_text}</ReactMarkdown> | ||
</div> | ||
); | ||
} | ||
|
||
return null; | ||
</div> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.