Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutikapoor08 committed Oct 18, 2019
1 parent 11dfbed commit 90386c9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 116 deletions.
4 changes: 2 additions & 2 deletions public/manifest.json
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "hooks state management",
"name": "State management using hooks and graphql",
"icons": [
{
"src": "favicon.ico",
Expand Down
88 changes: 0 additions & 88 deletions src/.idea/workspace.xml

This file was deleted.

12 changes: 6 additions & 6 deletions src/components/AddSong.js
Expand Up @@ -7,7 +7,7 @@ import Context from '../context';

const AddSong = () => {
const [name, setName] = useState("");
const [actor, setActor] = useState("");
const [artist, setArtist] = useState("");
const [lyrics, setLyrics] = useState("");
const {dispatch} = useContext(Context);

Expand All @@ -18,24 +18,24 @@ const AddSong = () => {
e.preventDefault();
addSong({ variables: { song: {
name,
actor,
artist,
lyrics
}}
});
const songs = [{name, actor, lyrics}];
const songs = [{name, artist, lyrics}];
dispatch({type: "ADD_CONTENT", payload: songs});
setName("");
setLyrics("");
setActor("");
setArtist("");
}}>
<legend>Add a new song</legend>
<div className={'mui-textfield mui-textfield--float-label width-small'}>
<input value={name} type="text" name="name" onChange={e => setName(e.target.value)} />
<label>Name</label>
</div>
<div className="mui-textfield mui-textfield--float-label width-small">
<input value={actor} type="text" name="actor" onChange={e => setActor(e.target.value)}/>
<label>Singer</label>
<input value={artist} type="text" name="artist" onChange={e => setArtist(e.target.value)}/>
<label>Artist</label>
</div>
<div className="mui-textfield mui-textfield--float-label">
<textarea value={lyrics} type="text" name="lyrics" onChange={e => setLyrics(e.target.value)}/>
Expand Down
19 changes: 4 additions & 15 deletions src/components/Home.js
@@ -1,7 +1,7 @@
import React, { useEffect, useContext} from "react";
import {graphql} from "react-apollo";
import Container from "muicss/lib/react/container";
import { singleActor } from '../graphql/queries'
import { singleArtist } from '../graphql/queries'
import AddSong from './AddSong'
import Context from '../context'

Expand All @@ -23,20 +23,9 @@ const Home = ({ data: { loading, error, songs } }) => {
<div key={`song-${song.id}`} className={'song-list-item'}>
<div className={'text-wrapper'}>
<h1>{song.name}</h1>
<h3>{song.actor}</h3>
<h3>{song.artist}</h3>
<p>{song.lyrics}</p>
</div>
{/*<Mutation*/}
{/*mutation={DELETE_SONG}>*/}
{/*{ (deleteSong) =>*/}
{/*<button onClick={() => {*/}
{/*dispatch({type: "DELETE_CONTENT", payload: {id: song.id}});*/}
{/*deleteSong({variables: {id: {id: song.id}}});*/}
{/*}}>*/}
{/*Remove song*/}
{/*</button>*/}
{/*}*/}
{/*</Mutation>*/}
</div>
))}
</div>
Expand All @@ -47,10 +36,10 @@ const Home = ({ data: { loading, error, songs } }) => {
};


export default graphql(singleActor, {
export default graphql(singleArtist, {
options: ({ match }) => ({
variables: {
actor: match.params.slug,
artist: match.params.slug,
name: match.params.slug,
lyrics: match.params.slug
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/mutations.js
Expand Up @@ -4,7 +4,7 @@ export const ADD_SONG = gql`
mutation AddSong($song: SongCreateInput!) {
createSong(data: $song) {
name
actor
artist
lyrics
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/graphql/queries.js
@@ -1,11 +1,11 @@
import gql from "graphql-tag";

export const singleActor = gql`
query songs($actor: String) {
songs(where: { actor: $actor }) {
export const singleArtist = gql`
query songs($artist: String) {
songs(where: { artist: $artist }) {
name
id
actor
artist
lyrics
}
}
Expand Down

0 comments on commit 90386c9

Please sign in to comment.