Skip to content

Commit bbb3b69

Browse files
committed
Tau - update for Phoenix 1.7 compatibility
1 parent fca2388 commit bbb3b69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1249
-378
lines changed

app/server/beam/tau/.formatter.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
22
import_deps: [:phoenix],
3-
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"]
3+
plugins: [Phoenix.LiveView.HTMLFormatter],
4+
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"]
45
]

app/server/beam/tau/.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ erl_crash.dump
2222
# Ignore package tarball (built via "mix hex.build").
2323
tau-*.tar
2424

25-
# Temporary files, for example, from tests.
26-
/tmp/
25+
# Ignore assets that are produced by build tools.
26+
/priv/static/assets/
27+
28+
# Ignore digested assets cache.
29+
/priv/static/cache_manifest.json
2730

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

app/server/beam/tau/assets/css/app.css

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
1-
@tailwind base;
2-
@tailwind components;
3-
@tailwind utilities;
4-
5-
6-
/* Alerts and form errors used by phx.new */
7-
.alert {
8-
padding: 15px;
9-
margin-bottom: 20px;
10-
border: 1px solid transparent;
11-
border-radius: 4px;
12-
}
13-
.alert-info {
14-
color: #31708f;
15-
background-color: #d9edf7;
16-
border-color: #bce8f1;
17-
}
18-
.alert-warning {
19-
color: #8a6d3b;
20-
background-color: #fcf8e3;
21-
border-color: #faebcc;
22-
}
23-
.alert-danger {
24-
color: #a94442;
25-
background-color: #f2dede;
26-
border-color: #ebccd1;
27-
}
28-
.alert p {
29-
margin-bottom: 0;
30-
}
31-
.alert:empty {
32-
display: none;
33-
}
34-
.invalid-feedback {
35-
color: #a94442;
36-
display: block;
37-
margin: -1rem 0 2rem;
38-
}
1+
@import "tailwindcss/base";
2+
@import "tailwindcss/components";
3+
@import "tailwindcss/utilities";
394

405
/* LiveView specific classes for your customization */
416
.phx-no-feedback.invalid-feedback,
@@ -48,24 +13,24 @@
4813
transition: opacity 1s ease-out;
4914
}
5015

