Skip to content

Commit 6fa5440

Browse files
committed
Upgrade to .NET 10
1 parent 836ae25 commit 6fa5440

File tree

5 files changed

+258
-1
lines changed

5 files changed

+258
-1
lines changed

MyApp/Components/App.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<base href="/" />
8+
<ResourcePreloader />
89
<link rel="stylesheet" href="css/app.css" />
910
<link href="css/typography.css" rel="stylesheet">
1011
<link href="css/highlight.css" rel="stylesheet">
12+
<link rel="stylesheet" href="@Assets["MyApp.styles.css"]" />
1113
<link rel="icon" href="/img/blazor.svg" type="image/svg+xml">
1214
<link rel="icon" type="image/png" href="favicon.png" />
1315
@BlazorHtml.ImportMap(new()
@@ -22,7 +24,8 @@
2224

2325
<body class="bg-white dark:bg-black dark:text-white">
2426
<Routes />
25-
<script src="_framework/blazor.web.js"></script>
27+
<ReconnectModal />
28+
<script src="@Assets["_framework/blazor.web.js"]"></script>
2629
<script src="js/servicestack-blazor.js"></script>
2730
<script>JS.init({ colorScheme:false })</script>
2831
<script src="lib/js/highlight.js"></script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script type="module" src="@Assets["Components/Layout/ReconnectModal.razor.js"]"></script>
2+
3+
<dialog id="components-reconnect-modal" data-nosnippet>
4+
<div class="components-reconnect-container">
5+
<div class="components-rejoining-animation" aria-hidden="true">
6+
<div></div>
7+
<div></div>
8+
</div>
9+
<p class="components-reconnect-first-attempt-visible">
10+
Rejoining the server...
11+
</p>
12+
<p class="components-reconnect-repeated-attempt-visible">
13+
Rejoin failed... trying again in <span id="components-seconds-to-next-attempt"></span> seconds.
14+
</p>
15+
<p class="components-reconnect-failed-visible">
16+
Failed to rejoin.<br />Please retry or reload the page.
17+
</p>
18+
<button id="components-reconnect-button" class="components-reconnect-failed-visible">
19+
Retry
20+
</button>
21+
<p class="components-pause-visible">
22+
The session has been paused by the server.
23+
</p>
24+
<button id="components-resume-button" class="components-pause-visible">
25+
Resume
26+
</button>
27+
<p class="components-resume-failed-visible">
28+
Failed to resume the session.<br />Please reload the page.
29+
</p>
30+
</div>
31+
</dialog>
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
.components-reconnect-first-attempt-visible,
2+
.components-reconnect-repeated-attempt-visible,
3+
.components-reconnect-failed-visible,
4+
.components-pause-visible,
5+
.components-resume-failed-visible,
6+
.components-rejoining-animation {
7+
display: none;
8+
}
9+
10+
#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
11+
#components-reconnect-modal.components-reconnect-show .components-rejoining-animation,
12+
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
13+
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible,
14+
#components-reconnect-modal.components-reconnect-retrying,
15+
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
16+
#components-reconnect-modal.components-reconnect-retrying .components-rejoining-animation,
17+
#components-reconnect-modal.components-reconnect-failed,
18+
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible {
19+
display: block;
20+
}
21+
22+
23+
#components-reconnect-modal {
24+
z-index: 100;
25+
background-color: white;
26+
width: 20rem;
27+
margin: 20vh auto;
28+
padding: 2rem;
29+
border: 0;
30+
border-radius: 0.5rem;
31+
box-shadow: 0 3px 6px 2px rgba(0, 0, 0, 0.3);
32+
opacity: 0;
33+
transition: display 0.5s allow-discrete, overlay 0.5s allow-discrete;
34+
animation: components-reconnect-modal-fadeOutOpacity 0.5s both;
35+
&[open]
36+
37+
{
38+
animation: components-reconnect-modal-slideUp 1.5s cubic-bezier(.05, .89, .25, 1.02) 0.3s, components-reconnect-modal-fadeInOpacity 0.5s ease-in-out 0.3s;
39+
animation-fill-mode: both;
40+
}
41+
42+
}
43+
44+
#components-reconnect-modal::backdrop {
45+
background-color: rgba(0, 0, 0, 0.4);
46+
animation: components-reconnect-modal-fadeInOpacity 0.5s ease-in-out;
47+
opacity: 1;
48+
}
49+
50+
@keyframes components-reconnect-modal-slideUp {
51+
0% {
52+
transform: translateY(30px) scale(0.95);
53+
}
54+
55+
100% {
56+
transform: translateY(0);
57+
}
58+
}
59+
60+
@keyframes components-reconnect-modal-fadeInOpacity {
61+
0% {
62+
opacity: 0;
63+
}
64+
65+
100% {
66+
opacity: 1;
67+
}
68+
}
69+
70+
@keyframes components-reconnect-modal-fadeOutOpacity {
71+
0% {
72+
opacity: 1;
73+
}
74+
75+
100% {
76+
opacity: 0;
77+
}
78+
}
79+
80+
.components-reconnect-container {
81+
display: flex;
82+
flex-direction: column;
83+
align-items: center;
84+
gap: 1rem;
85+
}
86+
87+
#components-reconnect-modal p {
88+
margin: 0;
89+
text-align: center;
90+
}
91+
92+
#components-reconnect-modal button {
93+
border: 0;
94+
background-color: #6b9ed2;
95+
color: white;
96+
padding: 4px 24px;
97+
border-radius: 4px;
98+
}
99+
100+
#components-reconnect-modal button:hover {
101+
background-color: #3b6ea2;
102+
}
103+
104+
#components-reconnect-modal button:active {
105+
background-color: #6b9ed2;
106+
}
107+
108+
.components-rejoining-animation {
109+
position: relative;
110+
width: 80px;
111+
height: 80px;
112+
}
113+
114+
.components-rejoining-animation div {
115+
position: absolute;
116+
border: 3px solid #0087ff;
117+
opacity: 1;
118+
border-radius: 50%;
119+
animation: components-rejoining-animation 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
120+
}
121+
122+
.components-rejoining-animation div:nth-child(2) {
123+
animation-delay: -0.5s;
124+
}
125+
126+
@keyframes components-rejoining-animation {
127+
0% {
128+
top: 40px;
129+
left: 40px;
130+
width: 0;
131+
height: 0;
132+
opacity: 0;
133+
}
134+
135+
4.9% {
136+
top: 40px;
137+
left: 40px;
138+
width: 0;
139+
height: 0;
140+
opacity: 0;
141+
}
142+
143+
5% {
144+
top: 40px;
145+
left: 40px;
146+
width: 0;
147+
height: 0;
148+
opacity: 1;
149+
}
150+
151+
100% {
152+
top: 0px;
153+
left: 0px;
154+
width: 80px;
155+
height: 80px;
156+
opacity: 0;
157+
}
158+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Set up event handlers
2+
const reconnectModal = document.getElementById("components-reconnect-modal");
3+
reconnectModal.addEventListener("components-reconnect-state-changed", handleReconnectStateChanged);
4+
5+
const retryButton = document.getElementById("components-reconnect-button");
6+
retryButton.addEventListener("click", retry);
7+
8+
const resumeButton = document.getElementById("components-resume-button");
9+
resumeButton.addEventListener("click", resume);
10+
11+
function handleReconnectStateChanged(event) {
12+
if (event.detail.state === "show") {
13+
reconnectModal.showModal();
14+
} else if (event.detail.state === "hide") {
15+
reconnectModal.close();
16+
} else if (event.detail.state === "failed") {
17+
document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible);
18+
} else if (event.detail.state === "rejected") {
19+
location.reload();
20+
}
21+
}
22+
23+
async function retry() {
24+
document.removeEventListener("visibilitychange", retryWhenDocumentBecomesVisible);
25+
26+
try {
27+
// Reconnect will asynchronously return:
28+
// - true to mean success
29+
// - false to mean we reached the server, but it rejected the connection (e.g., unknown circuit ID)
30+
// - exception to mean we didn't reach the server (this can be sync or async)
31+
const successful = await Blazor.reconnect();
32+
if (!successful) {
33+
// We have been able to reach the server, but the circuit is no longer available.
34+
// We'll reload the page so the user can continue using the app as quickly as possible.
35+
const resumeSuccessful = await Blazor.resumeCircuit();
36+
if (!resumeSuccessful) {
37+
location.reload();
38+
} else {
39+
reconnectModal.close();
40+
}
41+
}
42+
} catch (err) {
43+
// We got an exception, server is currently unavailable
44+
document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible);
45+
}
46+
}
47+
48+
async function resume() {
49+
try {
50+
const successful = await Blazor.resumeCircuit();
51+
if (!successful) {
52+
location.reload();
53+
}
54+
} catch {
55+
location.reload();
56+
}
57+
}
58+
59+
async function retryWhenDocumentBecomesVisible() {
60+
if (document.visibilityState === "visible") {
61+
await retry();
62+
}
63+
}

MyApp/Components/_Imports.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@using System.Net.Http
22
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components
34
@using Microsoft.AspNetCore.Components.Authorization
45
@using Microsoft.AspNetCore.Components.Forms
56
@using Microsoft.AspNetCore.Components.Routing
@@ -17,4 +18,5 @@
1718
@using MyApp
1819
@using MyApp.Components
1920
@using MyApp.Components.Shared
21+
@using MyApp.Components.Layout
2022
@using MyApp.ServiceModel

0 commit comments

Comments
 (0)