-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BootstrapDash#1 from netlify/revengers-demo
Revengers demo
- Loading branch information
Showing
6 changed files
with
341 additions
and
1,524 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"version": "0.1.0", | ||
"author": "Kyle Mathews <[email protected]>", | ||
"dependencies": { | ||
"faunadb": "^2.6.1", | ||
"gatsby": "^2.3.5", | ||
"gatsby-image": "^2.0.37", | ||
"gatsby-plugin-manifest": "^2.0.26", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env node | ||
|
||
/* Import faunaDB sdk */ | ||
const faunadb = require("faunadb") | ||
|
||
const q = faunadb.query | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB_SERVER_SECRET, | ||
}) | ||
|
||
console.log("Adjusting the gauntlet…") | ||
|
||
client | ||
.query(q.Paginate(q.Match(q.Ref("indexes/all_items")))) | ||
.then(response => { | ||
const itemRefs = response.data | ||
const getAllItemsDataQuery = itemRefs.map(ref => { | ||
return q.Get(ref) | ||
}) | ||
console.log("Admiring infinity stones first…") | ||
return client.query(getAllItemsDataQuery).then(ret => { | ||
Promise.all( | ||
ret.map(el => { | ||
if (Math.random() >= 0.5) { | ||
return null | ||
} | ||
return client | ||
.query(q.Delete(q.Ref(`classes/items/${el.ref.id}`))) | ||
.then(response => { | ||
console.log(`Message from ${el.data.name}: I don't feel so good…`) | ||
}) | ||
}) | ||
).then(() => console.log(`_silence_`)) | ||
}) | ||
}) | ||
.catch(e => console.error(e)) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React, { useState, useEffect } from "react" | ||
|
||
import Layout from "../components/layout" | ||
import { withPrefix } from "gatsby" | ||
|
||
const GuestbookPage = () => { | ||
const [messages, setMessages] = useState(null) | ||
|
@@ -34,51 +34,63 @@ const GuestbookPage = () => { | |
poll() | ||
return () => (polling = false) | ||
}, []) | ||
|
||
return ( | ||
<Layout> | ||
<h1>Guestbook!</h1> | ||
<div className="revengers"> | ||
<div className="chicken-wrap"> | ||
<div className="revengers-title"> | ||
<img src={withPrefix("/[email protected]")} alt="Logo" /> | ||
<h2>A messaging app for super-villains</h2> | ||
</div> | ||
|
||
{messages === null && <div>Loading guestbook...</div>} | ||
{messages && | ||
messages.map(message => ( | ||
<div className="msg" key={message.ts}> | ||
<h2>{message.data.name}</h2> | ||
<div> | ||
{message.data.message.split(/\n/).map((line, i) => ( | ||
<p key={i}>{line}</p> | ||
))} | ||
{messages === null && <div>Loading guestbook...</div>} | ||
{messages && | ||
(["BadRequest", "Unauthorized"].includes(messages.name) ? ( | ||
<div style={{ border: "1px solid red", color: "yellow" }}> | ||
Bad/Unauthorized Request - you may have forgotten to setup your | ||
Fauna DB addon (<pre>netlify addons:create fauna</pre>) and run{" "} | ||
<pre>netlify dev:exec functions/fauna/create-schema.js</pre> | ||
</div> | ||
</div> | ||
))} | ||
) : ( | ||
messages.map(message => ( | ||
<div className="msg" key={message.ts}> | ||
<div> | ||
<p>{message.data.message.trim()}</p> | ||
</div> | ||
<h2 className="msg-author">{message.data.name}</h2> | ||
</div> | ||
)) | ||
))} | ||
|
||
<div> | ||
<form className="guestbook-form" onSubmit={submit}> | ||
<div className="form-control"> | ||
<label>Your name:</label> | ||
<input | ||
type="text" | ||
value={message.name} | ||
onChange={e => setMessage({ ...message, name: e.target.value })} | ||
/> | ||
</div> | ||
<div className="form-control"> | ||
<label>Your message:</label> | ||
<textarea | ||
value={message.message} | ||
onChange={e => | ||
setMessage({ ...message, message: e.target.value }) | ||
} | ||
/> | ||
</div> | ||
<div className="form-control"> | ||
<button type="submit" disabled={saving}> | ||
{saving ? "Submitting..." : "Submit"} | ||
</button> | ||
</div> | ||
</form> | ||
<div> | ||
<form className="guestbook-form" onSubmit={submit}> | ||
<div className="form-control"> | ||
<label>Your evil name:</label> | ||
<input | ||
type="text" | ||
value={message.name} | ||
required | ||
onChange={e => setMessage({ ...message, name: e.target.value })} | ||
/> | ||
</div> | ||
<div className="form-control"> | ||
<label>Your evil message:</label> | ||
<textarea | ||
value={message.message} | ||
required | ||
onChange={e => | ||
setMessage({ ...message, message: e.target.value }) | ||
} | ||
/> | ||
</div> | ||
<div className="form-control"> | ||
<button className="submit-btn" type="submit" disabled={saving}> | ||
{saving ? "Sending..." : "SEND MESSAGE, in a evil way"} | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</Layout> | ||
</div> | ||
) | ||
} | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.