Skip to content

Instantly share code, notes, and snippets.

View zackshapiro's full-sized avatar

Zack Shapiro zackshapiro

View GitHub Profile
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,
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: [],
import React from 'react'
const initialState = {
files: [],
pending: [],
next: null,
uploading: false,
uploaded: {},
status: 'idle',
}
.container {
padding: 8px;
width: 100%;
box-sizing: border-box;
overflow-x: hidden;
}
.form {
position: relative;
width: 100%;
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) => {
// 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)
}
}
const FriendListItem = gql`
fragment FriendListItem on User {
firstName
lastName
avatar {
thumbnail
}
}
`;
// 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;
interface SimpleUser {
id: number;
firstName: string;
lastName: string;
avatar: Avatar;
}
friends {
firstName
lastName
avatar {
thumbnail
}
}