51-
.phx-disconnected{
16+
.phx-disconnected {
5217
cursor: wait;
5318
}
54-
.phx-disconnected *{
19+
.phx-disconnected * {
5520
pointer-events: none;
5621
}
5722

5823
.phx-modal {
59-
opacity: 1!important;
24+
opacity: 1 !important;
6025
position: fixed;
6126
z-index: 1;
6227
left: 0;
6328
top: 0;
6429
width: 100%;
6530
height: 100%;
6631
overflow: auto;
67-
background-color: rgb(0,0,0);
68-
background-color: rgba(0,0,0,0.4);
32+
background-color: rgb(0, 0, 0);
33+
background-color: rgba(0, 0, 0, 0.4);
6934
}
7035

7136
.phx-modal-content {

app/server/beam/tau/assets/js/app.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// We import the CSS which is extracted to its own file by esbuild.
2-
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
3-
41
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
52
// to get started and then uncomment the line below.
63
// import "./user_socket.js"
@@ -19,40 +16,40 @@
1916
//
2017

2118
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
22-
import "phoenix_html"
19+
import "phoenix_html";
2320
// Establish Phoenix Socket and LiveView configuration.
24-
import {Socket} from "phoenix"
25-
import {LiveSocket} from "phoenix_live_view"
26-
import topbar from "../vendor/topbar"
27-
import Alpine from "../vendor/alpine"
21+
import { Socket } from "phoenix";
22+
import { LiveSocket } from "phoenix_live_view";
23+
import topbar from "../vendor/topbar";
24+
import Alpine from "../vendor/alpine";
2825

29-
window.Alpine = Alpine
30-
Alpine.start()
26+
window.Alpine = Alpine;
27+
Alpine.start();
3128

32-
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
29+
let csrfToken = document
30+
.querySelector("meta[name='csrf-token']")
31+
.getAttribute("content");
3332
let liveSocket = new LiveSocket("/live", Socket, {
34-
params: {_csrf_token: csrfToken},
35-
dom: {
33+
params: { _csrf_token: csrfToken },
34+
dom: {
3635
onBeforeElUpdated(from, to) {
3736
if (from._x_dataStack) {
3837
window.Alpine.clone(from, to);
3938
}
4039
},
4140
},
42-
4341
});
4442

4543
// Show progress bar on live navigation and form submits
46-
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
47-
window.addEventListener("phx:page-loading-start", info => topbar.show())
48-
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
49-
44+
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });
45+
window.addEventListener("phx:page-loading-start", (info) => topbar.show());
46+
window.addEventListener("phx:page-loading-stop", (info) => topbar.hide());
5047

5148
// connect if there are any LiveViews on the page
52-
liveSocket.connect()
49+
liveSocket.connect();
5350

5451
// expose liveSocket on window for web console debug logs and latency simulation:
5552
// >> liveSocket.enableDebug()
5653
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
5754
// >> liveSocket.disableLatencySim()
58-
window.liveSocket = liveSocket
55+
window.liveSocket = liveSocket;
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1+
const plugin = require("tailwindcss/plugin");
2+
13
const colors = require("tailwindcss/colors");
24

35
module.exports = {
46
content: [
5-
"../lib/*_web/**/*.*ex",
67
"./js/**/*.js",
8+
"../lib/*_web.ex",
9+
"../lib/*_web/**/*.*ex",
710
(process.env.MIX_DEPS_PATH || "../deps") + "/petal_components/**/*.*ex",
811
],
912
theme: {
1013
extend: {
1114
colors: {
15+
brand: "#FD4F00",
1216
primary: colors.pink,
1317
secondary: colors.blue,
1418
},
1519
},
1620
},
17-
plugins: [require("@tailwindcss/forms")],
21+
plugins: [
22+
require("@tailwindcss/forms"),
23+
plugin(({ addVariant }) =>
24+
addVariant("phx-no-feedback", [".phx-no-feedback&", ".phx-no-feedback &"])
25+
),
26+
plugin(({ addVariant }) =>
27+
addVariant("phx-click-loading", [
28+
".phx-click-loading&",
29+
".phx-click-loading &",
30+
])
31+
),
32+
plugin(({ addVariant }) =>
33+
addVariant("phx-submit-loading", [
34+
".phx-submit-loading&",
35+
".phx-submit-loading &",
36+
])
37+
),
38+
plugin(({ addVariant }) =>
39+
addVariant("phx-change-loading", [
40+
".phx-change-loading&",
41+
".phx-change-loading &",
42+
])
43+
),
44+
],
1845
darkMode: "class",
1946
};

app/server/beam/tau/assets/vendor/topbar.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* @license MIT
33
* topbar 1.0.0, 2021-01-06
4+
* Modifications:
5+
* - add delayedShow(time) (2022-09-21)
46
* http://buunguyen.github.io/topbar
57
* Copyright (c) 2021 Buu Nguyen
68
*/
@@ -35,10 +37,11 @@
3537
})();
3638

