-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSizeManager.cs
More file actions
41 lines (36 loc) · 1.43 KB
/
SizeManager.cs
File metadata and controls
41 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using DevExpress.Blazor;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.JSInterop;
namespace switcher.Services {
public class SizeManager {
protected CookiesService _cookiesService;
protected IJSRuntime _jsRuntime { get; set; }
const string SizeModeCookieKey = "DXSizeMode";
public SizeMode ActiveSizeMode;
public SizeManager(CookiesService cs, IHttpContextAccessor httpContextAccessor, IJSRuntime js) {
_cookiesService = cs;
_jsRuntime = js;
var sizeMode = _cookiesService.GetCookie(httpContextAccessor, SizeModeCookieKey);
if (string.IsNullOrEmpty(sizeMode))
ActiveSizeMode = SizeMode.Medium;
else
ActiveSizeMode = Enum.Parse<SizeMode>(sizeMode);
}
public async Task SetSizeMode(SizeMode sizeMode) {
ActiveSizeMode = sizeMode;
await _cookiesService.SetCookie(SizeModeCookieKey, sizeMode.ToString());
await SetSizeInJS();
}
public async Task SetSizeInJS() {
await _jsRuntime.InvokeVoidAsync("setSize", GetFontSizeString());
}
public string GetFontSizeString() {
return ActiveSizeMode switch {
SizeMode.Small => "14px",
SizeMode.Medium => "16px",
SizeMode.Large => "18px",
_ => "16px"
};
}
}
}