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
const posts = (state = [], action) => { | |
let posts = []; | |
switch(action.type){ | |
case VIEW_ALL: | |
// TODO: Return all posts | |
return posts; | |
case SEARCH_POST: | |
// TODO: Return posts matched in search | |
return posts; | |
default: |
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
// React and other imports... | |
import { connect } from 'react-redux'; | |
import { viewAll, searchPost } from './actions'; | |
class App extends Component { | |
// Code for our App component... | |
} | |
// Mapping state to props | |
function mapStateToProps(state){ |
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
componentDidMount(){ | |
fetch("https://jsonbin.io/b/59f721644ef213575c9f6531") | |
.then( response => response.json()) | |
.then( data => { this.setState({posts: data})}); | |
} |
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
let posts = '', postLinks = ''; | |
if(this.state.posts && this.state.posts.data){ | |
posts = this.state.posts.data.map(post => {return <Post post={post} key={"post_"+post.id}/>;}); | |
postLinks = this.state.posts.data.map(post => {return <a href={"#"+post.id} key={"post_link_"+post.id} className="button">{post.title}</a>}) | |
} |
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
// Import necessary packages... | |
class App extends Component { | |
// Constructor and methods... | |
// Mounting the component causes an action | |
componentDidMount(){ | |
fetch("https://jsonbin.io/b/59f721644ef213575c9f6531") | |
.then( response => response.json()) | |
.then( data => { | |
let posts = { |
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
const posts = (state = {data: [], selected: []}, action) => { | |
let posts = {data: [], selected: []}; | |
switch(action.type){ | |
case VIEW_ALL: | |
Object.assign(posts.data, state.data); | |
posts.selected = []; | |
return posts; | |
case SEARCH_POST: | |
Object.assign(posts.data, state.data); | |
let search = new JsSearch.Search('date-added'); |
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
<input type="search" className="searchBox" onChange={event => { | |
if(event.currentTarget.value) this.searchPost(event.currentTarget.value); | |
else this.viewAll(); | |
}}/> |
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
{'code': '<div class="row">\r\n' | |
' <div class="card">\r\n' | |
' <div class="section">\r\n' | |
' <h3>Card Title</h3>\r\n' | |
' <p>Card content...</p>\r\n' | |
' </div>\r\n' | |
' </div>\r\n' | |
' <div class="card">\r\n' | |
' <div class="section">\r\n' | |
' <h3>Card Title</h3>\r\n' |
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
{ | |
"lang": "en", | |
"title": "Index", | |
"stylesheets": ["./css/style.css"], | |
"scripts": ["./js/main.js"], | |
"charset": "utf-8", | |
"description": "This is a page", | |
"keywords": "page, sample", | |
"author": "None", | |
"favicon": "./images/favicon.png", |
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
const copyToClipboard = str => { | |
const el = document.createElement('textarea'); | |
el.value = str; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
}; |