Skip to content

Instantly share code, notes, and snippets.

View Ledoux's full-sized avatar

ledoux Ledoux

View GitHub Profile
@Ledoux
Ledoux / clement.css
Last active December 11, 2015 18:51
Un gist pour Clement
.clement {
color:red;
}
@Ledoux
Ledoux / new.txt
Created December 12, 2015 13:35
HackRepNum
Projet de loi pour une République numérique
TITRE IER
LA CIRCULATION DES DONNEES ET DU SAVOIR
CHAPITRE IER
ECONOMIE DE LA DONNEE
Section 1
@Ledoux
Ledoux / text.txt
Created December 12, 2015 13:36
HackRechNum
Projet de loi pour une République numérique
TITRE IER
LA CIRCULATION DES DONNEES ET DU SAVOIR
CHAPITRE IER
ECONOMIE DE LA DONNEE
Section 1
@Ledoux
Ledoux / Offer.jsx
Last active April 16, 2019 20:44
pass-Culture Offer Component
class Offer extends Component {
constructor() {
super();
this.state = {
available: 0
};
}
componentDidMount() {
this.props.requestGetOffer();
from flask import current_app as app, jsonify, request
from models import Offer, PcObject, Stock
@app.route('/offers/<id>', methods=['GET'])
@login_required
def get_offer(id):
offer = load_or_404(Offer, id)
return jsonify(offer._asdict(include=["stocks"]))
@app.route('/stocks', methods=['POST'])
{
"id": "CD",
"name": "Marx et Compagnie",
"stocks": [
{ "available": 15, "id": "AE" },
{ "available": 25, "id": "BF" },
]
}
import React, { Fragment } from 'react'
const AddStock = ({ handleAddStock }) => {
const [available, setAvailable] = useState(0)
return (
<Fragment>
<input
onChange={event => setAvailable(event.target.value)}
value={available}
/>
const OfferContainer = compose(
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
)(Offer);
import { createSelector } from 'reselect'
const selectOfferById = createSelector(
state => state.data.offers,
(state, offerId) => offerId,
(offers, offerId) => (offers || []).find(offer => offer.id === offerId)
)
export default selectOfferById
...
class Offer extends Component {
componentDidMount () {
const { dispatch, match: { params: { offerId } } } = this.props
dispatch(requestData({
apiPath: `/offers/${offerId}`,
normalizer: {
stocks: 'stocks'
}