This file contains hidden or 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
class LocationSerializer | |
include FastJsonapi::ObjectSerializer | |
attributes :name | |
end |
This file contains hidden or 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
class LocationsController < ApplicationController | |
def index | |
locations = Location.page(params[:page]) | |
render_json(serializer, locations) | |
end | |
def show | |
location = Location.find params[:id] | |
render_json(serializer, location) | |
end |
This file contains hidden or 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
class ApplicationController < ActionController::API | |
private | |
def render_json(serializer, obj, options={}) | |
if obj.class.name == 'ActiveRecord::Relation' | |
return render_collection(serializer, obj, options) | |
end | |
render_record(serializer, obj, options) |
This file contains hidden or 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
100.times do |x| | |
loc = Location.create(name: Faker::Address.street_name) | |
puts "created #{loc.name}" | |
end |
This file contains hidden or 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
import React, { useState } from "react"; | |
import "./PaintGrid.css"; | |
import { PainterContext } from "../contexts/PainterContext"; | |
function PaintGrid(_) { | |
const { colors, color } = React.useContext(PainterContext); | |
const rows = 10; | |
const cols = 10; |
This file contains hidden or 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
import React from "react"; | |
import { PainterContext } from '../contexts/PainterContext'; | |
function ColorPreview(props) { | |
const {color} = React.useContext(PainterContext); | |
return ( | |
<div className="colorPreview">Color selected: {color.name}</div> | |
); | |
} |
This file contains hidden or 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
import React from "react"; | |
import { PainterContext } from "../contexts/PainterContext"; | |
function ColorPicker(_) { | |
const { colors, setColor } = React.useContext(PainterContext); | |
const colorOption = color => { | |
return ( | |
<div | |
key={color.name} |
This file contains hidden or 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
import React from "react"; | |
import "./App.css"; | |
import ColorPicker from "./ColorPicker"; | |
import PaintGrid from "./PaintGrid"; | |
import ColorPreview from "./ColorPreview"; | |
import { colors, PainterContext } from "../contexts/PainterContext"; | |
function App() { | |
// use state for color and setColor | |
const [color, setColor] = React.useState(colors[0]); |
This file contains hidden or 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
import React from "react"; | |
// define list of colors | |
export const colors = [ | |
{ name: "white", hex: "#fff" }, | |
{ name: "black", hex: "#000" }, | |
{ name: "red", hex: "#ff0000" }, | |
{ name: "green", hex: "#00ff00" }, | |
{ name: "blue", hex: "#0000ff" }, | |
{ name: "pink", hex: "#ffa6c9" }, |
This file contains hidden or 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import 'bulma/css/bulma.css' | |
import App from './components/App'; | |
ReactDOM.render(<App />, document.getElementById('root')); |