remove the sample-complex folder

This commit is contained in:
jhuleatt
2019-11-11 16:59:08 -08:00
parent b863eed4ff
commit 7820b0f162
28 changed files with 1 additions and 264 deletions

View File

@@ -1,3 +0,0 @@
{
"presets": [["@babel/preset-env"], "@babel/preset-react"]
}

View File

@@ -1,31 +0,0 @@
{
"name": "sample-complex",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"scripts": {
"build": "rimraf dist && npm run build-client && npm run build-server",
"build-client": "NODE_ENV=development parcel build src/client.tsx -d dist/client --no-minify --public-url .",
"build-server": "NODE_ENV=development parcel build src/server.tsx -d dist/server --target=node10 --no-minify",
"start": "yarn run build && node dist/server/server.js"
},
"devDependencies": {
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-react": "^7.0.0",
"parcel-bundler": "^1.12.3",
"rimraf": "^2.6.3"
},
"dependencies": {
"@types/express": "^4.16.1",
"@types/react": "^16.8.14",
"@types/react-dom": "^16.8.4",
"express": "^4.16.4",
"firebase": "^7.0.0",
"firebase-admin": "^7.3.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"reactfire": "2.0.0"
}
}

View File

@@ -1,67 +0,0 @@
import * as React from 'react';
import * as firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
import { AuthCheck } from 'reactfire';
const SignInButton = () => {
const [hasBeenClicked, setHasBeenClicked] = React.useState(false);
const signIn = () => {
setHasBeenClicked(true);
firebase.auth().signInAnonymously();
};
return (
<button onClick={signIn} disabled={hasBeenClicked}>
Sign in to add your favorite animals
</button>
);
};
const DisabledInput = () => {
return <NewAnimalForm disabled />;
};
const NewAnimalForm = ({ value, setValue, disabled, onClick }) => {
return (
<>
<input
disabled={disabled}
value={value}
onChange={e => setValue(e.target.value)}
/>
<button disabled={disabled} onClick={onClick} className="bg-blue-100">
Save
</button>
</>
);
};
const AddAnimal = () => {
const [newAnimalName, setName] = React.useState('');
const addAnimal = () =>
firebase
.firestore()
.collection('animals')
.add({ commonName: newAnimalName });
if (!firebase.apps.length) {
return <DisabledInput />;
}
return (
<React.Suspense fallback={<DisabledInput />}>
<AuthCheck fallback={<SignInButton />} auth={firebase.auth()}>
<input value={newAnimalName} onChange={e => setName(e.target.value)} />
<button className="bg-blue-300" onClick={addAnimal}>
Save
</button>
</AuthCheck>
</React.Suspense>
);
};
export default AddAnimal;

View File

@@ -1,15 +0,0 @@
import * as React from 'react';
import Animals from './FirestoreAnimals';
import AddAnimal from './AddAnimal';
const App = ({ isBrowser, animals }) => {
return (
<div className="bg-blue-100 h-screen">
<h1 className="text-lg">Animals</h1>
<AddAnimal />
<Animals serverAnimals={animals} />
</div>
);
};
export default App;

View File

@@ -1,33 +0,0 @@
import * as React from 'react';
import * as firebase from 'firebase/app';
import 'firebase/firestore';
import { useFirestoreCollection } from 'reactfire';
const deserialize = collection => {
return {
docs: collection.map(item => ({ ...item, data: () => item.data }))
};
};
const Animals = ({ serverAnimals }) => {
let initialAnimals = deserialize(serverAnimals);
let animals = initialAnimals;
if (firebase.apps.length) {
animals = useFirestoreCollection(
firebase.firestore().collection('animals'),
{ startWithValue: initialAnimals }
);
}
return (
<ul className="list-disc list-inside">
{animals.docs.map(animal => (
<li key={animal.id}>name: {animal.data().commonName}</li>
))}
</ul>
);
};
export default Animals;

View File

@@ -1,16 +0,0 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
import * as firebase from 'firebase/app';
import firebaseConfig from './firebase-config.json';
const serverState = window.__initialState;
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
ReactDOM.hydrate(
<App isBrowser={true} animals={serverState.animals} />,
document.getElementById('app')
);

View File

@@ -1,8 +0,0 @@
{
"apiKey": "AIzaSyBg3u1sJlyJwQCE95oSDH_mtLABS-is8ZM",
"authDomain": "rxfire-525a3.firebaseapp.com",
"databaseURL": "https://rxfire-525a3.firebaseio.com",
"projectId": "rxfire-525a3",
"storageBucket": "rxfire-525a3.appspot.com",
"messagingSenderId": "844180061847"
}

View File

@@ -1,20 +0,0 @@
const x = (appMarkup: string, initialState: string) => {
return `<!DOCTYPE html>
<html>
<head>
<title>Empty project</title>
<meta charset="utf-8" />
<link href="https://unpkg.com/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<script>
window.__initialState = ${initialState}
</script>
<div id="app">${appMarkup}</div>
<script src="dist/client.js"></script>
</body>
</html>`;
};
export default x;

View File

@@ -1,50 +0,0 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom/server';
import express from 'express';
import htmlTemplate from './html-template';
import App from './App';
import serviceAccount from './firebase-key.json';
import admin from 'firebase-admin';
const app = express();
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://rxfire-525a3.firebaseio.com'
});
const serializeQuerySnapshot = (snap: admin.firestore.QuerySnapshot): any[] => {
const items: any[] = [];
snap.forEach(dataSnap => {
items.push({ id: dataSnap.id, data: dataSnap.data() });
});
return items;
};
const db = admin.firestore();
app.use('/dist', express.static(`dist/client`));
app.get('/*', async (req, res) => {
console.log('got a request');
const animalsSnapShot = await db.collection('animals').get();
const serializedAnimalSnapshot = serializeQuerySnapshot(animalsSnapShot);
const markup = ReactDOM.renderToString(
<App isBrowser={false} animals={serializedAnimalSnapshot} />
);
const html = htmlTemplate(
markup,
JSON.stringify({ animals: serializedAnimalSnapshot })
);
res.send(html);
});
const PORT = 3030;
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}...`);
});

View File

@@ -1,16 +0,0 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"module": "esNext",
"moduleResolution": "node",
"target": "es5",
"allowJs": true,
"jsx": "react",
"resolveJsonModule": true
},
"include": ["./src/**/*"]
}

View File

@@ -5,11 +5,7 @@
},
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",

View File

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB