Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbuntinx committed Jul 28, 2020
0 parents commit c8909ab
Show file tree
Hide file tree
Showing 34 changed files with 7,082 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_ENDPOINT=https://conduit.productionready.io
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/bower_components/
/node_modules/
/.pulp-cache/
/output/
/generated-docs/
/.psc-package/
/.psc*
/.purs*
/.psa*
/dist/
/.cache/
/.spago/
/*.log
/.parcel-cache
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"purescript.addNpmPath": true,
"purescript.addPscPackageSources": true,
"purescript.addSpagoSources": true,
"purescript.editorMode": true,
"purescript.buildCommand": "spago build --purs-args \"--json-errors\"",
"[purescript]": {
"editor.formatOnSave": true
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Jonas Buntinx

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Real World PureScript React
Empty file added assets/.gitkeep
Empty file.
30 changes: 30 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Conduit</title>
<link
href="//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"
rel="stylesheet"
type="text/css"
/>
<link
href="//fonts.googleapis.com/css?family=Titillium+Web:700|Source+Serif+Pro:400,700|Merriweather+Sans:400,700|Source+Sans+Pro:400,300,600,700,300italic,400italic,600italic,700italic"
rel="stylesheet"
type="text/css"
/>
<link
href="//demo.productionready.io/main.css"
rel="stylesheet"
type="text/css"
/>
</head>

<body>
<div id="conduit"></div>
<script src="./index.js"></script>
</body>

</html>
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("~/output/Main").main();
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "purescript-react-realworld",
"version": "1.0.0",
"description": "A real-world application demonstrating PureScript and React",
"keywords": [
"Purescript",
"React",
"RealWorld"
],
"author": "Jonas Buntinx",
"license": "MIT",
"scripts": {
"build": "spago build",
"bundle": "yarn build && parcel build index.html",
"clean": "rm -Rf .cache dist output",
"dev-server": "parcel serve --no-source-maps index.html",
"id": "pscid",
"pscid:build": "yarn build",
"postinstall": "spago install",
"rebuild": "yarn clean && yarn build",
"rebundle": "yarn clean && yarn bundle",
"serve": "yarn build && yarn dev-server",
"test": "spago test"
},
"devDependencies": {
"parcel": "^1.12.4",
"pscid": "^2.9.3",
"purescript": "^0.13.8",
"purescript-psa": "^0.7.3",
"purty": "^6.2.0",
"spago": "^0.15.3"
},
"dependencies": {
"moment": "^2.27.0",
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
168 changes: 168 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{-
Welcome to your new Dhall package-set!
Below are instructions for how to edit this file for most use
cases, so that you don't need to know Dhall to use it.
## Warning: Don't Move This Top-Level Comment!
Due to how `dhall format` currently works, this comment's
instructions cannot appear near corresponding sections below
because `dhall format` will delete the comment. However,
it will not delete a top-level comment like this one.
## Use Cases
Most will want to do one or both of these options:
1. Override/Patch a package's dependency
2. Add a package not already in the default package set
This file will continue to work whether you use one or both options.
Instructions for each option are explained below.
### Overriding/Patching a package
Purpose:
- Change a package's dependency to a newer/older release than the
default package set's release
- Use your own modified version of some dependency that may
include new API, changed API, removed API by
using your custom git repo of the library rather than
the package set's repo
Syntax:
Replace the overrides' "{=}" (an empty record) with the following idea
The "//" or "⫽" means "merge these two records and
when they have the same value, use the one on the right:"
-------------------------------
let overrides =
{ packageName =
upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" }
, packageName =
upstream.packageName // { version = "v4.0.0" }
, packageName =
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
}
-------------------------------
Example:
-------------------------------
let overrides =
{ halogen =
upstream.halogen // { version = "master" }
, halogen-vdom =
upstream.halogen-vdom // { version = "v4.0.0" }
}
-------------------------------
### Additions
Purpose:
- Add packages that aren't already included in the default package set
Syntax:
Replace the additions' "{=}" (an empty record) with the following idea:
-------------------------------
let additions =
{ package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, etc.
}
-------------------------------
Example:
-------------------------------
let additions =
{ benchotron =
{ dependencies =
[ "arrays"
, "exists"
, "profunctor"
, "strings"
, "quickcheck"
, "lcg"
, "transformers"
, "foldable-traversable"
, "exceptions"
, "node-fs"
, "node-buffer"
, "node-readline"
, "datetime"
, "now"
]
, repo =
"https://github.com/hdgarrood/purescript-benchotron.git"
, version =
"v7.0.0"
}
}
-------------------------------
-}


let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.8/packages.dhall sha256:0e95ec11604dc8afc1b129c4d405dcc17290ce56d7d0665a0ff15617e32bbf03

let overrides =
{ simple-json =
upstream.simple-json
// { repo = "https://github.com/robertdp/purescript-simple-json.git"
, version = "v7.0.1"
}
}

let additions =
{ apiary =
{ dependencies =
[ "media-types"
, "milkis"
, "simple-json"
]
, repo = "https://github.com/robertdp/purescript-apiary"
, version = "v0.1.0"
}
, react-basic-hooks-store =
{ dependencies =
[ "avar"
, "console"
, "prelude"
, "react-basic-hooks"
]
, repo = "https://github.com/robertdp/purescript-react-basic-hooks-store"
, version = "v0.2.2"
}
, wire =
{ dependencies =
[ "arrays"
, "filterable"
, "foreign-object"
, "free"
, "freet"
, "react-basic-hooks"
, "refs"
, "unsafe-reference"
]
, repo = "https://github.com/robertdp/purescript-wire"
, version = "v0.4.1"
}
}

in upstream // overrides // additions
20 changes: 20 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ name = "purescript-react-realword"
, dependencies =
[ "apiary"
, "console"
, "effect"
, "foreign-generic"
, "heterogeneous"
, "js-timers"
, "profunctor-lenses"
, "react-basic"
, "react-basic-hooks"
, "react-basic-hooks-store"
, "routing"
, "routing-duplex"
, "web-uievents"
, "wire"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
39 changes: 39 additions & 0 deletions src/Conduit/Api/User.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Conduit.Api.User where

import Apiary.Media (JSON)
import Apiary.Route (POST)
import Data.Maybe (Maybe)

type Login
= POST "/api/users/login"
{ body ::
JSON
{ user ::
{ email :: String
, password :: String
}
}
, response ::
{ ok ::
JSON
{ user :: User ()
}
}
}

-- | Types
type User r
= Profile
( token :: Token
| r
)

type Profile r
= { username :: String
, bio :: Maybe String
, image :: Maybe String
| r
}

type Token
= String
26 changes: 26 additions & 0 deletions src/Conduit/Api/Utils.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Conduit.Api.Utils where

import Prelude
import Apiary.Client (Error, makeRequest) as Apiary
import Apiary.Client.Request (class BuildRequest) as Apiary
import Apiary.Client.Response (class DecodeResponse) as Apiary
import Conduit.Data.Config as Config
import Data.Either (Either)
import Effect.Aff.Class (class MonadAff, liftAff)
import Milkis as Milkis

makeRequest ::
forall m route path query body rep response.
MonadAff m =>
Apiary.BuildRequest route path query body rep =>
Apiary.DecodeResponse rep response =>
route ->
path ->
query ->
body ->
m (Either Apiary.Error response)
makeRequest route path query body = liftAff $ Apiary.makeRequest route addBaseUrl path query body

-- | Helpers
addBaseUrl :: forall r. { url :: Milkis.URL | r } -> { url :: Milkis.URL | r }
addBaseUrl request@{ url: Milkis.URL url } = request { url = Milkis.URL (Config.apiEndpoint <> url) }
Loading

0 comments on commit c8909ab

Please sign in to comment.