WIP
This commit is contained in:
77
src/Client/Client.fs
Normal file
77
src/Client/Client.fs
Normal file
@@ -0,0 +1,77 @@
|
||||
module Client
|
||||
|
||||
open Elmish
|
||||
open Elmish.React
|
||||
open Fable.React
|
||||
open Fable.React.Props
|
||||
open Fetch.Types
|
||||
open Thoth.Fetch
|
||||
open Fulma
|
||||
open Thoth.Json
|
||||
open Browser.Types
|
||||
open Shared
|
||||
|
||||
let [<Literal>] ENTER_KEY = 13.
|
||||
|
||||
let onEnter msg dispatch =
|
||||
OnKeyDown (fun ev ->
|
||||
if ev.keyCode = ENTER_KEY then
|
||||
dispatch msg)
|
||||
|
||||
let targetValue (ev: Event) =
|
||||
(ev.target :?> HTMLInputElement).value
|
||||
|
||||
type Model = { Run: Run }
|
||||
|
||||
type Msg =
|
||||
| StartRun
|
||||
| UpdateName of string
|
||||
|
||||
//let initialCounter () = Fetch.fetchAs<Counter> "/api/init"
|
||||
|
||||
let init () : Model * Cmd<Msg> =
|
||||
let initialModel = { Run = { Name = "george" } }
|
||||
initialModel, Cmd.none
|
||||
|
||||
let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> =
|
||||
match msg with
|
||||
| StartRun ->
|
||||
let nextModel = { currentModel with Run = { Name = currentModel.Run.Name + " saved" } }
|
||||
nextModel, Cmd.none
|
||||
| UpdateName newName ->
|
||||
let nextModel = { currentModel with Run = { Name = newName }}
|
||||
nextModel, Cmd.none
|
||||
|
||||
let view (model : Model) (dispatch : Msg -> unit) =
|
||||
Columns.columns []
|
||||
[ Column.column [ Column.Offset (Screen.All, Column.Is3)
|
||||
Column.Width (Screen.All, Column.Is6) ]
|
||||
[ Box.box' []
|
||||
[ Heading.h1 [] [ str "lunch run" ]
|
||||
p [] [ str "Start a lunch run today!" ]
|
||||
Field.div []
|
||||
[ Control.div []
|
||||
[ Input.text [ Input.Placeholder "lunch run name"
|
||||
Input.Value model.Run.Name
|
||||
Input.OnChange (fun ev -> targetValue ev |> UpdateName |> dispatch)
|
||||
Input.Props [ onEnter StartRun dispatch ] ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
#if DEBUG
|
||||
open Elmish.Debug
|
||||
open Elmish.HMR
|
||||
#endif
|
||||
|
||||
Program.mkProgram init update view
|
||||
#if DEBUG
|
||||
|> Program.withConsoleTrace
|
||||
#endif
|
||||
|> Program.withReactBatched "elmish-app"
|
||||
#if DEBUG
|
||||
|> Program.withDebugger
|
||||
#endif
|
||||
|> Program.run
|
||||
16
src/Client/Client.fsproj
Normal file
16
src/Client/Client.fsproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<DefineConstants>FABLE_COMPILER</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="index.html" />
|
||||
<None Include="paket.references" />
|
||||
<None Include="style.scss" />
|
||||
<Compile Include="..\Shared\Shared.fs" />
|
||||
<Compile Include="Version.fs" />
|
||||
<Compile Include="Client.fs" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\.paket\Paket.Restore.targets" />
|
||||
</Project>
|
||||
5
src/Client/Version.fs
Normal file
5
src/Client/Version.fs
Normal file
@@ -0,0 +1,5 @@
|
||||
module Version
|
||||
|
||||
let template = "1.18.0"
|
||||
|
||||
let app = "0.0.1"
|
||||
14
src/Client/index.html
Normal file
14
src/Client/index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>lunch run!</title>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="elmish-app"></div>
|
||||
</body>
|
||||
</html>
|
||||
10
src/Client/paket.references
Normal file
10
src/Client/paket.references
Normal file
@@ -0,0 +1,10 @@
|
||||
group Client
|
||||
FSharp.Core
|
||||
Fable.Core
|
||||
Fable.Elmish.Debugger
|
||||
Fable.Elmish.React
|
||||
Fable.Elmish.HMR
|
||||
Thoth.Fetch
|
||||
Fulma
|
||||
Fable.FontAwesome.Free
|
||||
|
||||
BIN
src/Client/public/favicon.png
Normal file
BIN
src/Client/public/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 810 B |
17
src/Client/style.scss
Normal file
17
src/Client/style.scss
Normal file
@@ -0,0 +1,17 @@
|
||||
@charset "utf-8";
|
||||
|
||||
// FontAwesome
|
||||
$fa_font_path: "~@fortawesome/fontawesome-free/webfonts";
|
||||
@import '~@fortawesome/fontawesome-free/scss/fontawesome.scss';
|
||||
@import '~@fortawesome/fontawesome-free/scss/regular.scss';
|
||||
@import '~@fortawesome/fontawesome-free/scss/solid.scss';
|
||||
@import '~@fortawesome/fontawesome-free/scss/brands.scss';
|
||||
|
||||
// OpenSans
|
||||
$FontPathOpenSans: "~open-sans-fonts/open-sans";
|
||||
@import '~open-sans-fonts/open-sans';
|
||||
$family-primary: 'Open Sans';
|
||||
|
||||
// Bulma
|
||||
@import "~bulma/bulma";
|
||||
|
||||
37
src/Server/Server.fs
Normal file
37
src/Server/Server.fs
Normal file
@@ -0,0 +1,37 @@
|
||||
open System.IO
|
||||
open System.Threading.Tasks
|
||||
|
||||
open Microsoft.AspNetCore.Builder
|
||||
open Microsoft.Extensions.DependencyInjection
|
||||
open FSharp.Control.Tasks.V2
|
||||
open Giraffe
|
||||
open Saturn
|
||||
open Shared
|
||||
|
||||
|
||||
let tryGetEnv = System.Environment.GetEnvironmentVariable >> function null | "" -> None | x -> Some x
|
||||
|
||||
let publicPath = Path.GetFullPath "../Client/public"
|
||||
|
||||
let port =
|
||||
"SERVER_PORT"
|
||||
|> tryGetEnv |> Option.map uint16 |> Option.defaultValue 8085us
|
||||
|
||||
// let webApp = router {
|
||||
// get "/api/init" (fun next ctx ->
|
||||
// task {
|
||||
// let counter = {Value = 7}
|
||||
// return! json counter next ctx
|
||||
// })
|
||||
// }
|
||||
|
||||
let app = application {
|
||||
url ("http://0.0.0.0:" + port.ToString() + "/")
|
||||
//use_router webApp
|
||||
memory_cache
|
||||
use_static publicPath
|
||||
use_json_serializer(Thoth.Json.Giraffe.ThothSerializer())
|
||||
use_gzip
|
||||
}
|
||||
|
||||
run app
|
||||
13
src/Server/Server.fsproj
Normal file
13
src/Server/Server.fsproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="paket.references" />
|
||||
<Compile Include="..\Shared\Shared.fs" />
|
||||
<Compile Include="Server.fs" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\.paket\Paket.Restore.targets" />
|
||||
</Project>
|
||||
4
src/Server/paket.references
Normal file
4
src/Server/paket.references
Normal file
@@ -0,0 +1,4 @@
|
||||
group Server
|
||||
FSharp.Core
|
||||
Saturn
|
||||
Thoth.Json.Giraffe
|
||||
5
src/Shared/Shared.fs
Normal file
5
src/Shared/Shared.fs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Shared
|
||||
|
||||
type Run = { Name : string }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user