Skip to content

Commit 58725f8

Browse files
committed
Add toast
1 parent 03293e0 commit 58725f8

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

web_app/static/scss/bootstrap.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ $box-shadow: 0.125rem 0.125rem 0.25rem rgba(0, 0, 0, 0.2);
8787
//@import "~bootstrap/scss/progress";
8888
@import "~bootstrap/scss/list-group";
8989
@import "~bootstrap/scss/close";
90-
//@import "~bootstrap/scss/toasts";
90+
@import "~bootstrap/scss/toasts";
9191
//@import "~bootstrap/scss/modal";
9292
//@import "~bootstrap/scss/tooltip";
9393
//@import "~bootstrap/scss/popover";

web_app/static/scss/content.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,17 @@ h2.home {
449449
max-height: 10rem;
450450
}
451451
}
452+
453+
454+
// Toast
455+
.toast.text-bg-dark {
456+
a {
457+
color: tint-color($primary, 30%);
458+
text-decoration: none;
459+
460+
&:hover {
461+
color: $primary;
462+
text-decoration: underline;
463+
}
464+
}
465+
}

web_app/static/ts/application.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DetailList} from "./lists"
22
import {ChartContainer, RecipesContainer} from "./results"
33
import {SearchBox} from "./search"
4-
import {Collapse, ScrollSpy, Tab} from "bootstrap"
4+
import {Collapse, ScrollSpy, Tab, Toast} from "bootstrap"
55
import {Analyzer} from "./filtering";
66
import { registerLicense } from '@syncfusion/ej2-base';
77
import {InteractionElement} from "./interaction";
@@ -56,3 +56,28 @@ if (toc) {
5656
rootMargin: "-70px 0px -25% 0px", // Top: Account for sticky header, Bottom: Ignore the bottom 25% of the viewport
5757
})
5858
}
59+
60+
// Init toast
61+
function showToast(): boolean {
62+
const toastDismissed = localStorage.getItem('jobToastDismissed')
63+
if (!toastDismissed) {
64+
return true
65+
}
66+
67+
const toastDismissedTime = Number(toastDismissed)
68+
if (isNaN(toastDismissedTime)) {
69+
return true
70+
}
71+
72+
const showToastTime = new Date().getTime() - 3*24*3600*1000 // 3 days
73+
return showToastTime > toastDismissedTime
74+
}
75+
76+
const toastElement = document.getElementById('jobToast')
77+
if (toastElement && showToast()) {
78+
toastElement.addEventListener('hide.bs.toast', () => {
79+
localStorage.setItem('jobToastDismissed', (new Date()).getTime() as unknown as string)
80+
})
81+
const toast = Toast.getOrCreateInstance(toastElement, {'autohide': false})
82+
toast.show()
83+
}

web_app/templates/base.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ <h5>About</h5>
110110
</div>
111111
</div>
112112
</footer>
113+
114+
<div class="toast-container position-fixed bottom-0 end-0 p-3">
115+
<div id="jobToast" class="toast align-items-center text-bg-dark" role="alert" aria-live="assertive" aria-atomic="true">
116+
<div class="d-flex">
117+
<div class="toast-body">
118+
Hello, world! 👋 This is Christian, the creator of Beer-Analytics. I'm currently looking for new opportunities as a software engineer. If you're interested in working together, let's connect! Check out my <a href="https://www.linkedin.com/in/christianscheb/" target="_blank">LinkedIn</a> or <a href="mailto:mail@christianscheb.de">drop me an email</a>. Cheers! 🍻
119+
</div>
120+
<button type="button" class="btn-close btn-close-white p-2 me-2 m-auto" data-bs-dismiss="toast" aria-label="Dismiss" title="Dismiss"></button>
121+
</div>
122+
</div>
123+
</div>
124+
113125
{% web_analytics %}
114126
</body>
115127
</html>

0 commit comments

Comments
 (0)