@@ -38104,23 +38104,24 @@ define("extensionsIntegrated/Phoenix/main", function (require, exports, module)
3810438104 Strings = require("strings"),
3810538105 Dialogs = require("widgets/Dialogs"),
3810638106 NotificationUI = require("widgets/NotificationUI"),
38107- DefaultDialogs = require("widgets/DefaultDialogs");
38107+ DefaultDialogs = require("widgets/DefaultDialogs"),
38108+ ProfileMenu = require("./profile-menu");
3810838109
3810938110 const PERSIST_STORAGE_DIALOG_DELAY_SECS = 60000;
3811038111 let $icon;
3811138112
3811238113 function _addToolbarIcon() {
38113- const helpButtonID = "help -button";
38114+ const helpButtonID = "user-profile -button";
3811438115 $icon = $("<a>")
3811538116 .attr({
3811638117 id: helpButtonID,
3811738118 href: "#",
38118- class: "help ",
38119- title: Strings.CMD_SUPPORT
38119+ class: "user ",
38120+ title: Strings.CMD_USER_PROFILE
3812038121 })
3812138122 .appendTo($("#main-toolbar .bottom-buttons"));
3812238123 $icon.on('click', ()=>{
38123- Phoenix.app.openURLInDefaultBrowser(brackets.config.support_url );
38124+ ProfileMenu.init( );
3812438125 });
3812538126 }
3812638127 function _showUnSupportedBrowserDialogue() {
@@ -38839,6 +38840,284 @@ define("extensionsIntegrated/Phoenix/newly-added-features", function (require, e
3883938840 };
3884038841});
3884138842
38843+ define("extensionsIntegrated/Phoenix/profile-menu", function (require, exports, module) {
38844+ const Mustache = require("thirdparty/mustache/mustache");
38845+ const PopUpManager = require("widgets/PopUpManager");
38846+
38847+ // HTML templates
38848+ const loginTemplate = `<div class="profile-popup">
38849+ <div class="popup-header">
38850+ <h1 class="popup-title">{{welcomeTitle}}</h1>
38851+ </div>
38852+ <div class="popup-body">
38853+ <button id="phoenix-signin-btn" class="btn btn-primary">
38854+ <i class="fa fa-sign-in-alt"></i>
38855+ {{signInBtnText}}
38856+ </button>
38857+ <div class="support-link">
38858+ <button id="phoenix-support-btn" class="btn btn-link">
38859+ <i class="fa fa-question-circle"></i>
38860+ {{supportBtnText}}
38861+ </button>
38862+ </div>
38863+ </div>
38864+ </div>
38865+ `;
38866+ const profileTemplate = `<div class="profile-popup">
38867+ <div class="popup-header">
38868+ <div class="user-profile-header">
38869+ <div class="user-avatar">
38870+ {{initials}}
38871+ </div>
38872+ <div class="user-info">
38873+ <div class="user-name">{{userName}}</div>
38874+ <div class="user-plan">{{planName}}</div>
38875+ </div>
38876+ </div>
38877+ </div>
38878+ <div class="popup-body">
38879+ <div class="quota-section">
38880+ <div class="quota-header">
38881+ <span>{{quotaLabel}}</span>
38882+ <span>{{quotaUsed}} / {{quotaTotal}} {{quotaUnit}}</span>
38883+ </div>
38884+ <div class="progress-bar">
38885+ <div class="progress-fill" style="width: {{quotaPercent}}%;"></div>
38886+ </div>
38887+ </div>
38888+
38889+ <button id="phoenix-account-btn" class="btn btn-default menu-button">
38890+ <i class="fa fa-user"></i>
38891+ {{accountBtnText}}
38892+ </button>
38893+
38894+ <button id="phoenix-support-btn" class="btn btn-default menu-button">
38895+ <i class="fa fa-question-circle"></i>
38896+ {{supportBtnText}}
38897+ </button>
38898+
38899+ <button id="phoenix-signout-btn" class="btn btn-default menu-button signout">
38900+ <i class="fa fa-sign-out-alt"></i>
38901+ {{signOutBtnText}}
38902+ </button>
38903+ </div>
38904+ </div>
38905+ `;
38906+
38907+ // for the popup DOM element
38908+ let $popup = null;
38909+
38910+ // this is to track whether the popup is visible or not
38911+ let isPopupVisible = false;
38912+
38913+ // if user is logged in we show the profile menu, otherwise we show the login menu
38914+ const isLoggedIn = false;
38915+
38916+ const defaultLoginData = {
38917+ welcomeTitle: "Welcome to Phoenix Code",
38918+ signInBtnText: "Sign in to your account",
38919+ supportBtnText: "Contact support"
38920+ };
38921+
38922+ const defaultProfileData = {
38923+ initials: "CA",
38924+ userName: "Charly A.",
38925+ planName: "Paid Plan",
38926+ quotaLabel: "AI quota used",
38927+ quotaUsed: "7,000",
38928+ quotaTotal: "10,000",
38929+ quotaUnit: "tokens",
38930+ quotaPercent: 70,
38931+ accountBtnText: "Account details",
38932+ supportBtnText: "Contact support",
38933+ signOutBtnText: "Sign out"
38934+ };
38935+
38936+ function _handleSignInBtnClick() {
38937+ console.log("User clicked sign in button");
38938+ }
38939+
38940+ function _handleSignOutBtnClick() {
38941+ console.log("User clicked sign out");
38942+ }
38943+
38944+ function _handleContactSupportBtnClick() {
38945+ Phoenix.app.openURLInDefaultBrowser(brackets.config.support_url);
38946+ }
38947+
38948+ function _handleAccountDetailsBtnClick() {
38949+ console.log("User clicked account details");
38950+ }
38951+
38952+ /**
38953+ * Close the popup if it's open
38954+ * this is called at various instances like when the user click on the profile icon even if the popup is open
38955+ * or when user clicks somewhere else on the document
38956+ */
38957+ function closePopup() {
38958+ if ($popup) {
38959+ PopUpManager.removePopUp($popup);
38960+ $popup = null;
38961+ isPopupVisible = false;
38962+ }
38963+ }
38964+
38965+ /**
38966+ * this function is to position the popup near the profile button
38967+ */
38968+ function positionPopup() {
38969+ const $profileButton = $("#user-profile-button");
38970+
38971+ if ($profileButton.length && $popup) {
38972+ const buttonPos = $profileButton.offset();
38973+ const popupWidth = $popup.outerWidth();
38974+ const windowWidth = $(window).width();
38975+
38976+ // pos above the profile button
38977+ let top = buttonPos.top - $popup.outerHeight() - 10;
38978+
38979+ // If popup would go off the right edge of the window, align right edge of popup with right edge of button
38980+ let left = Math.min(
38981+ buttonPos.left - popupWidth + $profileButton.outerWidth(),
38982+ windowWidth - popupWidth - 10
38983+ );
38984+
38985+ // never go off left edge
38986+ left = Math.max(10, left);
38987+
38988+ $popup.css({
38989+ top: top + "px",
38990+ left: left + "px"
38991+ });
38992+ }
38993+ }
38994+
38995+ /**
38996+ * Shows the sign-in popup when the user is not logged in
38997+ * @param {Object} loginData - Data to populate the template (optional)
38998+ */
38999+ function showLoginPopup(loginData) {
39000+ // If popup is already visible, just close it
39001+ if (isPopupVisible) {
39002+ closePopup();
39003+ return;
39004+ }
39005+
39006+ // Merge provided data with defaults
39007+ const templateData = $.extend({}, defaultLoginData, loginData || {});
39008+
39009+ // create the popup element
39010+ closePopup(); // close any existing popup first
39011+
39012+ // Render template with data
39013+ const renderedTemplate = Mustache.render(loginTemplate, templateData);
39014+ $popup = $(renderedTemplate);
39015+
39016+ $("body").append($popup);
39017+ isPopupVisible = true;
39018+
39019+ positionPopup();
39020+
39021+ PopUpManager.addPopUp($popup, function() {
39022+ $popup.remove();
39023+ $popup = null;
39024+ isPopupVisible = false;
39025+ }, true, { closeCurrentPopups: true });
39026+
39027+ // event handlers for buttons
39028+ $popup.find("#phoenix-signin-btn").on("click", function () {
39029+ _handleSignInBtnClick();
39030+ closePopup();
39031+ });
39032+
39033+ $popup.find("#phoenix-support-btn").on("click", function () {
39034+ _handleContactSupportBtnClick();
39035+ closePopup();
39036+ });
39037+
39038+ // handle window resize to reposition popup
39039+ $(window).on("resize.profilePopup", function () {
39040+ if (isPopupVisible) {
39041+ positionPopup();
39042+ }
39043+ });
39044+ }
39045+
39046+ /**
39047+ * Shows the user profile popup when the user is logged in
39048+ * @param {Object} profileData - Data to populate the template (optional)
39049+ */
39050+ function showProfilePopup(profileData) {
39051+ // If popup is already visible, just close it
39052+ if (isPopupVisible) {
39053+ closePopup();
39054+ return;
39055+ }
39056+
39057+ // Merge provided data with defaults
39058+ const templateData = $.extend({}, defaultProfileData, profileData || {});
39059+
39060+ closePopup();
39061+
39062+ // Render template with data
39063+ const renderedTemplate = Mustache.render(profileTemplate, templateData);
39064+ $popup = $(renderedTemplate);
39065+
39066+ $("body").append($popup);
39067+ isPopupVisible = true;
39068+ positionPopup();
39069+
39070+ PopUpManager.addPopUp($popup, function() {
39071+ $popup.remove();
39072+ $popup = null;
39073+ isPopupVisible = false;
39074+ }, true, { closeCurrentPopups: true });
39075+
39076+ $popup.find("#phoenix-account-btn").on("click", function () {
39077+ _handleAccountDetailsBtnClick();
39078+ closePopup();
39079+ });
39080+
39081+ $popup.find("#phoenix-support-btn").on("click", function () {
39082+ _handleContactSupportBtnClick();
39083+ closePopup();
39084+ });
39085+
39086+ $popup.find("#phoenix-signout-btn").on("click", function () {
39087+ _handleSignOutBtnClick();
39088+ closePopup();
39089+ });
39090+
39091+ // handle window resize to reposition popup
39092+ $(window).on("resize.profilePopup", function () {
39093+ if (isPopupVisible) {
39094+ positionPopup();
39095+ }
39096+ });
39097+ }
39098+
39099+ /**
39100+ * Toggle the profile popup based on the user's login status
39101+ * this function is called inside the src/extensionsIntegrated/Phoenix/main.js when user clicks on the profile icon
39102+ * @param {Object} data - Data to populate the templates (optional)
39103+ */
39104+ function init(data) {
39105+ // check if the popup is already visible or not. if visible close it
39106+ if (isPopupVisible) {
39107+ closePopup();
39108+ return;
39109+ }
39110+
39111+ if (isLoggedIn) {
39112+ showProfilePopup(data);
39113+ } else {
39114+ showLoginPopup(data);
39115+ }
39116+ }
39117+
39118+ exports.init = init;
39119+ });
39120+
3884239121/*
3884339122 * GNU AGPL-3.0 License
3884439123 *
@@ -104135,6 +104414,7 @@ define("nls/root/strings", {
104135104414 "CMD_AUTO_UPDATE": "Auto Update",
104136104415 "CMD_HOW_TO_USE_BRACKETS": "How to Use {APP_NAME}",
104137104416 "CMD_SUPPORT": "{APP_NAME} Support",
104417+ "CMD_USER_PROFILE": "User Profile",
104138104418 "CMD_DOCS": "Help, Getting Started",
104139104419 "CMD_SUGGEST": "Suggest a Feature",
104140104420 "CMD_REPORT_ISSUE": "Report Issue",
0 commit comments