From 9d9df3175e64be5cd6d8023ddc4434b1cf47539d Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 19 Jan 2022 01:22:31 +0100 Subject: [PATCH] user: Add HTML templates for user menu --- src/invidious/frontend/user_menu.cr | 112 ++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/invidious/frontend/user_menu.cr diff --git a/src/invidious/frontend/user_menu.cr b/src/invidious/frontend/user_menu.cr new file mode 100644 index 00000000..9a486f70 --- /dev/null +++ b/src/invidious/frontend/user_menu.cr @@ -0,0 +1,112 @@ +module Invidious::Frontend::UserMenu + extend self + + # ------------------- + # Menu items + # ------------------- + + enum UserContentMenu + Subscriptions + WatchHistory + Playlists + end + + enum UserAccountMenu + Preferences + Account + ImportExport + LogOut + end + + private alias UserMenuItem = UserContentMenu | UserAccountMenu + + # ------------------- + # HTML templates + # ------------------- + + # Generates the following menu: + # + # ``` + #
+ # + #
+ # ``` + # + # The selected entry will have the "selected" class. + # + def make_menu(env : HTTP::Server::Context, selected_item : UserMenuItem) : String + # A capacity of 1500 is enough to store the HTML (empty) + # plus the URLs with parameters and the translated text. + str_builder = String::Builder.new(1500) + + # TODO: Get variables from HTTP env + locale = env.get("preferences").as(Preferences).locale + params = nil + + # Start of menu #1 + str_builder << <<-HTML +
+
+ HTML + + return str_builder.to_s + end +end