Skip to content
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
9 changes: 9 additions & 0 deletions app/controllers/hello_world_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class HelloWorldController < ApplicationController
layout "hello_world"

def index
@hello_world_props = { name: "Stranger" }
end
end
2 changes: 1 addition & 1 deletion app/controllers/homepage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class HomepageController < ApplicationController
layout "home"

def index
@homepage_props = { name: "Stranger" }
@homepage_props = {parks: Park.all}
end
end
7 changes: 7 additions & 0 deletions app/controllers/landingpage_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class LandingpageController < ApplicationController
layout "landing_page"

def index

end
end
25 changes: 25 additions & 0 deletions app/javascript/bundles/HelloWorld/components/HelloWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import PropTypes from 'prop-types';
import React, { useState } from 'react';

const HelloWorld = (props) => {
const [name, setName] = useState(props.name);

return (
<div>
<h3>Hello, {name}!</h3>
<hr />
<form>
<label htmlFor="name">
Say hello to:
<input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
</label>
</form>
</div>
);
};

HelloWorld.propTypes = {
name: PropTypes.string.isRequired, // this is passed from the Rails view
};

export default HelloWorld;
14 changes: 3 additions & 11 deletions app/javascript/bundles/homepage/components/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@
import Sidebar from './Sidebar';

const HomePage = (props) => {
//const parks = props.parks
//const listParks = parks.map((park) =>
// <li key = {park.toString()}>
// {park}
//</li>);
const parks = props.parks
return(
// <ul> listParks</ul>
<main>
<div className = "home" id = "outer-container">
<Sidebar pageWrapId={'page-wrap'} outerContainerId={'outer-container'} />
<Sidebar parks = {parks} pageWrapId={'page-wrap'} outerContainerId={'outer-container'} />
<div id="page-wrap">
<h1>
Welcome to NattyTracker!
{/* This is the main page
{arr.map((num) => {
return <li>{num} </li>
})} */}
</h1>
<h2>
Please click the button in the top-left, and choose a National Park!
Expand All @@ -32,5 +23,6 @@ const HomePage = (props) => {
);
};
HomePage.propTypes = {
parks: PropTypes.array.isRequired
}
export default HomePage;
37 changes: 37 additions & 0 deletions app/javascript/bundles/homepage/components/LandingPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import PropTypes from 'prop-types';
import React from 'react';
import '../../../../assets/stylesheets/homepage.css';
import '../../../../assets/stylesheets/Sidebar.css';

const LandingPage = () => {
return(
<main>
<header>
This is the landing page
{/* insert natty tracker logo here */}
</header>
<body>
<form>
<h1>
Login
</h1>
<div class = "Container">
<label htmlFor="uname"> <b>Username</b></label>
<input type = "text" placeholder="Username" name="uname" required></input>
<button type = "submit"> Login</button>
<label>
<input type = "checkbox" checked = "checked" name="remember"> Remember me </input>
</label>
<br></br> {/*not sure why just </br> doesn't work*/}
<button type = "submit">Sign Up</button>
</div>
</form>
</body>
</main>
);
}

LandingPage.propTypes = {

}
export default LandingPage;
3 changes: 2 additions & 1 deletion app/javascript/bundles/homepage/components/ParkPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const ParkPage = (props) => {
<p> This is the parks page </p>
);
}

ParkPage.propTypes = {

}
export default ParkPage;
54 changes: 28 additions & 26 deletions app/javascript/bundles/homepage/components/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
import React from 'react';
import { slide as Menu } from 'react-burger-menu';

//creates burger menu checkbox
function ParkItems(props){
return <a href = {"/parks/" + props.id}>
<input type = "checkbox" className="menu-item"></input>
<label htmlFor="menu-item"> {props.name} </label>
<br/> <br/>
</a>;
}

export default props => {
// const parks = props.parks

//use first 62 IDs (reduces size by ~95%)
var parks = [];
for(var i = 0; i < 61; i++){ //should probably remove hard coding
parks[i] = props.parks[i];
if(i == 28)
parks[i].name = "Haleakala National Park"; //last "a" in parks[28].name is a special character; will tackle this issue later
}

//parkItems = react elements for each iteration of parks
const parkItems = parks.map((park) =>
<ParkItems key={park.id.toString()} id={park.id} name={park.name}/>
);

return (
<Menu>
<a className="menu-item" href="/">
<Menu>
<a className="menu-item" href="/homepage">
Home
</a>
<br/>
<a className="menu-item" href="/parks/1">
Arcadia
</a>
<br/>
<a className="menu-item" href="/parks/2">
Arches
</a>
<br/>
<a className="menu-item" href="/parks/3">
Badlands
</a>
<br/>
<a className="menu-item" href="/parks/4">
Big Bend
</a>
<br/>
<a className="menu-item" href="/parks/23">
Grand Canyon
</a>
<br/>
<a className="menu-item" href="/parks/60">
Yosemite
</a>

{parkItems} {/* yay */}
</Menu>
);
};

8 changes: 8 additions & 0 deletions app/javascript/packs/hello-world-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ReactOnRails from 'react-on-rails';

import HelloWorld from '../bundles/HelloWorld/components/HelloWorld';

// This is how react_on_rails can see the HelloWorld in the browser.
ReactOnRails.register({
HelloWorld,
});
8 changes: 8 additions & 0 deletions app/javascript/packs/landingpage-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ReactOnRails from 'react-on-rails';

import LandingPage from '../bundles/homepage/components/LandingPage';

// This is how react_on_rails can see the HelloWorld in the browser.
ReactOnRails.register({
LandingPage,
});
2 changes: 2 additions & 0 deletions app/views/hello_world/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello World</h1>
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
24 changes: 24 additions & 0 deletions app/views/layouts/landing_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Natty Tracker</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'landingpage-bundle' %>
</head>

<body>
<header class="main">
<%= image_tag 'logo.png', alt: 'Natty Tracker' %>
<style>
</style>
<h1><%= @page_title %></h1>
<%= button_to "Log Out", logout_path %>
</header>
<main class='<%= controller.controller_name %>'>
<%= yield %>
</main>
</body>
</html>
1 change: 0 additions & 1 deletion app/views/parks/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<p id="notice"><%= notice %></p>

<%= react_component("ParkPage", props: @park_props, prerender = false %>

<head>
<%= stylesheet_link_tag 'application' %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/sessions/test_welcome.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= react_component("LandingPage", props: @landingpage_props, prerender: false) %>
<%= link_to "Enter App", '/homepage' %>
1 change: 0 additions & 1 deletion app/views/sessions/welcome.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
<%= button_to "Login", '/login', method: :get%>

<%= button_to "Sign Up", '/users/new', method: :get%>

<%= link_to "Enter App", '/homepage' %>