Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Basic Sleep App issue #53 #57

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fe1ca06
mix phx.new app #53
nelsonic Dec 8, 2021
60ce732
add outline of desired functionality in "How?" section for #53
nelsonic Dec 9, 2021
dac8dcb
[WiP] add detail to README.md for #53
nelsonic Feb 20, 2022
ec90683
move tutorial to its own file #53
nelsonic Feb 20, 2022
6fb3a05
update version of Phoenix to 1.6.6
nelsonic Feb 20, 2022
4ef32da
add context for "App" Namespace to tutorial.md #53
nelsonic Mar 6, 2022
59cf727
Create .github/workflows/ci.yml to run tests #53
nelsonic Mar 13, 2022
6231fab
add more detail to README.md and links in tutorial.md #53
nelsonic Mar 13, 2022
f48898f
add ExCoveralls & coveralls.json to check test coverage #53
nelsonic Mar 13, 2022
f8c7cd3
temporarily lower coverage threshold to 40% to avoid noise while buil…
nelsonic Mar 13, 2022
56318a2
3. Create app_live.ex and insert code #53
nelsonic Mar 13, 2022
9001fbb
4. Create app_view.ex and add essential code #53
nelsonic Mar 13, 2022
da04c74
5. rename page/index.html.heex to app/index.html.heex and simplify co…
nelsonic Mar 13, 2022
2952ed4
5. simplify templates/layout/root.html.heex to bare minimum #53
nelsonic Mar 13, 2022
0280658
6. Modify router.ex to point to the AppLive instead of Page #53
nelsonic Mar 13, 2022
3468016
add steps to tutorial.md #53
nelsonic Mar 13, 2022
2b2ba87
7. Add step to tutorial.md to repair broken test #53
nelsonic Mar 13, 2022
30d16e2
Create elixir_buildpack.config and Procfile to deploy demo to Heroku #53
nelsonic Mar 13, 2022
8897af8
update elixir_buildpack.config and Procfile to always_rebuild=true & …
nelsonic Mar 13, 2022
6129fa1
use ssl for DB connection on Heroku #53
nelsonic Mar 13, 2022
f6e1c3f
use ssl for DB connection on Heroku #53
nelsonic Mar 13, 2022
3c16d10
Check for DYNO envar instead of HEROKU for db ssl #53
nelsonic Mar 13, 2022
1636477
set preferred_cli_env for mix coveralls.json task to :test #53
nelsonic Mar 13, 2022
ec5d89a
[WiP] add section on test coverage #53
nelsonic Mar 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
import_deps: [:ecto, :phoenix],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Elixir CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build and test
environment: sleep
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
with:
elixir-version: '1.12.3' # Define the elixir version [required]
otp-version: '24.0.2' # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run Tests
run: mix coveralls.json

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
app-*.tar

# Ignore assets that are produced by build tools.
/priv/static/assets/

# Ignore digested assets cache.
/priv/static/cache_manifest.json