3739
var canvas,
38-
progressTimerId,
39-
fadeTimerId,
4040
currentProgress,
4141
showing,
42+
progressTimerId = null,
43+
fadeTimerId = null,
44+
delayTimerId = null,
4245
addEvent = function (elem, type, handler) {
4346
if (elem.addEventListener) elem.addEventListener(type, handler, false);
4447
else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
@@ -95,6 +98,11 @@
9598
for (var key in opts)
9699
if (options.hasOwnProperty(key)) options[key] = opts[key];
97100
},
101+
delayedShow: function(time) {
102+
if (showing) return;
103+
if (delayTimerId) return;
104+
delayTimerId = setTimeout(() => topbar.show(), time);
105+
},
98106
show: function () {
99107
if (showing) return;
100108
showing = true;
@@ -125,6 +133,8 @@
125133
return currentProgress;
126134
},
127135
hide: function () {
136+
clearTimeout(delayTimerId);
137+
delayTimerId = null;
128138
if (!showing) return;
129139
showing = false;
130140
if (progressTimerId != null) {

app/server/beam/tau/config/config.exs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,46 @@ import Config
1010
# Configures the endpoint
1111
config :tau, TauWeb.Endpoint,
1212
url: [host: "localhost"],
13-
render_errors: [view: TauWeb.ErrorView, accepts: ~w(html json), layout: false],
13+
render_errors: [
14+
formats: [html: TauWeb.ErrorHTML, json: TauWeb.ErrorJSON],
15+
layout: false
16+
],
1417
pubsub_server: Tau.PubSub,
15-
live_view: [signing_salt: "Zr1UgcpP"]
18+
live_view: [signing_salt: "mZfPjIKs"]
1619

1720
# Configures Elixir's Logger
1821
config :logger, :console,
1922
format: "$time $metadata[$level] $message\n",
2023
metadata: [:request_id]
2124

25+
# Configure esbuild (the version is required)
26+
config :esbuild,
27+
version: "0.16.6",
28+
default: [
29+
args:
30+
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
31+
cd: Path.expand("../assets", __DIR__),
32+
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
33+
]
34+
35+
# Configure tailwind (the version is required)
36+
config :tailwind,
37+
version: "3.2.4",
38+
default: [
39+
args: ~w(
40+
--config=tailwind.config.js
41+
--input=css/app.css
42+
--output=../priv/static/assets/app.css
43+
),
44+
cd: Path.expand("../assets", __DIR__)
45+
]
46+
2247
# Use Jason for JSON parsing in Phoenix
2348
config :phoenix, :json_library, Jason
2449

25-
config :petal_components, :error_translator_function, {PetalBoilerplateWeb.ErrorHelpers, :translate_error}
50+
config :petal_components,
51+
:error_translator_function,
52+
{PetalBoilerplateWeb.ErrorHelpers, :translate_error}
2653

2754
# Import environment specific config. This must remain at the bottom
2855
# of this file so it overrides the configuration defined above.

app/server/beam/tau/config/dev.exs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ config :tau, TauWeb.Endpoint,
1717
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
1818
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]},
1919
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}
20-
2120
]
2221

2322
# ## SSL Support
@@ -56,9 +55,10 @@ config :tau, TauWeb.Endpoint,
5655
]
5756
]
5857

59-
6058
config :exsync, extensions: [".erl"]
6159

60+
# Enable dev routes for dashboard and mailbox
61+
config :tau, dev_routes: true
6262

6363
# Do not include metadata nor timestamps in development logs
6464
config :logger, :console, format: "[$level] $message\n"
@@ -69,26 +69,3 @@ config :phoenix, :stacktrace_depth, 20
6969

7070
# Initialize plugs at runtime for faster development compilation
7171
config :phoenix, :plug_init_mode, :runtime
72-
73-
# Configure esbuild (the version is required)
74-
config :esbuild,
75-
version: "0.16.6",
76-
default: [
77-
args:
78-
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
79-
cd: Path.expand("../assets", __DIR__),
80-
env: %{"NODE_PATH" => System.get_env("MIX_DEPS_PATH") || Path.expand("../deps", __DIR__)}
81-
],
82-
path: System.get_env("MIX_ESBUILD_PATH")
83-
84-
config :tailwind,
85-
version: "3.2.4",
86-
default: [
87-
args: ~w(
88-
--config=tailwind.config.js
89-
--input=css/app.css
90-
--output=../priv/static/assets/app.css
91-
),
92-
cd: Path.expand("../assets", __DIR__)
93-
],
94-
path: System.get_env("MIX_TAILWINDCSS_PATH")

app/server/beam/tau/config/prod.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Config
1111
# before starting your production server.
1212
config :tau, TauWeb.Endpoint,
1313
cache_static_manifest: "priv/static/cache_manifest.json",
14+
# TODO what is this used for - not in phx 1.7 generator
1415
server: true
1516

1617
# Do not print debug messages in production

app/server/beam/tau/config/test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ config :tau, TauWeb.Endpoint,
88
server: false
99

1010
# Print only warnings and errors during test
11-
config :logger, level: :warn
11+
config :logger, level: :warning
1212

1313
# Initialize plugs at runtime for faster test compilation
1414
config :phoenix, :plug_init_mode, :runtime

0 commit comments

Comments
 (0)