Skip to content

Commit

Permalink
Merge branch 'n400-rename_handle_var_to_alias'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brecht De Rooms committed Apr 27, 2020
2 parents fab6b85 + b122473 commit d36a82e
Show file tree
Hide file tree
Showing 24 changed files with 154 additions and 135 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const App = () => {
<Route exact path="/accounts/register">
<Register />
</Route>
<Route path="/users/:authorHandle" component={User} />
<Route path="/users/:authorAlias" component={User} />
<Route path="/tags/:tag" component={Tag} />
<Route path="/">
<Home />
Expand Down
6 changes: 3 additions & 3 deletions src/components/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Card = props => {
<div className="fweet-card-text refweet">
<div className="fweet-header">
<span className="fweet-name"> {fweetAndMore.original.user.name} </span>
<span className="fweet-handle"> @{fweetAndMore.original.user.handle} </span>
<span className="fweet-alias"> @{fweetAndMore.original.user.alias} </span>
</div>
<p className="fweet-description"> {fweetAndMore.original.fweet.message} </p>
</div>
Expand All @@ -42,7 +42,7 @@ const Card = props => {
<div className="fweet-card-text">
<div className="fweet-header">
<span className="fweet-name"> {fweetAndMore.user.name} </span>
<span className="fweet-handle"> @{fweetAndMore.user.handle} </span>
<span className="fweet-alias"> @{fweetAndMore.user.alias} </span>
</div>
<p className="fweet-description"> {fweetAndMore.fweet.message} </p>
</div>
Expand All @@ -60,7 +60,7 @@ const Card = props => {
<div className="fweet-card-text comment" key={commandAndAuthor.comment.ref.toString()}>
<div className="fweet-header">
<span className="fweet-name"> {commandAndAuthor.author.name} </span>
<span className="fweet-handle"> @{commandAndAuthor.author.handle} </span>
<span className="fweet-alias"> @{commandAndAuthor.author.alias} </span>
</div>
<p className="fweet-description"> {commandAndAuthor.comment.message} </p>
</div>
Expand Down
16 changes: 8 additions & 8 deletions src/components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Form = props => {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [name, setName] = useState('')
const [handle, setHandle] = useState('')
const [alias, setAlias] = useState('')

const handleChangeUserName = event => {
setUsername(event.target.value)
Expand All @@ -20,8 +20,8 @@ const Form = props => {
setName(event.target.value)
}

const handleChangeHandle = event => {
setHandle(event.target.value)
const handleChangeAlias = event => {
setAlias(event.target.value)
}

const linkInfo = props.isLogin
Expand All @@ -31,11 +31,11 @@ const Form = props => {
return (
<React.Fragment>
<div className="account-form-container">
<form className="account-form" onSubmit={e => props.handleSubmit(e, username, password, handle, name)}>
{props.isLogin ? null : renderInputField('Name', name, 'text', e => handleChangeName(e))}
{props.isLogin ? null : renderInputField('Handle', handle, 'text', e => handleChangeHandle(e))}
<form className="account-form" onSubmit={e => props.handleSubmit(e, username, password, alias, name)}>
{props.isLogin ? null : renderInputField('Name', name, 'text', e => handleChangeName(e))}
{props.isLogin ? null : renderInputField('Alias', alias, 'text', e => handleChangeAlias(e))}
{renderInputField('Email', username, 'text', e => handleChangeUserName(e))}
{renderInputField('Password', password, 'password', e => handleChangePassword(e))}
{renderInputField('Password', password, 'password', e => handleChangePassword(e))}
<div className="input-row align-right">
<Link to={linkInfo.link}> {linkInfo.linkText}</Link>
<button className={props.isLogin ? 'login' : 'register'}> {props.isLogin ? 'Login' : 'Register'} </button>
Expand All @@ -50,7 +50,7 @@ const renderInputField = (name, value, type, fun) => {
const lowerCaseName = name.toLowerCase()
return (
<div className="input-row">
<span className="input-row-column">{name}</span>
<label htmlFor="{lowerCaseName}" className="input-row-column">{name}</label>
<input
className="input-row-column"
autoComplete={lowerCaseName}
Expand Down
9 changes: 7 additions & 2 deletions src/components/fweeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Uploader } from './uploader'
import Asset from './asset'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPaperPlane } from '@fortawesome/free-solid-svg-icons'
import { toast } from 'react-toastify'

const Fweeter = props => {
const [fweet, setFweet] = useState('')
Expand All @@ -19,8 +20,12 @@ const Fweeter = props => {

const handleSubmit = event => {
event.preventDefault()

if (!fweet) return

if (!fweet) {
toast.warn('Please enter some text first :)')
return
}

props.handleCreateFweet(fweet, asset).then(e => {
setFweet('')
setAsset(null)
Expand Down
8 changes: 5 additions & 3 deletions src/components/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isFunction } from '../fauna/helpers/util'

const renderLogo = sessionContext => {
return (
<div className="fauna-logo">
<div key="link_logo" className="fauna-logo">
<Link className="logo-container" to="/">
<img alt="Fauna logo" src="/images/logo-fauna-white.svg" />
</Link>
Expand Down Expand Up @@ -53,13 +53,15 @@ const renderLink = (link, sessionContext) => {
if (link.handleClick) {
return (
<li onClick={event => handleLogout(event, sessionContext)} key={`nav-link-${link.label}`}>
<Link>{link.label}</Link>
<Link key={'link_' + link.label}>{link.label}</Link>
</li>
)
} else {
return (
<li key={`nav-link-${link.href}-${link.label}`}>
<Link to={link.href}>{link.label}</Link>
<Link key={'link_' + link.label} to={link.href}>
{link.label}
</Link>
</li>
)
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Search = props => {
}

const handleUserClick = (event, searchResult) => {
history.push(`/users/${searchResult.handle}`)
history.push(`/users/${searchResult.alias}`)

event.stopPropagation()
}
Expand Down Expand Up @@ -69,11 +69,11 @@ const Search = props => {
<React.Fragment>
<div className="search-results">
<div className="search-results-title">People</div>
<div className="search-results-people">{renderUserResults(searchResults.filter(e => e.handle))}</div>
<div className="search-results-people">{renderUserResults(searchResults.filter(e => e.alias))}</div>
</div>
<div className="search-results">
<div className="search-results-title">Tags</div>
<div className="search-results-tags">{renderTagResults(searchResults.filter(e => !e.handle))}</div>
<div className="search-results-tags">{renderTagResults(searchResults.filter(e => !e.alias))}</div>
</div>
</React.Fragment>
)
Expand All @@ -90,9 +90,9 @@ const Search = props => {
<div className="avatar">
<img className="avatar-image" src={`/images/${res.icon}.png`} alt="profile" />
</div>
<div className="search-result-name-and-handle">
<div className="search-result-name-and-alias">
<div className="name">{res.name}</div>
<div className="handle">@{res.handle}</div>
<div className="alias">@{res.alias}</div>
</div>
<div className="search-result-follow-button" onClick={event => handleFollowUser(event, res)}>
<button className="icon">
Expand Down
16 changes: 1 addition & 15 deletions src/fauna/helpers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ const wrapPromiseError = (promise, entity) => {
})
}

const handle = (promise, tag, printData) => {
return promise
.then(data => {
// console.log('Success call:' + tag)
if (printData) console.log(data)
return data
})
.catch(error => {
console.error('Failed to execute: ' + tag)
console.error(error)
throw error
})
}

const handleSetupError = (promise, entity) => {
return promise
.then(data => {
Expand Down Expand Up @@ -64,4 +50,4 @@ const safeVerifyError = (error, keys) => {
}
return error
}
export { handlePromiseError, wrapPromiseError, handle, handleSetupError, safeVerifyError }
export { handlePromiseError, wrapPromiseError, handleSetupError, safeVerifyError }
12 changes: 6 additions & 6 deletions src/fauna/queries/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ function RegisterAccountExample2(email, password) {
* However, we also want to create a user automatically when we create an account.
* We can use a Let to structure our query */
// eslint-disable-next-line no-unused-vars
function RegisterExample3(email, password, name, handle, icon, rateLimiting = true) {
function RegisterExample3(email, password, name, alias, icon, rateLimiting = true) {
const RegisterFQLStatement = Let(
{
user: Create(Collection('users'), {
data: {
name: name,
handle: handle,
alias: alias,
icon: icon
}
}),
Expand All @@ -107,7 +107,7 @@ function RegisterExample3(email, password, name, handle, icon, rateLimiting = tr
/* Register Example4 - let's extend it to do e-mail validation
And follow ourselves at the moment we create the user
since you only see the feed of the people you follow */
function RegisterWithUser(email, password, name, handle, icon, rateLimiting = true) {
function RegisterWithUser(email, password, name, alias, icon, rateLimiting = true) {
// It's always a good idea to use If for such validations compared to Do since Do is not short-circuited at this point
// at the read-phase, which means that you will incur more reads.
const ValidateEmail = FqlStatement =>
Expand Down Expand Up @@ -136,7 +136,7 @@ function RegisterWithUser(email, password, name, handle, icon, rateLimiting = tr
user: Create(Collection('users'), {
data: {
name: name,
handle: handle,
alias: alias,
icon: icon
}
}),
Expand Down Expand Up @@ -269,9 +269,9 @@ function register(client, email, password) {
return client.query(Call(q.Function('register'), email, password)).then(res => flattenDataKeys(res))
}

function registerWithUser(client, email, password, name, handle, icon) {
function registerWithUser(client, email, password, name, alias, icon) {
return client
.query(Call(q.Function('register_with_user'), email, password, name, handle, icon))
.query(Call(q.Function('register_with_user'), email, password, name, alias, icon))
.then(res => flattenDataKeys(res))
}

Expand Down
14 changes: 10 additions & 4 deletions src/fauna/queries/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CreateOrUpdateFunction, CreateAccountUDF } from './../setup/functions'
import { setupProtectedResource, setupDatabaseAuthSpec, deleteAndCreateDatabase } from '../setup/database'
import { DeleteAllAccounts } from '../setup/accounts'

import { handle, wrapPromiseError } from './../helpers/errors'
import { handlePromiseError, wrapPromiseError } from './../helpers/errors'
import { register, login } from './auth'

// About this spec:
Expand All @@ -24,14 +24,20 @@ beforeAll(async () => {
const adminClient = new faunadb.Client({
secret: process.env.REACT_APP_TEST__ADMIN_KEY
})
const secret = await handle(deleteAndCreateDatabase(adminClient, 'auth-spec'), 'Creating temporary test database')
const secret = await handlePromiseError(
deleteAndCreateDatabase(adminClient, 'auth-spec'),
'Creating temporary test database'
)
client = new faunadb.Client({
secret: secret
})
// Setup the database for this test.
await handle(setupDatabaseAuthSpec(client), 'Setup Database')
await handlePromiseError(setupDatabaseAuthSpec(client), 'Setup Database')
// Set up a resource that we should only be able to access after logging in.
misterProtectedRef = await handle(setupProtectedResource(client), 'Setup a protected collection and entity')
misterProtectedRef = await handlePromiseError(
setupProtectedResource(client),
'Setup a protected collection and entity'
)
} catch (err) {
console.error(err)
}
Expand Down
10 changes: 5 additions & 5 deletions src/fauna/queries/fweets.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ function getFweetsByTag(client, tag) {
return client.query(Call(q.Function('get_fweets_by_tag'), tag)).then(res => flattenDataKeys(res))
}

function GetFweetsByAuthor(authorHandle) {
function GetFweetsByAuthor(authorAlias) {
const FQLStatement = Let(
{
// We only receive the userHandle, not reference (since this is passed through the URL, a ref would be ugly in the url right?)
// We only receive the userAlias, not reference (since this is passed through the URL, a ref would be ugly in the url right?)
// So let's get the user, we assume that it still exists (if not Get will error but that is fine for our use case)
authorReference: Select([0], Paginate(Match(Index('users_by_handle'), authorHandle))),
authorReference: Select([0], Paginate(Match(Index('users_by_alias'), authorAlias))),
results: GetFweetsWithUsersMapGetGeneric(
// When we look at the feed of fweets of a certain user, we are just going to order them
// Chronologically.
Expand All @@ -439,8 +439,8 @@ function GetFweetsByAuthor(authorHandle) {
return AddRateLimiting('get_fweets_by_author', FQLStatement, Identity())
}

function getFweetsByAuthor(client, authorHandle) {
return client.query(Call(q.Function('get_fweets_by_author'), authorHandle)).then(res => flattenDataKeys(res))
function getFweetsByAuthor(client, authorAlias) {
return client.query(Call(q.Function('get_fweets_by_author'), authorAlias)).then(res => flattenDataKeys(res))
}

/* Get fweets and the user that is the author of the message.
Expand Down
26 changes: 16 additions & 10 deletions src/fauna/queries/fweets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import faunadb from 'faunadb'

import { setupDatabase, deleteAndCreateDatabase } from '../setup/database'

import { handle } from './../helpers/errors'
import { handlePromiseError } from './../helpers/errors'
import { registerWithUser, login } from './auth'
import { getFweets, createFweet, createFweetWithoutUDF } from './fweets'
import { follow } from './followers'
Expand All @@ -29,34 +29,40 @@ beforeAll(async () => {
secret: process.env.REACT_APP_TEST__ADMIN_KEY
})
// Create the admin client for the new database to bootstrap things
const secret = await handle(
const secret = await handlePromiseError(
deleteAndCreateDatabase(adminClientParentDb, 'fweets-spec'),
'Creating temporary test database'
)
adminClient = new faunadb.Client({
secret: secret
})
// Setup the database for this test.
await handle(setupDatabase(adminClient), 'Setup Database')
await handlePromiseError(setupDatabase(adminClient), 'Setup Database')

// Create a client with a login key (getting privileges from 'memberships' in roles)
// We create a user directly as well
await handle(registerWithUser(adminClient, '[email protected]', 'testtest'), 'Register with User')
const res = await handle(login(adminClient, '[email protected]', 'testtest'), 'Login')
await handlePromiseError(registerWithUser(adminClient, '[email protected]', 'testtest'), 'Register with User')
const res = await handlePromiseError(login(adminClient, '[email protected]', 'testtest'), 'Login')
loggedInClient = new faunadb.Client({ secret: res.secret })
user1Ref = res.user.ref

await handle(registerWithUser(adminClient, '[email protected]', 'testtest'), 'Register with User')
const res2 = await handle(login(adminClient, '[email protected]', 'testtest'), 'Login')
await handlePromiseError(registerWithUser(adminClient, '[email protected]', 'testtest'), 'Register with User')
const res2 = await handlePromiseError(login(adminClient, '[email protected]', 'testtest'), 'Login')
loggedInClient2 = new faunadb.Client({ secret: res2.secret })

// Create a client with the bootstrap key (assuming the bootstrap role)
const key = await handle(adminClient.query(CreateKey({ role: Role('keyrole_calludfs') })), 'Creating Bootstrap Key')
const key = await handlePromiseError(
adminClient.query(CreateKey({ role: Role('keyrole_calludfs') })),
'Creating Bootstrap Key'
)
bootstrapClient = new faunadb.Client({ secret: key.secret })

user2Ref = res2.user.ref
await handle(createFweet(loggedInClient, 'Tweet user 1 #tag1', ['tag1']), 'Creating Fweet 1')
await handle(createFweet(loggedInClient2, 'Tweet user 2 #tag2 #tag3', ['tag2', 'tag3']), 'Creating Fweet 2')
await handlePromiseError(createFweet(loggedInClient, 'Tweet user 1 #tag1', ['tag1']), 'Creating Fweet 1')
await handlePromiseError(
createFweet(loggedInClient2, 'Tweet user 2 #tag2 #tag3', ['tag2', 'tag3']),
'Creating Fweet 2'
)

return
// Set up a resource that we should only be able to access after logging in.
Expand Down
6 changes: 3 additions & 3 deletions src/fauna/queries/rate-limiting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DeleteAllRatelimiting } from '../setup/rate-limiting'
import { DeleteAllAccounts } from '../setup/accounts'
import { DeleteAllUsers } from '../setup/users'
import { registerWithUser, login } from './auth'
import { handle } from './../helpers/errors'
import { handlePromiseError } from './../helpers/errors'

// the rate-limiting function we are actually testing
import { AddRateLimiting } from './rate-limiting'
Expand Down Expand Up @@ -35,7 +35,7 @@ beforeAll(async () => {
adminClient = new faunadb.Client({
secret: process.env.REACT_APP_TEST__ADMIN_KEY
})
const secret = await handle(
const secret = await handlePromiseError(
deleteAndCreateDatabase(adminClient, 'ratelimiting-spec'),
'Creating temporary test database'
)
Expand All @@ -44,7 +44,7 @@ beforeAll(async () => {
secret: secret
})
// Setup the database for this test
await handle(setupDatabaseRateLimitingSpec(adminClient), 'Setup Database')
await handlePromiseError(setupDatabaseRateLimitingSpec(adminClient), 'Setup Database')
} catch (err) {
console.error(err)
}
Expand Down
Loading

0 comments on commit d36a82e

Please sign in to comment.