Skip to content

Instantly share code, notes, and snippets.

@DevNinja272
DevNinja272 / index.js
Created September 20, 2020 16:39
client/src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import Header from "./Components/Header";
import 'bootstrap/dist/css/bootstrap.min.css';
ReactDOM.render(
<React.StrictMode>
@DevNinja272
DevNinja272 / .gitignore
Created September 18, 2020 13:51
General .gitignore
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
@DevNinja272
DevNinja272 / WeatherForm.jsx
Last active September 21, 2020 04:37
client/src/Components/WeatherForm.jsx
// imports
class WeatherForm extends Component {
// default state values
// componentDidMount()
// refreshSaveWeather()
// onChange()
// saveFormData()
// saveToLocalStorage()
@DevNinja272
DevNinja272 / server.js
Last active September 24, 2020 14:39
server/server.js
// imports
const path = require('path');
// use body parser to get data from POST requests
// Use API routes from the api folder
// If in production, then use static frontend build files.
if (process.env.NODE_ENV === 'production') {
// Serve any static files
{
"name": "mern-weather-app",
"scripts": {
"dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
"heroku-postbuild": "cd client/src && npm install && npm run build"
},
}
@DevNinja272
DevNinja272 / WeatherForm.jsx
Last active September 23, 2020 16:41
client/src/Components
// imports
import {connect} from "react-redux";
import {saveZipCode, saveWeatherData, saveTemperature, updateHistory} from "../actions";
class WeatherForm extends Component {
// default state values
// componentDidMount()
refreshSavedWeather = () => {
if (localStorage.getItem("zipCode")) {
@DevNinja272
DevNinja272 / index.js
Created September 5, 2020 01:10
client/src
// other imports
...
// Adding redux and reducers
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import rootReducer from './reducers'
// Creates our store to use our reducers and the chrome extension to debug the redux store
const store = createStore(
// Get initial state from the previously saved data in local storage
let getHistoryFromLocal = () => {
let value = localStorage.getItem('WeatherHistory')
return JSON.parse(value) || [];
}
// Maintain a history list of queried weather data of 10
let getUpdatedHistory = (history, value) => {
let updateList = [...history];
if (updateList.length >= 10) {
@DevNinja272
DevNinja272 / index.js
Created September 4, 2020 21:37
client/src/actions
export const saveZipCode = (zipCode) => {
return {
type: "SAVE_ZIP",
payload: zipCode
}
}
export const saveWeatherData = (data) => {
return {
type: "SAVE_WEATHER_DATA",
@DevNinja272
DevNinja272 / WeatherForm.jsx
Last active September 23, 2020 16:28
client/src/Components/WeatherForm.jsx
// other imports
import axios from 'axios';
class WeatherForm extends Component {
// default state values
componentDidMount() {
this.refreshSavedWeather();
}