Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat ksm 3154 deliver ssr p2 #12

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,31 @@ webpack 5.73.0
Building and running
See package.json for the details of the commands below.

To run without SSR:
## This project contains a call to the Giphy Gif Api and requires an api key.

+ To build entire project, express to deliver react: `$ yarn build`
You can get your own Giphy api key at : [https://developers.giphy.com/docs/api#quick-start-guide](https://developers.giphy.com/docs/api#quick-start-guide)


## To run the API that serves Sailor Moon universe data

+ In the CLI, `$ yarn sailorserver`
+ The endpoint can be found at [http://localhost:3001/](http://localhost:3001/)

## To run client side rendering (csr):

+ To build the project in csr mode: `$ yarn build:csr`

+ To build the project in csr mode for development: `$ yarn watch:csr`

+ To deliver the project in csr mode: `$ yarn start:csr`


## To run server side rendering (ssr):

+ To build the project in ssr mode: `$ yarn build:csr`

+ To deliver the project in ssr mode: `$ yarn start:csr`

+ To start entire project, express server delivers react frontend: `$ yarn start`

## Redis and redis-cli
### KSM-3867 Deliverables
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": true,
"license": "unlicensed",
"scripts": {
"sailorserver": "node api/api-server.js",
"build:csr": "webpack --mode=development --config webpack/webpack.client.config.js",
"watch:csr": "webpack --mode=development --watch --config webpack/webpack.client.config.js",
"start:csr": "node servers/server.csr.js",
Expand Down
1 change: 0 additions & 1 deletion react-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>My React App</title>
<link rel='icon' type='image/png' href='./src/icons8-ufo-emoji-32.png' />
</head>
<body>
<div id='root'></div>
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styles from './Header.scss'
export default function Header () {
return (
<div className={styles.rootHeader}>
<h1 className={styles}>KQED Initial Training Project - Pamela Gilmour</h1>
<h1>KQED Initial Training Project - Pamela Gilmour</h1>
<nav>
<ul>
<li>
Expand Down
33 changes: 21 additions & 12 deletions react-app/src/components/HexPicker/HexPicker.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import {
randomize,
Expand All @@ -12,17 +12,30 @@ export default function HexPicker () {

const dispatch = useDispatch()

const applyColor = () => {
document.body.style.background = generatedValue
const applyColor = (color) => {
document.body.classList.remove('oppositeFontColor')
document.body.style.background = color
}
const applyFontColor = () => {
document.body.style.color = fontValue
const applyFontColor = (color) => {
document.body.classList.add('oppositeFontColor')
document.body.style.color = color
}

// console.log('generatedValue:', generatedValue)
// console.log('fontValue:', fontValue)
applyColor()
applyFontColor()

useEffect(() => {
dispatch(oppositeColor())
applyColor(generatedValue)
applyFontColor(fontValue)
}, [dispatch, generatedValue, fontValue])

const handleButtonClick = () => {
dispatch(randomize())
dispatch(oppositeColor())
// applyColor(generatedValue)
// applyFontColor(fontValue)
}

return (
<div className={style}>
Expand All @@ -31,11 +44,7 @@ export default function HexPicker () {
<p>{generatedValue}</p>
<button
aria-label='Generate random RGB value'
onClick={() => {
dispatch(randomize())
dispatch(oppositeColor())
}
}
onClick={handleButtonClick}
>
Click to Generate a Random RBG Value
</button>
Expand Down
4 changes: 4 additions & 0 deletions react-app/src/components/HexPicker/HexPicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ button {

p {
padding: 15px;
}

.oppositeFontColor {
color: #fff;
}
21 changes: 15 additions & 6 deletions react-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import { store } from './slices/store'
import App from './App'

const rootElement = document.getElementById('root')
const root = createRoot(rootElement)

root.render(
<Provider store={store}>
<App />
</Provider>
)
if(typeof window !== 'undefined' && rootElement) {
const root = createRoot(rootElement)

root.render(
<Provider store={store}>
<App />
</Provider>
)
} else {
const SSRPlaceholder = () => (
<div> Server Side Rendering Placeholder</div>
)

createRoot(<SSRPlaceholder />).render()
}
2 changes: 1 addition & 1 deletion webpack/webpack.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports={
new HtmlWebpackPlugin({
template: './react-app/index.html',
publicPath: '/',
favicon: './react-app/src/icons8-ufo-emoji-32.png'
favicon: './react-app/icons8-ufo-emoji-32.png'
}),
new ESLintPlugin({
extensions:['js', 'jsx', 'json']
Expand Down