Skip to content

Commit

Permalink
Merge pull request #31 from Plebeian-Technology/padawan
Browse files Browse the repository at this point in the history
Padawan
  • Loading branch information
dcordz authored Jun 6, 2024
2 parents 55359a8 + 2017580 commit f5ec1b0
Show file tree
Hide file tree
Showing 231 changed files with 34,594 additions and 17,001 deletions.
37 changes: 0 additions & 37 deletions .eslintignore

This file was deleted.

82 changes: 0 additions & 82 deletions .eslintrc.cjs

This file was deleted.

11 changes: 7 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ gem 'rgeo-geojson'
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem 'dartsass-rails', '~> 0.5.0'
# gem 'dartsass-rails'
# gem 'dartsass-rails', '~> 0.5.0'
gem 'sassc-rails'

gem 'bootstrap', '~> 5.3.2'


# https://github.com/BrandonShar/inertia-rails-template/blob/main/Gemfile
gem 'vite_rails'

Expand Down Expand Up @@ -114,8 +115,6 @@ group :development, :test do

gem 'pry'

gem 'better_errors'

# https://github.com/rspec/rspec-rails
# Run against this stable release
gem 'rspec-rails', '~> 6'
Expand Down Expand Up @@ -161,6 +160,10 @@ group :development do

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"

# https://github.com/BetterErrors/better_errors
gem "better_errors"
gem "binding_of_caller"
end

group :test do
Expand Down
24 changes: 4 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ GEM
bigdecimal (3.1.8)
bindata (2.5.0)
bindex (0.8.1)
binding_of_caller (1.0.1)
debug_inspector (>= 1.2.0)
bootsnap (1.18.3)
msgpack (~> 1.2)
bootstrap (5.3.3)
Expand All @@ -117,13 +119,11 @@ GEM
openssl-signature_algorithm (~> 1.0)
crass (1.0.6)
csv (3.3.0)
dartsass-rails (0.5.0)
railties (>= 6.0.0)
sass-embedded (~> 1.63)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
debug_inspector (1.2.0)
declarative (0.0.20)
diff-lcs (1.5.1)
digest-crc (0.6.5)
Expand Down Expand Up @@ -177,14 +177,6 @@ GEM
google-cloud-core (~> 1.6)
googleauth (~> 1.9)
mini_mime (~> 1.0)
google-protobuf (4.26.1-aarch64-linux)
rake (>= 13)
google-protobuf (4.26.1-arm64-darwin)
rake (>= 13)
google-protobuf (4.26.1-x86_64-darwin)
rake (>= 13)
google-protobuf (4.26.1-x86_64-linux)
rake (>= 13)
googleauth (1.11.0)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
Expand Down Expand Up @@ -379,14 +371,6 @@ GEM
rubyzip (2.3.2)
safety_net_attestation (0.4.0)
jwt (~> 2.0)
sass-embedded (1.77.2-aarch64-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.2-arm64-darwin)
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.2-x86_64-darwin)
google-protobuf (>= 3.25, < 5.0)
sass-embedded (1.77.2-x86_64-linux-gnu)
google-protobuf (>= 3.25, < 5.0)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
Expand Down Expand Up @@ -508,11 +492,11 @@ PLATFORMS
DEPENDENCIES
annotate
better_errors
binding_of_caller
bootsnap
bootstrap (~> 5.3.2)
capybara
concurrent-ruby
dartsass-rails (~> 0.5.0)
debug
dotenv
factory_bot_rails
Expand Down
1 change: 0 additions & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

