Skip to content

Instantly share code, notes, and snippets.

View LanciWeb's full-sized avatar

Marco Lancellotti LanciWeb

View GitHub Profile
@LanciWeb
LanciWeb / noteRoutes.js
Created October 15, 2020 18:00
V1 routes for the Fastify + React Admin project on Medium
module.exports = (app) => {
// create a note
app.post('/api/notes', (request, reply) => {});
// get the list of notes
app.get('/api/notes', (request, reply) => {});
// get a single note
app.get('/api/notes/:id', (request, reply) => {});
@LanciWeb
LanciWeb / Note.js
Created October 15, 2020 18:02
Note model for the Fastify + React Admin project on Medium
const mongoose = require('mongoose');
const { Schema } = mongoose;
const noteSchema = new Schema({
text: { type: String, required: true },
});
const Note = mongoose.model('note', noteSchema);
module.exports = Note;
@LanciWeb
LanciWeb / App.js
Created October 16, 2020 13:27
Clean App js for the Fastify + React Admin project on Medium
import React from 'react';
function App() {
return <div className="App">Hello world</div>
}
export default App;
@LanciWeb
LanciWeb / dataProvider.js
Created October 16, 2020 14:04
dataPRovider for the Fastify + React Admin project on Medium
import { fetchUtils } from 'react-admin';
import { stringify } from 'query-string';
const apiUrl = 'http://localhost:3000/api';
const httpClient = fetchUtils.fetchJson;
export default {
getList: (resource, params) => {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
@LanciWeb
LanciWeb / App.js
Last active October 16, 2020 16:01
App.js with Admin for the Fastify + React Admin project on Medium
import React from 'react';
import { Admin} from 'react-admin';
import dataProvider from './dataProvider';
function App() {
return (
<Admin dataProvider={dataProvider} />
);
}
@LanciWeb
LanciWeb / App.js
Last active October 16, 2020 16:01
App.js final for the Fastify + React Admin project on Medium
import React from 'react';
import dataProvider from './dataProvider';
import { Admin, Resource } from 'react-admin';
import NotesList from './components/NotesList';
import NotesEdit from './components/NotesEdit';
import NotesCreate from './components/NotesCreate';
function App() {
return (
<Admin dataProvider={dataProvider}>
@LanciWeb
LanciWeb / NotesList.js
Created October 16, 2020 16:05
NotesList.js for the Fastify + React Admin project on Medium
import React from 'react';
import {
List,
Datagrid,
TextField,
EditButton,
DeleteButton,
} from 'react-admin';
const NotesList = (props) => {
@LanciWeb
LanciWeb / NotesCreate.js
Created October 16, 2020 16:06
NotesCreate.js for the Fastify + React Admin project on Medium
import React from 'react';
import { Create, SimpleForm, TextInput } from 'react-admin';
const NotesCreate = (props) => {
return (
<Create {...props}>
<SimpleForm>
<TextInput source="text" required />
</SimpleForm>
</Create>
);
@LanciWeb
LanciWeb / NotesEdit.js
Created October 16, 2020 16:08
NotesEdit.js for the Fastify + React Admin project on Medium
import React from 'react';
import { Edit, SimpleForm, TextInput } from 'react-admin';
const NotesEdit = (props) => {
return (
<Edit {...props}>
<SimpleForm>
<TextInput disabled source="id" />
<TextInput required source="text" />
</SimpleForm>
</Edit>
@LanciWeb
LanciWeb / itemsReducer.js
Last active November 28, 2020 14:51
An example of reducer
//an ecample of reducer
export default (state, action) => {
const {type, payload} = action;
switch (type){
case 'ADD_ITEM':
return {...state, items: [...state.items, payload]};
case 'REMOVE_ITEM':
const filteredItems = state.items.filter(i => i.id !== payload);
return {...state, items: items};