Skip to content

Commit 03acb6a

Browse files
authored
Update Drawer (#175)
1 parent 070b85c commit 03acb6a

6 files changed

Lines changed: 115 additions & 44 deletions

File tree

src/TryMudBlazor.Client/Pages/Repl.razor

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
@page "/snippet/{snippetId?}"
22
@layout MainLayout
33

4+
<style>
5+
.try-drawer {
6+
width: var(--mud-drawer-width-mini-left) !important;
7+
overflow: hidden;
8+
}
9+
.try-editor {
10+
margin-left: var(--mud-drawer-width-mini-left) !important;
11+
}
12+
.try-avatar {
13+
border-color: var(--try-drawer-text);
14+
color: var(--try-drawer-text);
15+
}
16+
</style>
17+
418
<div class="try-layout">
5-
<MudDrawer Fixed="false" Elevation="1" Variant="@DrawerVariant.Mini" Class="try-drawer">
6-
<MudIconButton title="Run (Ctrl + S)" OnClick="@CompileAsync" Disabled="@Loading" Icon="@Icons.Material.Rounded.PlayArrow" Color="@(LayoutService.IsDarkMode ? Color.Success : Color.Inherit)" />
19+
<MudDrawer Open="true" Fixed="false" Elevation="1" Variant="@DrawerVariant.Persistent" Class="try-drawer mud-drawer-mini">
20+
<MudTooltip Text="Run your code">
21+
<MudIconButton title="Run (Ctrl + S)" OnClick="@CompileAsync" Disabled="@Loading" Icon="@Icons.Material.Rounded.PlayArrow" Color="@(LayoutService.IsDarkMode ? Color.Success : Color.Inherit)" />
22+
</MudTooltip>
723
<MudTooltip Text="Save or Share" Delay="800" Arrow="true" Placement="Placement.Right" Color="Color.Dark">
824
<SaveSnippetPopup @bind-Visible="SaveSnippetPopupVisible" CodeFiles="@CodeFiles.Values" UpdateActiveCodeFileContentAction="UpdateActiveCodeFileContent" />
925
<MudIconButton OnClick="ShowSaveSnippetPopup" Icon="@Icons.Material.Outlined.Save" Color="@(LayoutService.IsDarkMode ? Color.Info : Color.Inherit)" />
@@ -12,9 +28,14 @@
1228
<MudIconButton OnClick="@UpdateTheme" Icon="@(LayoutService.IsDarkMode ? @Icons.Material.Rounded.LightMode : @Icons.Material.Outlined.DarkMode)" Color="@(LayoutService.IsDarkMode ? Color.Warning : Color.Inherit)" />
1329
</MudTooltip>
1430
<MudSpacer />
31+
<MudStack Class="mb-12" AlignItems="AlignItems.Center" Justify="Justify.Center">
1532
<div class="d-flex justify-center">
1633
<div class="brand">Try<span class="pt-4 pb-12">MudBlazor</span></div>
1734
</div>
35+
<MudTooltip Text="Cleanup and Clear Compiler Cache" Delay="800" Arrow Placement="Placement.Right" Color="Color.Dark">
36+
<MudIconButton OnClick="@ClearCache" Icon="@Icons.Material.Filled.CleanHands" Color="@(LayoutService.IsDarkMode ? Color.Info : Color.Inherit)" />
37+
</MudTooltip>
38+
</MudStack>
1839
</MudDrawer>
1940
<div class="try-editor">
2041
<MudOverlay Visible="Loading" Absolute="true" DarkBackground="true">
@@ -26,10 +47,10 @@
2647
<ErrorList @bind-Show="@ShowDiagnostics" Diagnostics="@Diagnostics" />
2748
</div>
2849
<div id="user-page-window-container">
29-
<iframe id="user-page-window" src="/user-page"></iframe>
50+
<iframe id="user-page-window" src="/user-page" style="height: 98vh;"></iframe>
3051
</div>
3152
</div>
32-
<MudAppBar Bottom="true" Fixed="false" Color="@GetBottomAppBarColor()" Elevation="0" Class="try-errorlist repl-navbar">
53+
<MudAppBar Bottom="true" Fixed="true" Color="@GetBottomAppBarColor()" Elevation="0" Class="try-errorlist repl-navbar">
3354
<div class="try-errorlist-button d-flex align-center" @onclick="@ToggleDiagnostics">
3455
<MudIcon Icon="@Icons.Material.Outlined.ErrorOutline" />
3556
<MudText>@ErrorsCount</MudText>
@@ -45,11 +66,11 @@
4566
<MudLink Typo="Typo.body2" Class="ml-5 version-info" Color="Color.Inherit" Href="https://github.com/MudBlazor/MudBlazor/releases" Target="_blank">mudblazor @Version</MudLink>
4667
</MudAppBar>
4768
</div>
48-
@code{
69+
@code {
4970

5071
public Color GetBottomAppBarColor()
5172
{
52-
if(ErrorsCount != 0)
73+
if (ErrorsCount != 0)
5374
{
5475
return Color.Error;
5576
}

src/TryMudBlazor.Client/Pages/Repl.razor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public partial class Repl : IDisposable
3737
[Inject]
3838
public IJSInProcessRuntime JsRuntime { get; set; }
3939

40+
[Inject]
41+
public NavigationManager NavigationManager { get; set; }
42+
4043
[Parameter]
4144
public string SnippetId { get; set; }
4245

@@ -286,5 +289,11 @@ private async void UpdateTheme()
286289
await Task.Yield();
287290
await JsRuntime.InvokeVoidAsync("updateIframeTheme");
288291
}
292+
293+
private async Task ClearCache()
294+
{
295+
await JsRuntime.InvokeVoidAsync("Try.clearCache");
296+
NavigationManager.NavigateTo(NavigationManager.BaseUri, true);
297+
}
289298
}
290299
}

src/TryMudBlazor.Client/Pages/UserPage.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
@page "/user-page"
22

33
<MudContainer Class="mt-8">
4-
<MudText>This snippet hasn't been compiled yet.</MudText>
5-
<MudText>Run the code on the left to see the result here.</MudText>
4+
<MudAlert Style="width: max-content;padding-right: 30px;" Severity="Severity.Warning">
5+
<MudText>This snippet hasn't been compiled yet.<br/>Run the code on the left to see the result here.</MudText>
6+
</MudAlert>
67
<MudText Typo="@Typo.h6" Class="mt-12">How to load your own service</MudText>
78
<MudText Class="mt-3">
89
To install a service which your snippet can use create a new *.cs file, <br/>

src/TryMudBlazor.Client/Style/Editor/_page.scss

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
11

2-
.try-layout{
2+
.try-layout {
33
height: 100%;
44
overflow: hidden;
5-
.try-editor{
5+
6+
.try-editor {
67
display: flex;
78
height: 100%;
89
flex-direction: row;
910
position: relative;
11+
margin-left: var(--mud-drawer-width-mini-left) !important;
12+
1013
.code-editor {
1114
height: calc(100% - 54px);
1215
border: none;
1316
}
14-
#user-code-editor-container{
17+
18+
#user-code-editor-container {
1519
position: relative;
1620
}
17-
18-
.decorationsOverviewRuler{
21+
22+
.decorationsOverviewRuler {
1923
display: none !important;
2024
}
2125
}
22-
.try-drawer{
26+
27+
.try-drawer {
2328
background-color: var(--try-drawer);
2429
color: var(--try-drawer-text);
25-
26-
& + .mud-icon-button{
27-
padding:12px;
30+
width: var(--mud-drawer-width-mini-left) !important;
31+
overflow: hidden;
32+
33+
& + .mud-icon-button {
34+
padding: 12px;
2835
font-size: 2rem;
29-
.mud-icon-size-medium{
36+
37+
.mud-icon-size-medium {
3038
font-size: 2rem;
3139
}
3240
}
33-
34-
.mud-icon-button{
35-
padding:16px;
41+
42+
.mud-icon-button {
43+
padding: 16px;
3644
border-radius: 0px;
37-
&:hover{
45+
46+
&:hover {
3847
background-color: rgba(255, 255, 255, 0.05);
3948
}
4049
}
41-
.brand{
50+
51+
.brand {
4252
writing-mode: vertical-rl;
4353
text-orientation: upright;
4454
font-size: 1.1rem;
@@ -47,58 +57,61 @@
4757
}
4858
}
4959

50-
.try-diagnostics{
60+
.try-diagnostics {
5161
position: absolute;
5262
width: 100%;
5363
bottom: 32px;
5464
border-top: 1px solid var(--mud-palette-table-lines);
55-
56-
.mud-table{
65+
66+
.mud-table {
5767
background-color: var(--try-table);
5868
}
59-
69+
6070
table {
6171
width: 100%;
6272
}
6373

6474
th {
6575
font-weight: 600;
6676
padding: 0px 8px;
67-
&:last-child{
77+
78+
&:last-child {
6879
padding: 0px;
6980
}
7081
}
7182

72-
td{
83+
td {
7384
padding: 6px 8px;
7485
}
7586

76-
th , td {
87+
th, td {
7788
font-family: consolas;
7889
font-size: 12px;
7990
}
8091
}
81-
.try-errorlist{
92+
93+
.try-errorlist {
8294
height: 24px;
8395
bottom: 0;
8496
position: absolute;
8597

86-
&.mud-theme-inherit{
98+
&.mud-theme-inherit {
8799
background-color: #2c2c2c !important;
88100
color: #e0e0e0 !important;
89101
}
90102

91-
.mud-toolbar{
103+
.mud-toolbar {
92104
height: 24px;
93105
min-height: unset;
94106
flex-wrap: nowrap;
95107
padding-left: 6px;
96108
padding-right: 6px;
97109
}
98110

99-
.try-errorlist-button{
111+
.try-errorlist-button {
100112
padding: 3px 6px;
101-
&:hover{
113+
114+
&:hover {
102115
cursor: pointer;
103116
background-color: rgba(255, 255, 255, 0.25);
104117
}
@@ -109,43 +122,51 @@
109122
font-size: 18px;
110123
line-height: normal;
111124
}
125+
112126
svg:last-child {
113127
margin-right: 6px;
114128
}
129+
115130
p {
116131
font-size: 14px;
117132
line-height: normal;
118-
&:last-child{
133+
134+
&:last-child {
119135
margin-right: 6px;
120136
}
121137
}
122138
}
123139
}
140+
124141
.gutter.gutter-horizontal {
125142
cursor: ew-resize;
126143
background-color: var(--try-tabs);
127144
background-repeat: no-repeat;
128145
background-position: 50%;
129146
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg==');
130147

131-
&:active{
148+
&:active {
132149
background-color: #766ae7;
133150
}
134151
}
152+
135153
.minimap {
136154
display: none;
137155
}
138-
.decorationsOverviewRuler{
156+
157+
.decorationsOverviewRuler {
139158
width: 8px !important;
140159
}
141-
.invisible.scrollbar.vertical.fade, .visible.scrollbar.vertical{
160+
161+
.invisible.scrollbar.vertical.fade, .visible.scrollbar.vertical {
142162
width: 8px !important;
143163
}
144-
.invisible.scrollbar.horizontal.fade, .visible.scrollbar.horizontal{
164+
165+
.invisible.scrollbar.horizontal.fade, .visible.scrollbar.horizontal {
145166
height: 8px !important;
146167
}
147168

148-
.version-info{
169+
.version-info {
149170
font-family: consolas;
150171
font-size: 14px;
151172
text-transform: lowercase;

src/TryMudBlazor.Client/wwwroot/editor/main.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require.config({ paths: { 'vs': 'lib/monaco-editor/min/vs' } });
33
let _dotNetInstance;
44

55
const throttleLastTimeFuncNameMappings = {};
6+
const CACHE_NAME = 'dotnet-resources-/';
67

78
function registerLangugageProvider(language) {
89
monaco.languages.registerCompletionItemProvider(language, {
@@ -98,6 +99,20 @@ window.Try = {
9899
setTimeout(() => iFrame.src = newSrc);
99100
}
100101
},
102+
clearCache: async function () {
103+
const cacheName = CACHE_NAME;
104+
try {
105+
const cache = await caches.open(cacheName);
106+
const keys = await cache.keys();
107+
108+
await Promise.all(keys.map(key => {
109+
return cache.delete(key);
110+
}));
111+
console.log(`Cache '${cacheName}' has been cleared.`);
112+
} catch (error) {
113+
console.error('Error clearing cache:', error);
114+
}
115+
},
101116
dispose: function () {
102117
_dotNetInstance = null;
103118
window.removeEventListener('keydown', onKeyDown);
@@ -206,7 +221,7 @@ window.Try.CodeExecution = window.Try.CodeExecution || (function () {
206221

207222
return {
208223
getCompilationDlls: async function (dllNames) {
209-
const cache = await caches.open('dotnet-resources-/');
224+
const cache = await caches.open(CACHE_NAME);
210225
const keys = await cache.keys();
211226
const dllsData = [];
212227
await Promise.all(dllNames.map(async (dll) => {
@@ -226,7 +241,7 @@ window.Try.CodeExecution = window.Try.CodeExecution || (function () {
226241
return;
227242
}
228243

229-
const cache = await caches.open('dotnet-resources-/');
244+
const cache = await caches.open(CACHE_NAME);
230245

231246
const cacheKeys = await cache.keys();
232247
// Requires WasmFingerprintAssets to be enabled

src/TryMudBlazor.Server/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using MudBlazor;
12
using MudBlazor.Examples.Data;
23

34
namespace TryMudBlazor.Server;
@@ -41,7 +42,10 @@ public static void Main(string[] args)
4142
app.UseStaticFiles();
4243

4344
app.MapControllers();
44-
app.MapFallbackToFile("index.html");
45+
46+
var v = typeof(MudText).Assembly.GetName().Version;
47+
var cacheBusting = $"v{v.Major}.{v.Minor}.{v.Build}";
48+
app.MapFallbackToFile("index.html").CacheOutput(policy => policy.SetVaryByQuery("cachebust", cacheBusting));
4549

4650
app.Run();
4751
}

0 commit comments

Comments
 (0)