From 238635a6be611f284694f6ed70a21396350044e8 Mon Sep 17 00:00:00 2001 From: Jean Carlos Date: Sat, 16 Oct 2021 07:24:19 -0300 Subject: [PATCH] Changed favicon with base on notebook status (#594) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change favicon based on notebook status * Format correction * "operation" is unused * Improvements for better functioning of icons * Renamed icons files * Update favicons * Update changelog Co-authored-by: Jonatan Kłosko --- CHANGELOG.md | 3 + assets/js/lib/utils.js | 12 +++ assets/js/session/index.js | 26 ++++++ lib/livebook_web/live/session_live.ex | 1 + lib/livebook_web/templates/error/401.html.eex | 1 + lib/livebook_web/templates/error/404.html.eex | 1 + lib/livebook_web/templates/error/500.html.eex | 1 + .../templates/layout/root.html.heex | 1 + priv/static/favicon-evaluating.svg | 84 +++++++++++++++++ priv/static/favicon-stale.svg | 86 ++++++++++++++++++ priv/static/favicon.ico | Bin 5430 -> 0 bytes priv/static/favicon.svg | 80 ++++++++++++++++ 12 files changed, 296 insertions(+) create mode 100644 priv/static/favicon-evaluating.svg create mode 100644 priv/static/favicon-stale.svg delete mode 100644 priv/static/favicon.ico create mode 100644 priv/static/favicon.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d13e5b6f..9bc0f121f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added a keyboard shortcut for triggering on-hover docs ([#508](https://github.com/livebook-dev/livebook/pull/508)) - Added `--open-new` CLI flag to `livebook server` ([#529](https://github.com/livebook-dev/livebook/pull/529)) - Nx introductory notebook ([#528](https://github.com/livebook-dev/livebook/pull/528)) +- Display creation date of a session in home ([#593](https://github.com/livebook-dev/livebook/pull/593)) +- Dynamic favicon reflecting session state ([#594](https://github.com/livebook-dev/livebook/pull/594)) ### Changed - Improved intellisense to handle structs and sigils ([#513](https://github.com/livebook-dev/livebook/pull/513)) - Create new notebooks with an already focused code cell ([#527](https://github.com/livebook-dev/livebook/pull/527)) - Switched base Docker image from alpine to debian-slim ([#552](https://github.com/livebook-dev/livebook/pull/552)) +- Update matching brackets style ([#595](https://github.com/livebook-dev/livebook/pull/595)) ### Fixed diff --git a/assets/js/lib/utils.js b/assets/js/lib/utils.js index 820ecd73b..941faa2d0 100644 --- a/assets/js/lib/utils.js +++ b/assets/js/lib/utils.js @@ -104,6 +104,18 @@ export function throttle(fn, windowMs) { }; } +export function setFavicon(name) { + let link = document.querySelector(`[rel="icon"]`); + + if (!link) { + link = document.createElement("link"); + link.rel = "icon"; + document.head.appendChild(link); + } + + link.href = `/${name}.svg`; +} + export function findChildOrThrow(element, selector) { const child = element.querySelector(selector); diff --git a/assets/js/session/index.js b/assets/js/session/index.js index e595096bf..ee985be48 100644 --- a/assets/js/session/index.js +++ b/assets/js/session/index.js @@ -4,6 +4,7 @@ import { clamp, selectElementContent, smoothlyScrollToElement, + setFavicon, } from "../lib/utils"; import { getAttributeOrDefault } from "../lib/attribute"; import KeyBuffer from "./key_buffer"; @@ -203,6 +204,20 @@ const Session = { ); }, + updated() { + const prevProps = this.props; + this.props = getProps(this); + + if ( + this.props.globalEvaluationStatus !== prevProps.globalEvaluationStatus + ) { + const favicon = faviconForEvaluationStatus( + this.props.globalEvaluationStatus + ); + setFavicon(favicon); + } + }, + destroyed() { this._unsubscribeFromSessionEvents(); @@ -219,9 +234,20 @@ function getProps(hook) { "data-autofocus-cell-id", null ), + globalEvaluationStatus: getAttributeOrDefault( + hook.el, + "data-global-evaluation-status", + null + ), }; } +function faviconForEvaluationStatus(evaluationStatus) { + if (evaluationStatus === "evaluating") return "favicon-evaluating"; + if (evaluationStatus === "stale") return "favicon-stale"; + return "favicon"; +} + /** * Data of a specific LV client. * diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index 097c84ba7..e9ec150f3 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -79,6 +79,7 @@ defmodule LivebookWeb.SessionLive do id="session" data-element="session" phx-hook="Session" + data-global-evaluation-status={elem(@data_view.global_evaluation_status, 0)} data-autofocus-cell-id={@autofocus_cell_id}> diff --git a/lib/livebook_web/templates/error/401.html.eex b/lib/livebook_web/templates/error/401.html.eex index 259eed4d7..0878ed609 100644 --- a/lib/livebook_web/templates/error/401.html.eex +++ b/lib/livebook_web/templates/error/401.html.eex @@ -4,6 +4,7 @@ + <%= @status %> - Livebook "/> diff --git a/lib/livebook_web/templates/error/404.html.eex b/lib/livebook_web/templates/error/404.html.eex index eefa9d721..bbba60a28 100644 --- a/lib/livebook_web/templates/error/404.html.eex +++ b/lib/livebook_web/templates/error/404.html.eex @@ -4,6 +4,7 @@ + <%= @status %> - Livebook "/> diff --git a/lib/livebook_web/templates/error/500.html.eex b/lib/livebook_web/templates/error/500.html.eex index 1fe0c6207..e7d69c5c3 100644 --- a/lib/livebook_web/templates/error/500.html.eex +++ b/lib/livebook_web/templates/error/500.html.eex @@ -4,6 +4,7 @@ + <%= @status %> - Livebook "/> diff --git a/lib/livebook_web/templates/layout/root.html.heex b/lib/livebook_web/templates/layout/root.html.heex index 764173ec4..6db446c74 100644 --- a/lib/livebook_web/templates/layout/root.html.heex +++ b/lib/livebook_web/templates/layout/root.html.heex @@ -5,6 +5,7 @@ <%= csrf_meta_tag() %> + <%= live_title_tag assigns[:page_title] || "Livebook" %> diff --git a/priv/static/favicon-evaluating.svg b/priv/static/favicon-evaluating.svg new file mode 100644 index 000000000..6b6074d35 --- /dev/null +++ b/priv/static/favicon-evaluating.svg @@ -0,0 +1,84 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/priv/static/favicon-stale.svg b/priv/static/favicon-stale.svg new file mode 100644 index 000000000..85a1cf261 --- /dev/null +++ b/priv/static/favicon-stale.svg @@ -0,0 +1,86 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/priv/static/favicon.ico b/priv/static/favicon.ico deleted file mode 100644 index 5d63aabef05cae7b93894613cfe44b28d14a4eb8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5430 zcmeI0YfKzf6vr=H0{vhrA&udK$%nz>?|`ZyUY8FPV&or z%suCS&Yih;_O1|aLM6Ps1WI4=s=E-Yg%G~J6YWOypF&>%`cTD)iGCDIdKDyfc>w+S zqmQyLRMB!*;)(GZRYF{t$L6&k2IT2(oPg~RpoYqEYN#6j^Fr15DfkJR&JS#TV0%{+ z>Nlp*0jSi*&f3<~-*lLIN><9K+r`R8ijSjNe zr^Qsx*1kA?O^D4tEB=ft`|K(DMoB+1SWEfqI%M{bY`IU)0Zp|(789v?pw;LpH}PYe z?Zo`Kw&z$dHdC5&F86G_HL^FW+X&4PJimLAwsrm#`d0h&f+W+(k&-TIKKC_!_UY|f z?&k~htpag)b~W(z5cTQoeM&OASGF{LPBrf|(Y4Fn4}l(FHB4TxT>*S1dnRi=J$q_MYB9Il^`ArHzLl?8vAX24_%z(zS(h1Z;}I%OFm9XK`9Y zLNI2v5S^Y%3}`chRYLswhY){b+%Vu$vg3Wm7bF4RkN&?Feg?3fR40puR15FfxkuCu=nD- zQ|F6sk71kk(r@|eIu&~$$53yy=}U2N`8%itey-J&BcPoJ2DP!F6c*w)vNlXVmKA@N z5Cit$D>K!X$I^~Ca==W!wX99}W>RqAD%*D_CUk>EA9FAleJPekWv0p&&pGGK`q2>q zHf`zKn;K)Jt=h)<=(j2rl`ZIcvo;eR_OzXTa>OgNEn!~yyV74S=|^Z*+vz8Uzew8? zS{E&Uo(<^#!!bmK``hW`J)|AFn~SaQ@cAc(=i>K^X+HWb$|r8$Lhg4s|Cp#iyZqDe z{z-d|ymYYsrFULlHrp#Id!T)v_18oy^+N)JXs51iQT3r4$J)I1LxZ1Ed@x%fDU{FMu0q)Ip~`P zPLzK^ZEd~OcekI~Z}jr{fzeBvj!I~IgA#Dh8pmw(bCCbDtrz<|zU%*q+S_~R^zk}L zo6GNkw)!p;|cn5A;;`pQqXZZK8QFUdldEf5icIUpi=uNe0z1-oRzv(dH%w>r||J)u* z)fLbS$-5|X{chTlQu-Ipa|dyM#Z=pcYQy&s>&qBL{Yy{?7H#gO_@U7ZkiVg4d+LGF zoYc22N%xkbgtm_LK|M$V_ra2$d7xJc8kQp8|C$ELuki|^;m3&#Ze$jsVps_EpbI*2 lpT}Xm+PrK~ZT2(+QqwXxb^`)F@vnrX?TPX|@C&eB{{jI!Bo6=p diff --git a/priv/static/favicon.svg b/priv/static/favicon.svg new file mode 100644 index 000000000..596c0cc3e --- /dev/null +++ b/priv/static/favicon.svg @@ -0,0 +1,80 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +