Skip to content

Instantly share code, notes, and snippets.

View mikevercoelen's full-sized avatar
🎯
Focusing

Mike Vercoelen mikevercoelen

🎯
Focusing
View GitHub Profile
@mikevercoelen
mikevercoelen / uploadFile.js
Created July 22, 2021 04:33
Upload file with signed URL + endpoint
import _ from 'lodash'
import { gql } from '@apollo/client'
const THROTTLE_CAP = 750
const signFileUploadMutation = gql`
mutation SignFileUpload (
$fileName: String!
$type: FileUploadType!
) {
const removeImage = publicId => new Promise((resolve, reject) => {
cloudinary.v2.uploader.destroy(publicId, error => {
if (error) {
return reject(error)
}
resolve()
})
})
@mikevercoelen
mikevercoelen / CreateReducer.js
Last active April 16, 2018 10:47
Less boilerplate for Redux Reducers
function createReducer(initialState, handlers) {
return function reducer(state = initialState, action) {
if (handlers.hasOwnProperty(action.type)) {
return handlers[action.type](state, action)
}
return state
}
}
@mikevercoelen
mikevercoelen / index.js
Created January 30, 2018 09:24
Login page module index.js example code
import { injectReducer } from 'common/reducers'
import * as Routes from 'constants/Routes'
import { toggleLoader } from 'common/actions/loader'
export default (store) => ({
path: Routes.LOGIN,
getComponent: async function (nextState, cb) {
store.dispatch(toggleLoader(true))
const [module, reducer] = await Promise.all([
import('./containers/LoginContainer'),
@mikevercoelen
mikevercoelen / router.js
Created January 30, 2018 09:07
New purposal for routes
// Old
export const appRoutes = (
<div>
<Route path="companies/:companyId" component={CompanyNavigation} >
<IndexRoute component={CompanyProjectsContainer} /> // TODO: Dashboard?
<Route path="projects" component={CompanyProjectsContainer} />
<Route path="users" component={CompanyUsersContainer} />
<Route path="divisions" component={CompanyDivisionsContainer} />
<Route path="activities" component={CompanyActivitiesContainer} />
</Route>
@mikevercoelen
mikevercoelen / flat.js
Created January 8, 2018 15:39
Flatten a nested array in Javascript
//
// [email protected]
//
// For this solution, when a project has lodash, I would suggest to use `flattenDeep` @ https://lodash.com/docs/4.17.4#flattenDeep
// But ofcourse, a manual util function is easily written:
const nestedArray = [1, [2, 3], [4, 5, [6, 7]], 8]
function flattenArray (nestedArray) {
let flatArray = []