diff --git a/backend/templates/app.html b/backend/templates/app.html index bf02e4f..04cf57a 100644 --- a/backend/templates/app.html +++ b/backend/templates/app.html @@ -6,6 +6,8 @@ + +
diff --git a/default.nix b/default.nix index 3dd8d16..906c404 100644 --- a/default.nix +++ b/default.nix @@ -2,7 +2,7 @@ with pkgs; let backend = pkgs.callPackage ./backend { inherit sources pkgs; }; - frontend = pkgs.callPackage ./frontend { inherit sources pkgs; }; + frontend = pkgs.callPackage ./sina { inherit sources pkgs; }; gruvbox = pkgs.callPackage sources.gruvbox-css { }; in stdenv.mkDerivation { pname = "mi"; diff --git a/shell.nix b/shell.nix index 9fc2961..533024a 100644 --- a/shell.nix +++ b/shell.nix @@ -22,6 +22,7 @@ in pkgs.mkShell rec { elmPackages.elm-format elmPackages.elm-language-server elm2nix + nodePackages.uglify-js # keep this line if you use bash bashInteractive diff --git a/sina/.gitignore b/sina/.gitignore index e7e7f12..cbae3f2 100644 --- a/sina/.gitignore +++ b/sina/.gitignore @@ -12,3 +12,5 @@ node_modules # Desktop Services Store on macOS .DS_Store + +elm.js diff --git a/sina/default.nix b/sina/default.nix index 4000dfc..71c5ea6 100644 --- a/sina/default.nix +++ b/sina/default.nix @@ -1,8 +1,8 @@ -{ nixpkgs ? -, config ? {} +{ sources ? import ../nix/sources.nix +, pkgs ? import sources.nixpkgs {} }: -with (import nixpkgs config); +with pkgs; let mkDerivation = @@ -18,7 +18,7 @@ let inherit name src; buildInputs = [ elmPackages.elm ] - ++ lib.optional outputJavaScript nodePackages_10_x.uglify-js; + ++ lib.optional outputJavaScript nodePackages.uglify-js; buildPhase = pkgs.elmPackages.fetchElmDeps { elmPackages = import srcs; @@ -37,7 +37,7 @@ let ${lib.optionalString outputJavaScript '' echo "minifying ${elmfile module}" uglifyjs $out/${module}.${extension} --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \ - | uglifyjs --mangle --output=$out/${module}.min.${extension} + | uglifyjs --mangle --output $out/${module}.min.${extension} ''} '') targets)} ''; diff --git a/sina/elm-srcs.nix b/sina/elm-srcs.nix index d64d2bb..cfe05ad 100644 --- a/sina/elm-srcs.nix +++ b/sina/elm-srcs.nix @@ -1,5 +1,10 @@ { + "elm/json" = { + sha256 = "1a107nmm905dih4w4mjjkkpdcjbgaf5qjvr7fl30kkpkckfjjnrw"; + version = "1.1.2"; + }; + "elm/html" = { sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k"; version = "1.0.0"; @@ -15,21 +20,41 @@ version = "1.0.4"; }; - "elm/json" = { - sha256 = "1a107nmm905dih4w4mjjkkpdcjbgaf5qjvr7fl30kkpkckfjjnrw"; - version = "1.1.2"; - }; - "elm/url" = { sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4"; version = "1.0.0"; }; + "elm/http" = { + sha256 = "008bs76mnp48b4dw8qwjj4fyvzbxvlrl4xpa2qh1gg2kfwyw56v1"; + version = "2.0.0"; + }; + "elm/time" = { sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1"; version = "1.0.0"; }; + "rtfeldman/elm-iso8601-date-strings" = { + sha256 = "1fa5sslklldy0dq8bm0zdkb9ni50yxhb09xb6lgk00x55bmza9ik"; + version = "1.1.3"; + }; + + "elm/bytes" = { + sha256 = "02ywbf52akvxclpxwj9n04jydajcbsbcbsnjs53yjc5lwck3abwj"; + version = "1.0.8"; + }; + + "elm/file" = { + sha256 = "1rljcb41dl97myidyjih2yliyzddkr2m7n74x7gg46rcw4jl0ny8"; + version = "1.0.5"; + }; + + "elm/parser" = { + sha256 = "0a3cxrvbm7mwg9ykynhp7vjid58zsw03r63qxipxp3z09qks7512"; + version = "1.1.0"; + }; + "elm/virtual-dom" = { sha256 = "0q1v5gi4g336bzz1lgwpn5b1639lrn63d8y6k6pimcyismp2i1yg"; version = "1.0.2"; diff --git a/sina/public/index.html b/sina/public/index.html deleted file mode 100644 index 29ceaa1..0000000 --- a/sina/public/index.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - Elm App - - - -
- - diff --git a/sina/src/Main.elm b/sina/src/Main.elm index c3ab483..7edeb90 100644 --- a/sina/src/Main.elm +++ b/sina/src/Main.elm @@ -1,13 +1,10 @@ module Main exposing (..) import Browser -import Html exposing (Html, text, div, h1, img) +import Html exposing (Html, div, h1, img, text) import Html.Attributes exposing (src) ----- MODEL ---- - - type alias Model = {} @@ -17,10 +14,6 @@ init = ( {}, Cmd.none ) - ----- UPDATE ---- - - type Msg = NoOp @@ -30,22 +23,13 @@ update msg model = ( model, Cmd.none ) - ----- VIEW ---- - - view : Model -> Html Msg view model = div [] - [ img [ src "/logo.svg" ] [] - , h1 [] [ text "Your Elm App is working!" ] + [ h1 [] [ text "Your Elm App is working!" ] ] - ----- PROGRAM ---- - - main : Program () Model Msg main = Browser.element diff --git a/sina/src/index.js b/sina/src/index.js deleted file mode 100644 index c9bbd20..0000000 --- a/sina/src/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import './main.css'; -import { Elm } from './Main.elm'; -import * as serviceWorker from './serviceWorker'; - -Elm.Main.init({ - node: document.getElementById('root') -}); - -// If you want your app to work offline and load faster, you can change -// unregister() to register() below. Note this comes with some pitfalls. -// Learn more about service workers: https://bit.ly/CRA-PWA -serviceWorker.unregister(); diff --git a/sina/src/main.css b/sina/src/main.css deleted file mode 100644 index d9f0b64..0000000 --- a/sina/src/main.css +++ /dev/null @@ -1,26 +0,0 @@ -/* - elm-hot creates an additional div wrapper around the app to make HMR possible. - This could break styling in development mode if you are using Elm UI. - - More context in the issue: - https://github.com/halfzebra/create-elm-app/issues/320 -*/ -[data-elm-hot="true"] { - height: inherit; -} - -body { - font-family: 'Source Sans Pro', 'Trebuchet MS', 'Lucida Grande', 'Bitstream Vera Sans', 'Helvetica Neue', sans-serif; - margin: 0; - text-align: center; - color: #293c4b; -} - -h1 { - font-size: 30px; -} - -img { - margin: 20px 0; - max-width: 200px; -} diff --git a/static/index.html b/static/index.html deleted file mode 120000 index 23bb9cb..0000000 --- a/static/index.html +++ /dev/null @@ -1 +0,0 @@ -../frontend/app.html \ No newline at end of file diff --git a/static/install-sw.js b/static/install-sw.js new file mode 100644 index 0000000..76c43f9 --- /dev/null +++ b/static/install-sw.js @@ -0,0 +1,7 @@ +if (navigator.serviceWorker.controller) { + console.log("Active service worker found, no need to register"); +} else { + navigator.serviceWorker.register("/sw.js").then(function(reg) { + console.log("Service worker has been registered for scope:" + reg.scope); + }); +} diff --git a/sina/public/manifest.json b/static/manifest.json similarity index 69% rename from sina/public/manifest.json rename to static/manifest.json index 9b7dc41..e71fb8b 100644 --- a/sina/public/manifest.json +++ b/static/manifest.json @@ -1,9 +1,9 @@ { - "short_name": "Elm App", - "name": "Create Elm App Sample", + "short_name": "mi", + "name": "mi_irl", "icons": [ { - "src": "favicon.ico", + "src": "/static/favicon.png", "sizes": "192x192", "type": "image/png" } diff --git a/static/sw.js b/static/sw.js new file mode 100644 index 0000000..789cade --- /dev/null +++ b/static/sw.js @@ -0,0 +1,57 @@ +//This is the service worker with the combined offline experience (Offline page + Offline copy of pages) + +//Install stage sets up the offline page in the cache and opens a new cache +self.addEventListener('install', function(event) { + event.waitUntil(preLoad()); +}); + +const cacheName = "cache-xesite-2.0.0"; + +var preLoad = function(){ + console.log('[PWA Builder] Install Event processing'); + return caches.open(cacheName).then(function(cache) { + return cache.addAll(['/static/gruvbox.css', '/', '/static/elm.js']); + }); +}; + +self.addEventListener('fetch', function(event) { + if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') { + return; + } + event.respondWith(checkResponse(event.request).catch(function() { + return returnFromCache(event.request); + })); + event.waitUntil(addToCache(event.request)); +}); + +var checkResponse = function(request){ + return new Promise(function(fulfill, reject) { + fetch(request).then(function(response){ + if(response.status !== 404) { + fulfill(response); + } else { + reject(); + } + }, reject); + }); +}; + +var addToCache = function(request){ + return caches.open(cacheName).then(function (cache) { + return fetch(request).then(function (response) { + return cache.put(request, response); + }); + }); +}; + +var returnFromCache = function(request){ + return caches.open(cacheName).then(function (cache) { + return cache.match(request).then(function (matching) { + if(!matching || matching.status == 404) { + return cache.match('offline.html'); + } else { + return matching; + } + }); + }); +};