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
const reducer = (state, action) => { | |
switch (action.type) { | |
case 'load': | |
return { ...state, files: action.files, status: LOADED } | |
case 'submit': | |
return { ...state, uploading: true, pending: state.files, status: INIT } | |
case 'next': | |
return { | |
...state, | |
next: action.next, |
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
import { useReducer } from 'react' | |
// Constants | |
const LOADED = 'LOADED' | |
const INIT = 'INIT' | |
const PENDING = 'PENDING' | |
const FILES_UPLOADED = 'FILES_UPLOADED' | |
const UPLOAD_ERROR = 'UPLOAD_ERROR' | |
const initialState = { | |
files: [], |
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
import React from 'react' | |
const initialState = { | |
files: [], | |
pending: [], | |
next: null, | |
uploading: false, | |
uploaded: {}, | |
status: 'idle', | |
} |
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
.container { | |
padding: 8px; | |
width: 100%; | |
box-sizing: border-box; | |
overflow-x: hidden; | |
} | |
.form { | |
position: relative; | |
width: 100%; |
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
import React from 'react' | |
import './App.css' | |
const Input = (props) => ( | |
<input type='file' name='file-input' multiple {...props} /> | |
) | |
const App = () => { | |
const onSubmit = (e) => { | |
e.preventDefault() | |
} | |
const onChange = (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
// Check if we have a certain user in our cache | |
if let user = db.query("SELECT FROM users WHERE id = \(id)").first { | |
callback(user) | |
} | |
else { | |
// Fetch from the network instead | |
API.request("/users?id=\(id)").onSuccess { response in | |
callback(response.user) | |
} | |
} |
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
const FriendListItem = gql` | |
fragment FriendListItem on User { | |
firstName | |
lastName | |
avatar { | |
thumbnail | |
} | |
} | |
`; |
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
// Generated to support our `me` query | |
interface User_me { | |
firstName: string; | |
lastName: string; | |
location: User_me_location; | |
avatar: User_me_avatar; | |
} | |
interface User_me_location { | |
city: string; |
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
interface SimpleUser { | |
id: number; | |
firstName: string; | |
lastName: string; | |
avatar: Avatar; | |
} |
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
friends { | |
firstName | |
lastName | |
avatar { | |
thumbnail | |
} | |
} |