diff --git a/.env b/.env new file mode 100644 index 0000000..d643a8d --- /dev/null +++ b/.env @@ -0,0 +1 @@ +TESTING=Yay! \ No newline at end of file diff --git a/README.md b/README.md index 7435989..484726b 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,27 @@ -# Pick your own project - -Build an app of your choice. - -- You are free to use any technologies covered so far, but feel free to try new technologies you find interesting. -- Keep it simple. Aim to get the basic functionality working on day one. You can then extend it on days two and three. -- Feel free to use an external API to provide additional functionality to your app. Use an API that either does not have any authentication or uses API keys. -- This is an opportunity to practice the parts you have challenging so far and improve your understanding of them. -- Use pen and paper to draw a diagram of the webpage layout before starting to code. Have a think about what components you will need in advance. -- Use prop-types and stateless components where appropriate. -- Try to use Sass to create a separate stylesheet for each component. -- Try to add some unit testing. Some parts will be easier to test than others, focus on those first. -- Think about how to organise your data in advance -- Make sure your app is responsive -- Commit frequently -- Create pull request at the end -- Demos will be at 4pm on Friday -- Keep it simple - -## Technical notes - -* Run `npm install` after cloning to download all dependencies -* Use `npm run dev -- --watch` to build React -* Use `npm test` or `npm test -- --watchAll` to run tests - -## README - -* Produce a README.md which explains - * what the project does - * what technologies it uses - * how to build it and run it - * any unresolved issues the user should be aware of - -## Inspiration - -- Take a look at [https://public-apis.jeremyfairbank.com/](https://public-apis.jeremyfairbank.com/) or [https://github.com/toddmotto/public-apis](https://github.com/toddmotto/public-apis) for possible APIs to use. - -## Default option - -If you are struggling to think of a project to build. Try to create a Top Trumps using the [Star Wars API](https://swapi.co/) which allows one user to play the game against the computer. - -- On load, fetch all vehicles from [https://swapi.co/api/vehicles/](https://swapi.co/api/vehicles/) end point. -- Randomise the cards and deal half to player and half to computer. -- Display top card to user -- Allow user to pick an attribute from their card such as `cost_in_credits`, `length`, `max_atmosphering_speed`, `crew`, `passengers`, `cargo_capacity`. -- If the value for chosen attribute is higher on the user's card than on computer's top card, they win the computer's card and it should be taken from computer's deck and added to the bottom of the user's deck. If the attribute is higher on the computer's top card, then user's card should be taken from the user's deck and added to the bottom of computer's deck. -- Game continues until either user or computer has all the cards. -- Implement some features of your choosing. +![Screenshot](./static/exquisite-corpse-1.png) + +# Exquisite Corpse + +Exquisite corpse (_cadavre exquis_ in French) is a game invented by the Surrealists aimed at stimulating creative response. The method involves the collection and assemblage of generated words or images, according to an agreed rule (in this case “Adjective-Noun”). + +This game seeks to mimic the original by randomly generating lists of words, selected by type (adjective/adverb - noun/verb) and combining the results to create unique combinations. Intriguing combinations may then be chosen for 'workshopping' - with a timer allowing 5 minutes \* of free-flow writing. + +### Features + +- "random" endpoint on API is used to fetch 3 cycles of words, which the user may select by type - adjective/adverb, noun/verb +- local storage is used to select generatedword combinations for workshopping (may be added or deleted from selected stock) +- timer set on adding word combo to the workshop textarea +- css classes (with animation) indicate when word combo has been added, and when the timer is reaching end + +**The app is currently under development:** + +- Add descriptions as tooltips to generated word lists - this requires rebuild of word list arrays as objects with keys word: and definition, so as to pull in definition with Fetch. +- Textarea functionality set to fade… whenever user pauses +- Currently desktop-oriented design; address UX for mobile usage - server a different view for writing +- Resets required for select menus + +### Looking forward + +- Develop using GraphQL API approach, with OED + +\* set to 10s for testing! diff --git a/index.html b/index.html index f8102eb..c6176b5 100644 --- a/index.html +++ b/index.html @@ -4,11 +4,15 @@ - - YouJuke + + + + + Exquisite Corpse -
+ +
diff --git a/package-lock.json b/package-lock.json index a9fe824..404a44b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4181,6 +4181,11 @@ "domelementtype": "1" } }, + "dotenv": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.1.0.tgz", + "integrity": "sha512-/veDn2ztgRlB7gKmE3i9f6CmDIyXAy6d5nBq+whO9SLX+Zs1sXEgFLPi+aSuWqUuusMfbi84fT8j34fs1HaYUw==" + }, "duplexer3": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", @@ -8056,9 +8061,9 @@ } }, "merge": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/merge/-/merge-1.2.0.tgz", - "integrity": "sha1-dTHjnUlJwoGma4xabgJl6LBYlNo=", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/merge/-/merge-1.2.1.tgz", + "integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==", "dev": true }, "merge-stream": { @@ -9872,11 +9877,10 @@ "dev": true }, "prop-types": { - "version": "15.6.1", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz", - "integrity": "sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==", + "version": "15.6.2", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", + "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", "requires": { - "fbjs": "^0.8.16", "loose-envify": "^1.3.1", "object-assign": "^4.1.1" } @@ -10063,6 +10067,11 @@ "prop-types": "^15.6.0" } }, + "react-timer-machine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/react-timer-machine/-/react-timer-machine-1.0.1.tgz", + "integrity": "sha1-0IZrq+/ePZhEpBbC8yzeN60avpg=" + }, "read-chunk": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-2.1.0.tgz", @@ -12512,6 +12521,11 @@ "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", "dev": true }, + "timer-machine": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/timer-machine/-/timer-machine-1.1.0.tgz", + "integrity": "sha1-xm08Im7FOuSPVL3APEAv6YQGR/4=" + }, "timers-browserify": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-2.0.10.tgz", diff --git a/package.json b/package.json index 02dece7..998569d 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,12 @@ }, "dependencies": { "classnames": "^2.2.6", - "prop-types": "^15.6.1", + "dotenv": "^6.1.0", + "prop-types": "^15.6.2", "react": "^16.2.0", - "react-dom": "^16.2.0" + "react-dom": "^16.2.0", + "react-timer-machine": "^1.0.1", + "timer-machine": "^1.1.0" }, "devDependencies": { "babel-jest": "^22.4.1", diff --git a/src/components/App.js b/src/components/App.js index a4aaba8..6e584ad 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,19 +1,111 @@ -import React from 'react'; +// https://wordsapiv1.p.mashape.com/words/?partOfSpeech=noun +// https://wordsapiv1.p.mashape.com/words/?partOfSpeech=adjective -import '../styles/components/app.scss'; +import React from "react"; +import Generate from "./Generate"; +import Favourites from "./Favourites"; -class App extends React.Component { +import "../styles/base/base.scss"; +import "../styles/components/app.scss"; - constructor(){ +class App extends React.Component { + constructor() { super(); + this.state = { + type1Result: [], + type2Result: [], + favourites: [] + }; + this.receiveType = this.receiveType.bind(this); + this.addFavourites = this.addFavourites.bind(this); + this.removeFromFavourites = this.removeFromFavourites.bind(this); + } + + // want to add this into the fetch content.results[0].definition + + fetchWords(type, source) { + let tempArr = []; + const wordsUrl = `https://wordsapiv1.p.mashape.com/words/?partOfSpeech=${type}&random=true`; + + for (let i = 0; i < 3; i++) { + fetch(wordsUrl, { + headers: { + "X-Mashape-Key": "wZCRY1mr7wmsh03nJhT5o7UZZ6uYp16uOdRjsnMQ91Z2XQEGFb", + "X-Mashape-Host": "wordsapiv1.p.mashape.com" + } + }) + .then(response => response.json()) + .then(content => { + tempArr = tempArr.concat([content.word]); + if (source === "type1") { + this.setState({ type1Result: tempArr }); + } + if (source === "type2") { + this.setState({ type2Result: tempArr }); + } + }); + } + } + + receiveType(type, source) { + this.fetchWords(type, source); + } + + addFavourites(corpseitem) { + const favourites = this.state.favourites.concat(corpseitem); + this.setState({ + favourites: favourites + }); + window.localStorage.setItem("favourites", favourites); } - render(){ + removeFromFavourites(corpseitem) { + const filteredFavourites = this.state.favourites.filter( + currentFavourite => { + return currentFavourite !== corpseitem; + } + ); + this.setState({ + favourites: filteredFavourites + }); + } + + render() { return ( -
- App goes here +
+
+

