Skip to content

Commit d5539bc

Browse files
authored
Merge pull request #335 from EnCiv/civil-updates-1
Civil updates 1
2 parents e5c9cb4 + e1ec0ee commit d5539bc

File tree

132 files changed

+70883
-13437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+70883
-13437
lines changed

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,19 @@ app/svgr
8484
# Cypress screenshots and recordings
8585
cypress/videos
8686
cypress/screenshots
87+
88+
# Ignore because it's autogenerated
89+
app/web-components/index.js
90+
app/data-components/index.js
91+
92+
#less history
93+
.lesshst
94+
95+
#temp directory
96+
tmp
97+
98+
#directories that might contain secrets
99+
.ssh/
100+
101+
#this is used by Jest-mongodb for testing only -
102+
globalConfig.json

.storybook/main.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const webpack = require('webpack')
2+
3+
module.exports = {
4+
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
5+
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
6+
framework: '@storybook/react',
7+
core: {
8+
builder: 'webpack5',
9+
},
10+
webpackFinal: async config => {
11+
// config may or may not have these properties so we have to make sure they are there and then modify them to ensure we don't delete anything
12+
if (!config.resolve) config.resolve = {}
13+
if (!config.resolve.fallback) config.resolve.fallback = {}
14+
Object.assign(config.resolve.fallback, {
15+
fs: false,
16+
buffer: require.resolve('buffer'),
17+
path: require.resolve('path-browserify'),
18+
stream: require.resolve('stream-browserify'),
19+
os: require.resolve('os-browserify/browser'),
20+
zlib: require.resolve('browserify-zlib'),
21+
constants: require.resolve('constants-browserify'),
22+
util: require.resolve('util'),
23+
})
24+
if (!config.plugins) config.plugins = []
25+
config.plugins.push(new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }))
26+
config.plugins.push(new webpack.ProvidePlugin({ process: 'process/browser' })) // fix "process is not defined" error: // (do "npm install process" before running the build)
27+
for (const plugin of config.plugins) {
28+
if (plugin.definitions) {
29+
if (plugin.definitions['process.env']) {
30+
console.info(
31+
'.storybook/main.js: deleting process.env from',
32+
{ plugin },
33+
'see comments in that file'
34+
)
35+
delete plugin.definitions['process.env']
36+
/*
37+
webpack will try to string replace process.env with what is assigned in the definition.
38+
// But if there is code in the browser side that does something like "if(process.env)" it will get replaced and cause syntax error and break the existing code
39+
40+
definitions{
41+
...
42+
"process.env": "{\"NODE_ENV\":\"development\",\"NODE_PATH\":[],\"STORYBOOK\":\"true\",\"PUBLIC_URL\":\".\"}",
43+
...
44+
}
45+
46+
causes this:
47+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'development'
48+
to become
49+
if (!{"NODE_ENV":"development","NODE_PATH":["/usr/lib64/node_modules"],"STORYBOOK":"true","PUBLIC_URL":"."}) {"NODE_ENV":"development","NODE_PATH":["/usr/lib64/node_modules"],"STORYBOOK":"true","PUBLIC_URL":"."} = {};
50+
*/
51+
}
52+
}
53+
}
54+
return config
55+
},
56+
}

.storybook/preview.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import { ThemeProvider } from 'react-jss'
3+
import theme from '../app/theme'
4+
5+
export const parameters = {
6+
actions: { argTypesRegex: '^on[A-Z].*' },
7+
}
8+
9+
export const decorators = [
10+
Story => {
11+
if (typeof window.logger === 'undefined') window.logger = console
12+
if (typeof socket === 'undefined') window.socket = {}
13+
window.socket.NoSocket = true
14+
return (
15+
<ThemeProvider theme={theme}>
16+
<div style={{ backgroundColor: theme.backgroundColorApp }}>
17+
<Story />
18+
</div>
19+
</ThemeProvider>
20+
)
21+
},
22+
]

README.md

-95
Original file line numberDiff line numberDiff line change
@@ -40,101 +40,6 @@ This project is now using prettier. This makes some spacing and the user of quot
4040

4141
If you are not using VSC prettier will also be run before you commit, but see if prettier is available for your editor and post instuctions here
4242