vite: bin/vite dev
web: bin/rails server -b 'ssl://localhost:3000?key=config/ssl/key.pem&cert=config/ssl/cert.pem&verify_mode=none'
css: bin/rails dartsass:watch
133 changes: 129 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Because of these difficulties, it can be challenging to hold elected representat
- [Locales](#locales)
- [Current Supported Locales](#current-supported-locales)
- [Onboard a New Locale](#onboard-a-new-locale)
- [Feature Roadmap](#feature-roadmap)
- [Development](#development)
- [Environment Variables](#environment-variables)
- [Running Sway](#running-sway)

## Contributing

Expand All @@ -47,7 +49,7 @@ Sway is designed to work with and be extended to multiple locations regardless o

### Onboarding

To add a new locale, create a new [Issue](https://github.com/Plebeian-Technology//sway-rails/issues) and label it as `locale` and include the below files:
To add a new locale, create a new [Issue](https://github.com/Plebeian-Technology/sway/issues) and label it as `locale` and include the below files:

- An SVG image avatar for the locale, usually a flag representing that municipality. See [/public/images/avatars/baltimore-maryland-united_states.svg](/public/images/avatars/baltimore-maryland-united_states.svg) as an example. Wikipedia and Twitter are good sources to get these from.

Expand All @@ -57,11 +59,102 @@ To add a new locale, create a new [Issue](https://github.com/Plebeian-Technology

- To add and/or update Legislators in Sway, please provide a `legislators.json` file. For an example of the file structure, see [the Baltimore legislators.json file.](/storage/seeds/data/united_states/maryland/baltimore/legislators.json)

Once the above have been assembled, we will work with you to get them into Sway!

---

## Development

#### Create SSL Certificates for Local Development
### Environment Variables

1. Create a .env.development file at the root directory of the project.

NOTE: All the values set here are only used for development and should NOT be commited to git. Values should not include opening and closing "".

2. Sign up for Twilio and set the values the below keys:

You can get the ACCOUNT_SID and AUTH_TOKEN values by clicking "Account" at the top-right and then "API keys & tokens" on the left sidebar.

TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_VERIFY_SERVICE_SID=

To get a VERIFY_SERVICE_SID you must sign up for Twilio Verify, which Sway uses as one factor in the user authentication flow. To create a Verification Service you can use the Twilio API via the guide here - [https://www.twilio.com/docs/verify/api](https://www.twilio.com/docs/verify/api), or you can use the Twilio Console:

1. Click the "Develop" tab on the left sidebar.

2. Click "Explore Products +" on the left sidebar.

3. Scroll down and click "Verify".

4. Create a new Verify service.

3. Create a Google Cloud account and add values for the below keys:

GOOGLE_MAPS_API_KEY=

Sway uses Google Maps for geocoding user addresses into latitude/longitude coordinates during registration. These coordinates are then used with a geojson file and Census.gov API to determine a user's representatives in a given SwayLocale.

To create this key:

1. Click on the Navigation menu.

2. Hover over APIs & Services and click 'Enabled APIs & services'

3. Click the "+ ENABLE APIS AND SERVICES" button at the top.

4. Enable the "Maps JavaScript API"

5. On the sidebar, click "Keys & Credentials"

6. Generate an API Key with:
* a website restriction to localhost
* The "Maps JavaScript API" selected
* The "Places API" selected
* The "Geocoding API" selected

4. Create VAPID keys and set values for the keys below:

VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=

Sway uses these keys to send web push notifications via the [web-push](https://github.com/pushpad/web-push) ruby gem.

You can generate keys after running `bundle install` by opening the rails console with `rails c` and running:

```ruby
irb(main):001> WebPush.generate_key

=> #<WebPush::VapidKey:67d4 :public_key=BDH9S_5CtkeVBJmtGxcrXD7_bXyp4GyxYMiuH4Rlh0RW6dhsj3Arurxkf-0_BI2kLaUBFLcfIi9fi2K8wqxSUq0= :private_key=wsx-vK4_ZFULdXlqSnE2VJPc548k1ihydsfzqZKtDFY=>
```

Copy the full key, including the `=` at the end into each environment variable above.

You can read more about web push notifications here:

[https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices](https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Best_Practices)
[https://web.dev/articles/push-notifications-web-push-protocol](https://web.dev/articles/push-notifications-web-push-protocol)
[https://medium.com/@dejanvu.developer/implementing-web-push-notifications-in-a-ruby-on-rails-application-dcd829e02df0](https://medium.com/@dejanvu.developer/implementing-web-push-notifications-in-a-ruby-on-rails-application-dcd829e02df0)

5. Add your phone number as an Admin phone number by setting the below key in the same format:

ADMIN_PHONES=1234567890

Only administrators can create new Bills in Sway.

6. Set a database password:

SWAY_DATABASE_PASSWORD=sway2000!!

Just a reminder that this is only used for development.

### Running Sway

#### Create SSL Certificates

```zsh
brew install mkcert
Expand All @@ -71,7 +164,39 @@ mv localhost.pem config/ssl/cert.pem
mv localhost-key.pem config/ssl/key.pem
```

Once the above have been assembled, we will work with you to get them into Sway!
1. In one terminal window/tab/pane:

#### Set up Rails
```zsh
bundle install
bundle exec rails db:create
bundle exec rails db:migrate
bundle exec rails db:schema:load

# Load seeds including locales and geojson files
bundle exec rails db:seed
```

#### Run Rails
```zsh
bin/rails server -b 'ssl://localhost:3000?key=config/ssl/key.pem&cert=config/ssl/cert.pem&verify_mode=none'
```

2. In a second terminal window/tab/pane:

#### Setup React with Vite
```zsh
npm install
```

#### Run React with Vite
```zsh
./bin/vite dev
```

#### Browser

Open your browser to [https://localhost:3000](https://localhost:3000) to begin working with Sway.

## Copyright / License

Expand Down
2 changes: 1 addition & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//= link application.css
//= link_directory ../stylesheets/scss .css
//= link_tree ../stylesheets .scss
//= link_directory ../images
Loading

0 comments on commit f5ec1b0

Please sign in to comment.