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

pulling #1

Open
wants to merge 14 commits into
base: developer
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
63 changes: 56 additions & 7 deletions client/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import request from 'superagent'

export const SHOW_ERROR = 'SHOW_ERROR'
export const RECEIVE_POSTS = 'RECEIVE_POSTS'
export const RECEIVE_TRONALDDUMP = 'RECEIVE_TRONALDDUMP'
export const RECEIVE_NUCKCHORRIS = 'RECIEVE_NUCKCHORRIS'
export const RECEIVE_DADJOKE = 'RECIEVE_DADJOKE'
export const REQUEST_POSTS = 'REQUEST_POSTS'

export const requestPosts = () => {
Expand All @@ -10,27 +12,74 @@ export const requestPosts = () => {
}
}

export const receivePosts = (posts) => {
export const receiveTronaldDump = (quote) => {
return {
type: RECEIVE_POSTS,
posts: posts.map(post => post.data)
type: RECEIVE_TRONALDDUMP,
tronaldDump: quote.value
}
}

export const receiveNuckChorris = (value) => {
return {
type: RECEIVE_NUCKCHORRIS,
nuckChorris: value
}
}

export const receiveDadJoke = (joke) => {
return {
type: RECEIVE_DADJOKE,
dadJoke: joke.joke
}
}



export const showError = (errorMessage) => {
return {
type: SHOW_ERROR,
errorMessage: errorMessage
}
}

export function fetchPosts (subreddit) {

export function fetchTronaldDump () {
return (dispatch) => {
dispatch(requestPosts())
return request
.get(`/api/v1/tronalddump`)

.then(res => {
dispatch(receiveTronaldDump(res.body))
})
.catch(err => {
dispatch(showError(err.message))
})
}
}

export function fetchNuckChorris() {
return (dispatch) => {
dispatch(requestPosts())
return request
.get(`/api/v1/nuckchorris`)
.then(res => {
dispatch(receiveNuckChorris(res.body))
})
.catch(err => {
dispatch(showError(err.message))
})
}
}

export function fetchDadJoke() {
return (dispatch) => {
dispatch(requestPosts())
return request
.get(`/api/v1/reddit/subreddit/${subreddit}`)
.get(`/api/v1/dadjoke`)
.set('Accept', 'application/json')
.then(res => {
dispatch(receivePosts(res.body))
dispatch(receiveDadJoke(res.body))
})
.catch(err => {
dispatch(showError(err.message))
Expand Down
29 changes: 29 additions & 0 deletions client/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import request from "superagent";

const randomQuote = 'https://api.tronalddump.io/random/quote';
const nuckChorris = 'https://geek-jokes.sameerkumar.website/api'
const dadJoke = 'https://icanhazdadjoke.com/search'

export function getQuotes(callback) {
request
.get(randomQuote)
.end((err, res) => {
callback(err, res.body);
});
}

export function getNuck(callback) {
request
.get(nuckChorris)
.end((err, res) => {
callback(err, res.body);
});
}

export function getJoke(callback) {
request
.get(dadJoke)
.end((err, res) => {
callback(err, res.body);
});
}
24 changes: 19 additions & 5 deletions client/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import React from 'react'

import ErrorMessage from './ErrorMessage'
import LoadSubreddit from './LoadSubreddit'
import SubredditList from './SubredditList'
import WaitIndicator from './WaitIndicator'
import LoadTrump from './LoadTrump';
import LoadChuck from './LoadChuck';
import LoadJoke from './LoadJoke';
import Trump from './Trump'
import Chuck from './Chuck'
import Sounds from './Random-Sound'
import Joke from './Joke'

const App = () => (
<div className='app'>
<ErrorMessage />
<LoadSubreddit>
<LoadTrump >
<WaitIndicator />
</LoadSubreddit>
<SubredditList />
</LoadTrump>
<LoadChuck >
<WaitIndicator />
</LoadChuck>
<LoadJoke >
<WaitIndicator />
</LoadJoke>
<Trump />
<Chuck />
<Joke />
<button><Sounds />Yeet</button>
</div>
)

Expand Down
19 changes: 19 additions & 0 deletions client/components/Chuck.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import {connect} from 'react-redux'




const Chuck = ({nuckChorris}) => (
<div>{nuckChorris}</div>
)

const mapStateToProps = (state) => {
return {
nuckChorris: state.nuckChorris
}
}

export default connect(
mapStateToProps
)(Chuck)
21 changes: 21 additions & 0 deletions client/components/Joke.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import {connect} from 'react-redux'




const Joke = ({dadJoke}) => (

<div>{dadJoke}</div>
)

const mapStateToProps = (state) => {

return {
dadJoke: state.dadJoke
}
}

export default connect(
mapStateToProps
)(Joke)
14 changes: 14 additions & 0 deletions client/components/LoadChuck.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import {connect} from 'react-redux'
import {fetchNuckChorris} from '../actions'

const LoadChuck = ({children, dispatch}) => (
<div>
<button onClick={() => dispatch(fetchNuckChorris())}>
Information
</button>
{children}
</div>
)

export default connect()(LoadChuck)
14 changes: 14 additions & 0 deletions client/components/LoadJoke.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import {connect} from 'react-redux'
import {fetchDadJoke} from '../actions'

const LoadJoke = ({children, dispatch}) => (
<div>
<button onClick={() => dispatch(fetchDadJoke())}>
Contact us
</button>
{children}
</div>
)

export default connect()(LoadJoke)
14 changes: 0 additions & 14 deletions client/components/LoadSubreddit.jsx

This file was deleted.

14 changes: 14 additions & 0 deletions client/components/LoadTrump.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import {connect} from 'react-redux'
import {fetchTronaldDump} from '../actions'

const LoadTrump = ({children, dispatch}) => (
<div>
<button onClick={() => dispatch(fetchTronaldDump())}>
Click for Intelligence
</button>
{children}
</div>
)

export default connect()(LoadTrump)
7 changes: 0 additions & 7 deletions client/components/Post.jsx

This file was deleted.

54 changes: 54 additions & 0 deletions client/components/Random-Sound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from "react"


const Sound1 = '/Sound1.mp3'
const Sound2 = '/Sound2.mp3'
const Sound3 = '/Sound3.mp3'
const Sound4 = '/Sound4.mp3'
const Sound5 = '/Sound5.mp3'

const soundArray = [Sound1, Sound2, Sound3, Sound4, Sound5];



class Sounds extends React.Component {
constructor(props) {
super(props)
this.state = {
play: false
};
// this.url = Sound1,
this.url= this.randomSound(),
this.audio = new Audio(this.url)
// this.refreshList = this.refreshList.bind(this)
};

play(audio){
this.setState({
play:true
});
audio.play()
};
randomSound(){
return soundArray[(Math.floor(Math.random()*Math.floor(soundArray.length)))];
}
refreshList(){
var url = this.randomSound()
var audio = new Audio(url)
this.play(audio)

}


render(){
// console.log(this.randomSound())
return(
<div>
<button onClick={this.refreshList.bind(this)}>Yeet</button>
{/* <audio src={this.state.url} type="audio/mp3" autoPlay="true" /> */}
</div>
)
}
}

export default Sounds
4 changes: 2 additions & 2 deletions client/components/SubredditList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const Subreddit = ({subreddits}) => (
{subreddits.map((post, i) =>
<Post
key={i}
title={post.title}
title={tr.title}
/>
)}
</div>
)

const mapStateToProps = (state) => {
return {
subreddits: state.subreddits
tronaldDump: state.tonaldDump
}
}

Expand Down
19 changes: 19 additions & 0 deletions client/components/Trump.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import {connect} from 'react-redux'




const Trump = ({tronaldDump}) => (
<div>{tronaldDump}</div>
)

const mapStateToProps = (state) => {
return {
tronaldDump: state.tronaldDump
}
}

export default connect(
mapStateToProps
)(Trump)
14 changes: 14 additions & 0 deletions client/reducers/dadjoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {RECEIVE_DADJOKE} from '../actions'

function dad (state = [], action) {
console.log(action)
switch (action.type) {
case RECEIVE_DADJOKE:
return action.dadJoke

default:
return state
}
}

export default dad
11 changes: 8 additions & 3 deletions client/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import {combineReducers} from 'redux'

import errorMessage from './error-message'
import subreddits from './subreddits'
import tronaldDump from './tronaldDump'
import nuckChorris from './nuckChorris'
import waiting from './waiting'
import dadJoke from './dadjoke'

export default combineReducers({
errorMessage,
subreddits,
waiting
tronaldDump,
waiting,
nuckChorris,
dadJoke

})
Loading