43-
## How to add a new web page to the server
44-
45-
Here is the flow. When a user visits the server with a url, `getIota()` in [server](./app/server/server.js) will look up the path in the database. If it finds a match, it will look for a webComponent and render that on the server through [app/server/routes/serverReactRender](./app/server/routes/server-react-render.jsx). All the properties of this webComponent will be passed as props to the corresponding React component.Then the page will be sent to the browser, and then rehydrated there, meaning the webComponent will run again on the browser, starting at [app/client/main.js](./app/client/main.js) and react will connect all the DOM elements.
46-
47-
### 1) Add a React Component to [./app/components/web-components](./app/components/web-components)\*\*
48-
49-
here is simple one, [./app/components/web-components/undebate-iframes.jsx](./app/components/web-components/undebate-iframes.jsx):
50-
51-
```
52-
'use strict'
53-
54-
import React from 'react'
55-
import injectSheet from 'react-jss'
56-
57-
58-
const styles = {
59-
title: {
60-
color: 'black',
61-
fontSize: '2rem',
62-
textAlign: 'center',
63-
},
64-
frame: { marginTop: '1em', marginBottom: '1em', width: '100vw' },
65-
}
66-
67-
class UndebateIframes extends React.Component {
68-
render() {
69-
const { classes } = this.props
70-
const width = typeof window !== 'undefined' ? window.innerWidth : 1920
71-
const height = typeof window !== 'undefined' ? window.innerHeight : 1080
72-
73-
return (
74-
<div>
75-
<div>
76-
<span className={classes['title']}>These are the Undebates</span>
77-
</div>
78-
<iframe
79-
className={classes.frame}
80-
height={height * 0.9}
81-
width={width}
82-
name="race1"
83-
src="https://cc.enciv.org/san-francisco-district-attorney"
84-
/>
85-
<iframe
86-
className={classes.frame}
87-
height={height * 0.9}
88-
width={width}
89-
name="race2"
90-
src="https://cc.enciv.org/country:us/state:wi/office:city-of-onalaska-mayor/2020-4-7"
91-
/>
92-
</div>
93-
)
94-
}
95-
}
96-
export default injectSheet(styles)(UndebateIframes)
97-
```
98-
99-
### 2) Add that component to the [index.js](./components/web-components/index.js)
100-
101-
```
102-
...
103-
const WebComponents = {
104-
TestJoin: require('./test-join'),
105-
...
106-
UndebateIframes: require('./undebate-iframes'),
107-
}
108-
...
109-
```
110-
111-
Wish List: I wish that this file could be automatically generated based on the files in the directory. For now, we do it manually.
112-
113-
### 3) Create a new document in the iotas collection of the database
114-
115-
The example is the minimum information required. Any additional properties you add to webComponent will be passed as props to the associated React component.
116-
117-
```
118-
{
119-
"path": "/iframe-demo",
120-
"subject": "Iframe demo",
121-
"description": "a quick prototype of a page showing multiple undebates in separate iframes",
122-
"webComponent": {
123-
"webComponent": "UndebateIframes"
124-
},
125-
}
126-
```
127-
128-
Note that the \_id property is not shown here. When you add this document to the database, it will automatically assign the \_id.
129-
130-
### 4) Add new document to iota.js
131-
132-
If the new document that you are creating should be included in every new installation, then you should add the document, with the \_id assigned, to [iota.json](./iota.json)
133-
134-
### 5) Advanced: Component
135-
136-
If your page should pull data out of the database, or calculate something to pass to the web component, then you can add a component to [app/components/components](./app/components/data-components), add it to the [app/components/data-components/index.js](./app/components/data-components/index.js) and then add a component: {component: YourComponentNane, ...} to the document above.
137-
13843
## Database
13944

14045
There is a tool that lets you view and edit the database in a browser window. This has been really useful in development. To get there:

app/api/send-contact-us.js

-26
This file was deleted.

app/api/socketlogger.js

-8
This file was deleted.

app/client/bconsole.js

-26
This file was deleted.

app/client/client-side-clustering.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
// clustering is a node thing, dummy it out on the client side
4+
5+
export function isMaster() {
6+
return true
7+
}
8+
9+
export function onlyOnMaster(f1, f2) {
10+
return f1()
11+
}
12+
13+
export function onMessage() {
14+
return
15+
}
16+
export function send() {
17+
return
18+
}
File renamed without changes.

app/client/main-app.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict'
2+
3+
import { clientMain } from 'civil-client'
4+
import App from '../components/app'
5+
6+
// this is the entry point for the client App running on the browser
7+
// App will be run on both the server side, and the client side, but the stuff in clientMain will only be run to set things up on the browser
8+
clientMain(App)

0 commit comments

Comments
 (0)