# In case you use Node.js/npm, you want to ignore these.
npm-debug.log
/assets/node_modules/

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: MIX_ENV=prod mix ecto.migrate && mix assets.deploy && mix phx.server
280 changes: 278 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,278 @@
# sleep
Insomnia :-(
<div align="center">

# sleep 💤

![sleep-hero-image](https://user-images.githubusercontent.com/194400/159523182-0db2588a-658d-45ae-8ce3-98c37a47ca72.jpeg)


## “_Sleep is the single most effective thing we can do <br /> to reset our brain and body health each day._” <br /> ~ Matthew Walker, Why We Sleep

<br />

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/dwyl/sleep/Elixir%20CI?label=build&style=flat-square)](https://github.com/dwyl/phoenix-liveview-chat-example/actions/workflows/cy.yml)
[![codecov test coverage](https://img.shields.io/codecov/c/github/dwyl/sleep/main.svg?style=flat-square)](https://codecov.io/github/dwyl/phoenix-liveview-chat-example?branch=main)
[![Hex pm](https://img.shields.io/hexpm/v/phoenix_live_view.svg?style=flat-square)](https://hex.pm/packages/phoenix_live_view)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/phoenix-liveview-counter-tutorial/issues)
[![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep)

**Try it**: [**sleepdev.herokuapp.com**](https://sleepdev.herokuapp.com/)

</div>

<br />

Sleep is the cornerstone of a healthy life;
it restores your tired body
and consolidates neural connections
to help form/retain memories.
A good night's sleep
can dramatically increase effectiveness
in all areas of your life.
Tracking your sleep times
and reflecting on your sleep quality
can help you focus on this vital
aspect of health and longevity.

<br />

# Why? 🤷‍♀️

When you sleep well and feel rested,
you have mental clarity and energy
to focus on making progress in life. <br />
By contrast if you don't get a good night's sleep
virtually everything about your day
will be worse.

We wanted a simple way to: <br />
**a)** ***Track*** our own sleep/wake time & quality.<br />
**b)** ***Visualize*** our sleep patterns over time.<br />
**c)** ***Share*** that data with our significant other or any other relevant person.<br />

## Why Write a _Tutorial_? 💭

We decided to write this as a **step-by-step tutorial**
because it's a great opportunity
to document the whole process of building the App.
And it means anyone following along
can
[grok](https://en.wikipedia.org/wiki/Grok)
it
and even **_extend_ it**
to add their own features.


<br />

# What? 📱 🛌

This App is the simplest possible **sleep tracker**.
<!-- other than using a notepad + pen
or notes App ... -->
A **_deliberately_ basic** version of an App is
commonly referred to as Minimum Viable Product ("MVP")
which means it has the minimum features to be useful,
but leaves the possible enhancements out.
If you think of a feature/improvement, _please_
[**open an issue**!](https://github.com/dwyl/sleep/issues).
**Contributions/ideas** are **_always_ welcome**
and we're delighted to extend this
in response to feedback!

<br />

# Who? 👤

_Everyone_ that sleeps.

<br />

# When? 🕗

You can start using the MVP _now_ (_tonight_)!

> If you're reading this past **22:00**,
go straight to the "***Try it!***" section
and start recording your sleep _now_.
Please bookmark (⭐) the project
and come back to it tomorrow when you're fresh.

<br />

It's never too late
to start focusing on your sleep quality.
The benefits of good sleep habits
will last the rest of your life
and may _extend_ it!

<br />

# How? 👩‍💻

There are 3 steps to this:

1. _Try_ it! (2 mins)
2. _Run_ it! (5 mins)
3. _Build_ it! (20 mins)

Let's get started.

<br />

## 1. _Try_ it!

First, if you haven't already,
_try_ the App via Heroku:
[sleepdev.herokuapp.com](https://sleepdev.herokuapp.com)
to get a sense for the interface.

# @TODO: insert GIF of _performing_ the actions!

Try the following actions:

+ **Log _in_**
+ **_Start_** a sleep timer
+ **Stop** the timer - to confirm that it works.
+ **Log _out_** - to confirm that no data is stored in the browser.
+ **Log _back in_** - with the same Google or GitHub account you used to login before.
+ ***Confirm*** your "sleep" session was recorded.

Once you've given the app a quick test,
it's time try _running_ it.

<br />

## 2. _Run_ it!

Now that you've tried it on Heroku,
if you want to dig deeper,
try running the _finished_ (MVP) on your computer.


## Prerequisites 📝

Make sure you have the following installed:

+ [x] Elixir:
https://elixir-lang.org/install.html
+ [x] Postgres:
https://www.postgresql.org/download

### _Check_ You Have Everything Ready _Before_ Starting

Check you have the _latest version_ of **Elixir**
(_run the following command in your terminal_):

```sh
elixir -v
```

You should see something like:

```sh
Erlang/OTP 24 [erts-12.1.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Elixir 1.13 (compiled with Erlang/OTP 22)
```

_Confirm_ **PostgreSQL** is running (_so the App can store chat messages_)
run the following command:

```sh
lsof -i :5432
```

You should see output _similar_ to the following:

```sh
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 529 Alex 5u IPv6 0xbc5d729e529f062b 0t0 TCP localhost:postgresql (LISTEN)
postgres 529 Alex 6u IPv4 0xbc5d729e55a89a13 0t0 TCP localhost:postgresql (LISTEN)
```

This tells us that `postgresql`
is "_listening_" on TCP Port `5432`
(_the default port_).
If Postgres is not running,
check the docs for you OS.

With all those
[pre-flight checks](https://en.wikipedia.org/wiki/Preflight_checklist)
done, let's get _flying_!

<br />

## Clone, Install & Run the App!

Open a terminal window and run the following commands:

Clone the project to your computer:

```
git clone [email protected]:dwyl/sleep.git
```

Navigate to the **`sleep`** directory:

```
cd sleep
```


Install the dependencies:

```
mix deps.get
```

_Run_ the app:

```
mix phx.server
```

Open the following URL in your web browser:
http://localhost:4000


You should expect to see the following:

# @TODO: insert screenshot of _finished_ app!

<br />

## 3. _Build_ it! 🚀

Now that you know what the end result
looks & feels like
and you have a reference implementation
that you _know_ works on your computer,
it's time to write some **`code`**

## `GOTO:` [`tutorial.md`](https://github.com/dwyl/sleep/blob/main/tutorial.md)

<br />


<!--

# Research

We have read several books on sleep (_so you don't have to_).

Research findings in byte-size format to follow soon!


### “_Before you sleep, read something that is exquisite, and worth remembering._” ~ <br /> Desiderius Erasmus

## Why Focus on Sleep?

If you aren't sleeping enough
you will not be able to function.

## How Sleep Affects You

> Insert table of good vs. bad sleep.

-->
![wake-sleeping-heroku-app](https://liveview-chat-example.herokuapp.com/ping)
Loading