Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Del Rio ddelrio1986

  • eLearning Innovations
  • Seminole, Florida, United States of America
View GitHub Profile
@ddelrio1986
ddelrio1986 / GeneralError.jsx
Created Aug 16, 2018
A simple general error component
View GeneralError.jsx
import React from 'react'
import { Alert, Col, Grid, Row } from 'react-bootstrap'
const GeneralError = () => (
<Grid fluid>
<Row>
<Col xs={12}>
<Alert bsStyle="danger" style={{marginTop: '1em'}}>
<h4 style={{fontWeight: '600'}}>An error has occurred!</h4>
<p>Relaunch the content to ensure nothing is lost.</p>
@ddelrio1986
ddelrio1986 / handle-response.js
Last active Aug 16, 2018
Handle fetch errors
View handle-response.js
export function handleJSONResponse (response) {
return response.json()
.then(json => {
if (response.ok) return json
return Promise.reject({...json, responseObj: response})
})
}
export function handleTextResponse (response) {
View index.php
<?php
// Example of subclassing the base Exception class. Note that it doesn't HAVE to contain any code.
class FileWriteException extends Exception {
}
// Rule: When writing a function, you should throw exceptions for error management instead of returning a
// boolean.
// Rule: You should never throw Exception class directly. Instead, you should consider extending the Exception
@ddelrio1986
ddelrio1986 / index.js
Created Feb 8, 2018
Extend entities in DraftJS when typing next to them.
View index.js
/*
DraftJS Slack - #general
Jimj 02/08/2018 [8:13 AM]
@ddelrio Simplest solution I found for continuing entities is, in beforeInputHanded :
*/
const prev_char_space = this.getCharFromSelection() === ' '
const new_char_space = char === ' '
const prev_ent = this.getEntityAtSelection()
if (prev_ent && (!prev_char_space || !new_char_space)) {
const contentStateWithEntity = Modifier.insertText(
@ddelrio1986
ddelrio1986 / contentStateLogger.js
Created Nov 8, 2017
DraftJS ContentState Logger
View contentStateLogger.js
export const contentStateLogger = editorState => {
const result = JSON.stringify(convertToRaw(editorState.getCurrentContent()), null, 4);
const newResult = JSON.parse(result);
const contentState = JSON.stringify(newResult, null, 4);
// unquotes object keys
const keyQuotes = /"(.+)"(?=:)/g;
const newContentState = contentState.replace(keyQuotes, '$1');
console.log(newContentState);
};