Skip to content

Commit

Permalink
refactor: static SSR (#60)
Browse files Browse the repository at this point in the history
* 🚧 feat: wip

* refactor

* 🚧 feat: wip

* use [email protected]
  • Loading branch information
capdiem authored Dec 22, 2023
1 parent 325d348 commit 4ed2d05
Show file tree
Hide file tree
Showing 49 changed files with 628 additions and 676 deletions.
2 changes: 1 addition & 1 deletion src/MASA.OfficialWebsite.WebApp/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta name="description" content="数闪科技致力于用 .NET技术打造开源企业级开发者门户 平台工程 MASA Stack,提供一站式.NET现代化应用开发交付解决方案,赋能 560万.NET开发者转型为数字化人才,帮助企业降低数字化转型门槛,让变化更简单!" />
<base href="/" />
<link rel="stylesheet" href="_content/Masa.Blazor/css/masa-blazor.min.css" />
<link rel="stylesheet" href="_content/Masa.Blazor/css/masa-blazor.ssr.css" />
<link rel="stylesheet" href="css/standard.css" />
<link rel="stylesheet" href="css/shared.css" />
<link rel="stylesheet" href="css/small-shared.css" media="(max-width: 960px)" />
Expand All @@ -24,7 +25,6 @@

<body>
<Routes />
<MSsrStateProvider @rendermode="InteractiveServer"></MSsrStateProvider>

<script src="_framework/blazor.web.js"></script>
<script src="_content/BlazorComponent/js/blazor-component.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
@inject MasaBlazor MasaBlazor
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.AspNetCore.Components.Sections

<MAppBar App
Height="@BarHeight"
Class="@($"appbar {Class}")"
Color="transparent"
Flat
Dense>
<a href="/" style="display: contents">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
<AppBar Class="hidden-sm-and-down" BarHeight="100" LogoHeight="42">
<SectionOutlet SectionName="document" />
<SerializableNavMenu Items="@ProductNavItems" Title="产品" />
<SerializableNavMenu Items="@StudyNavItems" Title="学习" />
<MButton Text Class="nav h8 emphasis2--text" Href="/aboutus">

<MInteractiveTriggers Class="nav-menus"
WithPopup
Left="NavMenuLeft"
PopupClass="menu-list"
TValue="string"
QueryName="nav-menu"
QueryValue="@QueryValue"
InteractiveValue="navMenuInteractiveValues"
InteractiveComponentType="typeof(NavMenu)"
InteractiveComponentParameters="ProductNavMenuParameters">
<MButton Id="@($"{context}-nav-menu")" Class="mr-9 h8 emphasis2--text" Text>
@(context switch
{
"product" => "产品",
"study" => "学习",
_ => context
})
</MButton>
</MInteractiveTriggers>

<MButton Text Class="h8 emphasis2--text" Href="/aboutus">
关于我们
</MButton>
</AppBar>
Expand All @@ -13,4 +32,18 @@

[Parameter] public List<NavItem> StudyNavItems { get; set; } = new();

[SupplyParameterFromQuery(Name = "nav-menu")]
private string? QueryValue { get; set; }

private static string[] navMenuInteractiveValues = { "product", "study" };

private bool IsProductNavMenu => QueryValue?.Equals("product", StringComparison.OrdinalIgnoreCase) is true;

private Dictionary<string, object> ProductNavMenuParameters => new()
{
{ nameof(NavMenu.Items), IsProductNavMenu ? ProductNavItems : StudyNavItems },
};

private int NavMenuLeft => IsProductNavMenu ? -388 : -286;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@rendermode @(new InteractiveServerRenderMode(prerender: false))
@inherits MInteractivePopup

<div class="mt-2 @Class" style="@Style" id="follow-us-image">
<img src="@Image" />
</div>

@code {

[Parameter] [EditorRequired] public string Image { get; set; } = null!;

[Parameter] public string? Style { get; set; }

[Parameter] public string? Class { get; set; }

}
33 changes: 28 additions & 5 deletions src/MASA.OfficialWebsite.WebApp/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</svg>
<div class="rectangle-723"></div>
</div>
<MobileAppBar NavItems="AllNavItems" @rendermode="InteractiveServer" />

<MobileAppBar NavItems="AllNavItems" />

<DesktopAppBar ProductNavItems="productNavItems"
StudyNavItems="studyNavItems" />

Expand Down Expand Up @@ -128,8 +128,20 @@
<MCard Color="transparent" Flat Dark Class="footer-content__item footer-content__focus">
<MCardTitle>关注我们</MCardTitle>
<MCardText>
<WeChatBtn />
<QQChatBtn />
<MInteractiveTriggers Class="d-inline"
QueryName="@nameof(FollowUs)"
QueryValue="@FollowUs"
InteractiveValue="@(new[] { "wechat", "qq" })"
InteractiveComponentType="typeof(FollowUsBtn)"
InteractiveComponentParameters="@FollowUsParameters">
<MButton Outlined
Icon
Color="white"
Class="follow-us-icon mr-9">
<MIcon>@(context == "wechat" ? "mdi-wechat" : "mdi-qqchat")</MIcon>
</MButton>
</MInteractiveTriggers>

<MButton Class="follow-us-icon"
Outlined
Icon
Expand Down Expand Up @@ -157,6 +169,8 @@
</div>
</MApp>

<MSsrLayoutScript />

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
Expand All @@ -165,6 +179,15 @@

@code {

[SupplyParameterFromQuery]
private string? FollowUs { get; set; }

private Dictionary<string, object> FollowUsParameters => new()
{
{ nameof(FollowUsBtn.Image), FollowUs == "wechat" ? "https://cdn.masastack.com/images/contact.png" : "https://cdn.masastack.com/images/contact-qq.png" },
{ nameof(FollowUsBtn.Class), FollowUs }
};

private static readonly List<NavItem> productNavItems =
[
new NavItem("产品中心"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
<AppBar Class="hidden-md-and-up" BarHeight="48" LogoHeight="30">
<MButton Icon OnClick="() => _drawer = true">
@inject NavigationManager Navigation

<AppBar Class="hidden-md-and-up" BarHeight="48" LogoHeight="30">
<MButton Icon Href="@Navigation.GetUriWithQueryParameter(nameof(Aside), true)">
<MIcon>mdi-menu</MIcon>
</MButton>
</AppBar>

<MNavigationDrawer @bind-Value="_drawer" Fixed Temporary Right Width="315">
<MList Class="menu-list mt-1" Style="height: 100%; overflow-y: auto; padding-top:24px;" Elevation="0" Subheader TwoLine Routable>
@foreach (var item in NavItems)
{
@if (item.IsSubheader)
{
<MSubheader Style="height: auto"
Class="subtitle3 emphasis--text">
@item.Subheader
</MSubheader>
}
else
{
<MListItem Href="@item.Href" Disabled="@item.Disabled" ActiveClass="primary--text" Class="home-menu-hover">
@if (item.Image is not null)
{
<MListItemAvatar Tile Size="40" Class="mt-0 mb-0">
<MImage Src="@item.Image"
alt="@item.Title"
Height="@item.Size"
Width="@item.Size"
Contain
Eager />
</MListItemAvatar>
}
<MListItemContent >
<MListItemTitle Class="h8 regular--text">
@if (item.Disabled)
{
<div style="color: #A3AED0;">@item.Title</div>
}
else
{
<div style="color: #485585;">@item.Title</div>
}
</MListItemTitle>
<MListItemSubtitle Class="body2 regular3--text">@item.Subtitle</MListItemSubtitle>
</MListItemContent>
</MListItem>
}
}
</MList>
</MNavigationDrawer>
@if (Aside)
{
<MobileNavigationDrawer NavItems="NavItems" />
}

@code {

private bool? _drawer;

[Parameter] public List<NavItem> NavItems { get; set; } = new();

[SupplyParameterFromQuery]
private bool Aside { get; set; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
@rendermode InteractiveServer
@inject NavigationManager Navigation

<MNavigationDrawer Value="@_drawer"
ValueChanged="ValueChanged"
Fixed
Temporary
Right
Width="315"
NoSsr>
<MList Class="mt-1" Style="height: 100%; overflow-y: auto; padding-top:24px;" Elevation="0" Subheader TwoLine Routable>
@foreach (var item in NavItems)
{
@if (item.IsSubheader)
{
<MSubheader Style="height: auto"
Class="subtitle3 emphasis--text">
@item.Subheader
</MSubheader>
}
else
{
<MListItem Href="@item.Href" Disabled="@item.Disabled" ActiveClass="primary--text" Class="home-menu-hover">
@if (item.Image is not null)
{
<MListItemAvatar Tile Size="40" Class="mt-0 mb-0">
<MImage Src="@item.Image"
alt="@item.Title"
Height="@item.Size"
Width="@item.Size"
Contain
Eager />
</MListItemAvatar>
}
<MListItemContent >
<MListItemTitle Class="h8 regular--text">
@if (item.Disabled)
{
<div style="color: #A3AED0;">@item.Title</div>
}
else
{
<div style="color: #485585;">@item.Title</div>
}
</MListItemTitle>
<MListItemSubtitle Class="body2 regular3--text">@item.Subtitle</MListItemSubtitle>
</MListItemContent>
</MListItem>
}
}
</MList>
</MNavigationDrawer>

@code {

[Parameter] public List<NavItem> NavItems { get; set; } = new();

private bool? _drawer = false;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await Task.Delay(100);
_drawer = true;
StateHasChanged();
}
}

private async Task ValueChanged(bool? val)
{
var prevDrawer = _drawer;

_drawer = val;

StateHasChanged();

await Task.Delay(300);

if (prevDrawer is true && _drawer is false)
{
Navigation.NavigateTo(Navigation.GetUriWithQueryParameter("Aside", (bool?)null));
}
}

}
59 changes: 0 additions & 59 deletions src/MASA.OfficialWebsite.WebApp/Components/Layout/QQChatBtn.razor

This file was deleted.

Loading

0 comments on commit 4ed2d05

Please sign in to comment.