Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions Abies.Conduit/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Abies.Conduit.Routing;
using Abies.Conduit.Services;
using Abies.DOM;
using System.Threading.Tasks;
using static Abies.Conduit.Main.Message.Event;
using static Abies.UrlRequest;
Expand Down Expand Up @@ -222,24 +223,32 @@ public static (Model model, IEnumerable<Command> commands) Update(Abies.Message
}

}


private static Node WithLayout(Node page, Model model) =>
div([], [
Navigation.View(model),
page
]);

public static Document View(Model model)
=> model.Page switch
{
Page.Redirect => new Document(string.Format(Title, "Redirect"), h1([], [text("Redirecting...")])),
Page.NotFound => new Document(string.Format(Title, "Not Found"), h1([], [text("Not Found")])),
Page.Home home => new Document(string.Format(Title, nameof(Conduit.Page.Home)), Conduit.Page.Home.Page.View(home.Model)),
Page.Settings settings => new Document(string.Format(Title, nameof(Conduit.Page.Settings)), Conduit.Page.Settings.Page.View(settings.Model)),
Page.Login login => new Document(string.Format(Title, nameof(Conduit.Page.Login)), Conduit.Page.Login.Page.View(login.Model)),
Page.Register register => new Document(string.Format(Title, nameof(Conduit.Page.Register)), Conduit.Page.Register.Page.View(register.Model)), Page.Profile profile => new Document(string.Format(Title, nameof(Conduit.Page.Profile)), Conduit.Page.Profile.Page.View(profile.Model)),
Page.ProfileFavorites profileFavorites => new Document(string.Format(Title, "Profile Favorites"), Conduit.Page.Profile.Page.View(profileFavorites.Model)),
Page.Article article => new Document(string.Format(Title, nameof(Conduit.Page.Article)), Conduit.Page.Article.Page.View(article.Model)),
Page.NewArticle newArticle => new Document(string.Format(Title, "New Article"), Conduit.Page.Editor.Page.View(newArticle.Model)),
_ => new Document(string.Format(Title, "Not Found"), h1([], [text("Not Found")]))
Page.Redirect => new Document(string.Format(Title, "Redirect"), WithLayout(h1([], [text("Redirecting...")]), model)),
Page.NotFound => new Document(string.Format(Title, "Not Found"), WithLayout(h1([], [text("Not Found")]), model)),
Page.Home home => new Document(string.Format(Title, nameof(Conduit.Page.Home)), WithLayout(Conduit.Page.Home.Page.View(home.Model), model)),
Page.Settings settings => new Document(string.Format(Title, nameof(Conduit.Page.Settings)), WithLayout(Conduit.Page.Settings.Page.View(settings.Model), model)),
Page.Login login => new Document(string.Format(Title, nameof(Conduit.Page.Login)), WithLayout(Conduit.Page.Login.Page.View(login.Model), model)),
Page.Register register => new Document(string.Format(Title, nameof(Conduit.Page.Register)), WithLayout(Conduit.Page.Register.Page.View(register.Model), model)),
Page.Profile profile => new Document(string.Format(Title, nameof(Conduit.Page.Profile)), WithLayout(Conduit.Page.Profile.Page.View(profile.Model), model)),
Page.ProfileFavorites profileFavorites => new Document(string.Format(Title, "Profile Favorites"), WithLayout(Conduit.Page.Profile.Page.View(profileFavorites.Model), model)),
Page.Article article => new Document(string.Format(Title, nameof(Conduit.Page.Article)), WithLayout(Conduit.Page.Article.Page.View(article.Model), model)),
Page.NewArticle newArticle => new Document(string.Format(Title, "New Article"), WithLayout(Conduit.Page.Editor.Page.View(newArticle.Model), model)),
_ => new Document(string.Format(Title, "Not Found"), WithLayout(h1([], [text("Not Found")]), model))
};





public static Abies.Message OnUrlChanged(Url url)
=> new UrlChanged(url);

Expand Down
44 changes: 44 additions & 0 deletions Abies.Conduit/Navigation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Abies.Conduit.Main;
using Abies.Conduit.Routing;
using Abies.DOM;
using static Abies.Html.Elements;
using static Abies.Html.Attributes;

namespace Abies.Conduit;

public static class Navigation
{
private static Node NavLink(string url, string label, bool active) =>
li([class_("nav-item")], [
a([class_(active ? "nav-link active" : "nav-link"), href(url)], [text(label)])
]);

public static Node View(Model model)
{
var userLinks = model.CurrentUser == null
? new Node[]
{
NavLink("/login", "Sign in", model.CurrentRoute is Route.Login),

Check failure on line 21 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Login' does not exist in the type 'Route'

Check failure on line 21 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Login' does not exist in the type 'Route'
NavLink("/register", "Sign up", model.CurrentRoute is Route.Register)

Check failure on line 22 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Register' does not exist in the type 'Route'

Check failure on line 22 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Register' does not exist in the type 'Route'
}
: new Node[]
{
NavLink("/editor", "New Article", model.CurrentRoute is Route.NewArticle),

Check failure on line 26 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'NewArticle' does not exist in the type 'Route'

Check failure on line 26 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'NewArticle' does not exist in the type 'Route'
NavLink("/settings", "Settings", model.CurrentRoute is Route.Settings),

Check failure on line 27 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Settings' does not exist in the type 'Route'
NavLink($"/profile/{model.CurrentUser!.Username.Value}",
model.CurrentUser.Username.Value,
model.CurrentRoute is Route.Profile p && p.UserName.Value == model.CurrentUser.Username.Value ||

Check failure on line 30 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Profile' does not exist in the type 'Route'
model.CurrentRoute is Route.ProfileFavorites pf && pf.UserName.Value == model.CurrentUser.Username.Value)

Check failure on line 31 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'ProfileFavorites' does not exist in the type 'Route'
};

return nav([class_("navbar navbar-light")], [
div([class_("container")], [
a([class_("navbar-brand"), href("/")], [text("conduit")]),
ul([class_("nav navbar-nav pull-xs-right")], [
NavLink("/", "Home", model.CurrentRoute is Route.Home),

Check failure on line 38 in Abies.Conduit/Navigation.cs

View workflow job for this annotation

GitHub Actions / build

The type name 'Home' does not exist in the type 'Route'
..userLinks
])
])
]);
}
}
Loading