Exquisite Corpse

+
+

+ Exquisite corpse (cadavre exquis in French) is a game + invented by the Surrealists aimed at stimulating creative + response. The method involves the collection and assemblage of + generated words or images, according to an agreed rule (in this + case “Adjective-Noun”). +

+

+ This game seeks to mimic the original by randomly generating lists + of adjectives and nouns and combining the results to create unique + combinations. Intriguing combinations may then be chosen for + 'workshopping' – 5 minutes of free-flow writing. +

+
+
+ +
+ + + +
- ) + ); } } diff --git a/src/components/Favourite.js b/src/components/Favourite.js new file mode 100644 index 0000000..067432e --- /dev/null +++ b/src/components/Favourite.js @@ -0,0 +1,38 @@ +import React from "react"; +import TimerMachine from "./TimerMachine"; +import cx from "classnames"; + +import "../styles/components/favourite.scss"; + +class Favourite extends React.Component { + constructor() { + super(); + this.state = { active: false }; + this.handleClick = this.handleClick.bind(this); + } + + handleClick(event) { + this.setState({ + active: !this.state.active + }); + } + + render() { + const favouriteclasses = cx("workshop__favourite", { + active: this.state.active + }); + + return ( +
  • +

    + + {this.props.favourite} + +

    + {this.state.active ? : null} +
  • + ); + } +} + +export default Favourite; diff --git a/src/components/Favourites.js b/src/components/Favourites.js new file mode 100644 index 0000000..ebbd477 --- /dev/null +++ b/src/components/Favourites.js @@ -0,0 +1,33 @@ +import React from "react"; +import Favourite from "./Favourite"; +import "../styles/components/favourites.scss"; + +function Favourites({ favourites }) { + return ( +
    +

    Workshop

    +
      +
    1. + Generate nouns and adjectives to create a list of + ‘exquisite corpses’ +
    2. +
    3. + appealing exquisite corpses to + the workshop area +
    4. +
    5. + Select a corpse to start the timer and begin writing. + Do not pause. +
    6. +
    +
      + {favourites.map(favourite => ( + + ))} +
    +