Skip to content
Open
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
143 changes: 68 additions & 75 deletions src/components/sidebar/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "./style.scss";
import fsOperation from "fileSystem";
import toast from "components/toast";
import confirm from "dialogs/confirm";
import loader from "dialogs/loader";
import Ref from "html-tag-js/ref";
import actionStack from "lib/actionStack";
import activity from "lib/activity";
import auth, { loginEvents } from "lib/auth";
import config from "lib/config";
import helpers from "utils/helpers";
Expand Down Expand Up @@ -42,7 +42,6 @@ function create($container, $toggler) {
const MAX_WIDTH = () => innerWidth * 0.7; //Max width of the side bar
const resizeBar = Ref();
const userAvatar = Ref();
const userContextMenu = Ref();

$container = $container || app;
let mode = innerWidth > 750 ? "tab" : "phone";
Expand All @@ -67,18 +66,6 @@ function create($container, $toggler) {
onmousedown={onresize}
ontouchstart={onresize}
></div>

<div ref={userContextMenu} className="user-menu">
<div className="user-menu-header">
<div className="user-menu-name"></div>
<div className="user-menu-email"></div>
</div>
{/* <div className="user-menu-separator"></div> */}
<div className="user-menu-item" onclick={handleLogout}>
<span className="icon logout"></span>
{strings.logout}
</div>
</div>
</div>
);
const mask = <span className="mask" onclick={hide}></span>;
Expand Down Expand Up @@ -106,87 +93,91 @@ function create($container, $toggler) {
}

loginEvents.addListener(updateSidebarAvatar);
activity.init();

async function handleUserIconClick(e) {
try {
loader.create(strings["login"], strings["loading..."]);
let user = await auth.getLoggedInUser();

if (!user) {
const confirmation = await confirm(
strings.confirm,
strings["confirm-login"],
);
let openingProfile = false;

if (!confirmation) {
return;
}
async function handleUserIconClick() {
// A second tap while the profile is still opening would stack two pages.
if (openingProfile) return;
openingProfile = true;

loader.show();
// Cached users resolve instantly, so only show a loader if the
// account check is actually slow.
let loaderShown = false;
const loaderTimer = setTimeout(() => {
loaderShown = true;
loader.create(strings["login"], strings["loading..."]);
loader.show();
}, 250);

const stopLoader = () => {
clearTimeout(loaderTimer);
if (loaderShown) {
loaderShown = false;
loader.destroy();
}
};

await auth.login();
try {
let user = null;
try {
user = await auth.getLoggedInUser();
if (!user) {
return;
}
} catch (error) {
// offline or server error: still open the page as signed out
console.error("Error checking login status:", error);
}
stopLoader();

const menu = userContextMenu.el;
const isActive = menu.classList.toggle("active");

if (isActive) {
const menuName = userContextMenu.el.querySelector(".user-menu-name");
const menuEmail = userContextMenu.el.querySelector(".user-menu-email");

if (menuName) {
menuName.content = (
<div style={{ display: "flex" }}>
{user.name}
{Boolean(user.verified) && (
<span className="icon verified badge"></span>
)}
{Boolean(user.acode_pro) && <span className="badge">Pro</span>}
</div>
);
}

if (menuEmail) {
menuEmail.textContent = user.email || "";
}

setTimeout(() => {
document.addEventListener("click", handleClickOutside);
}, 10);
} else {
document.removeEventListener("click", handleClickOutside);
}
const { default: openProfile } = await import(
/* webpackChunkName: "profile" */ "pages/profile"
);
await openProfile({
user,
getAvatarSrc,
onLogin: handleLogin,
onLogout: handleLogout,
});
} catch (error) {
console.error("Error checking login status:", error);
console.error("Error opening profile:", error);
} finally {
loader.destroy();
stopLoader();
openingProfile = false;
}
}

function handleClickOutside(e) {
if (
!userContextMenu.el.contains(e.target) &&
e.target !== userAvatar.el &&
!userAvatar.el.contains(e.target)
) {
userContextMenu.el.classList.remove("active");
document.removeEventListener("click", handleClickOutside);
/**
* Starts the Acode login flow. Used by the profile page.
* @returns {Promise<object|null>} the logged in user, if any
*/
async function handleLogin() {
try {
await auth.login();
return (await auth.getLoggedInUser(true)) || null;
} catch (error) {
console.error("Error during login:", error);
return null;
}
}

async function getAvatarSrc(user) {
const avatarFile = await getUserAvatar(user).catch(() => null);
return avatarFile
? await helpers.toInternalUri(avatarFile)
: generateInitialsAvatar(user.name || user.email || "?");
}

/**
* Logs the user out. Used by the profile page.
* @returns {Promise<boolean>}
*/
async function handleLogout() {
loader.create(strings["logout"], strings["loading..."]);
loader.show();
try {
const user = await auth.getLoggedInUser();
const success = await auth.logout();
if (success) {
userContextMenu.el.classList.remove("active");
document.removeEventListener("click", handleClickOutside);
updateSidebarAvatar();
toast("Logged out successfully");

Expand All @@ -196,11 +187,13 @@ function create($container, $toggler) {
await fsOperation(avatarFile).delete();
}
} catch {}
} else {
toast("Failed to logout");
return true;
}
toast("Failed to logout");
return false;
} catch (error) {
console.error("Error during logout:", error);
return false;
} finally {
loader.destroy();
}
Expand Down
77 changes: 0 additions & 77 deletions src/components/sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -423,80 +423,3 @@ body.no-animation {
transform: scale(0.94);
}
}

.user-menu {
position: absolute;
bottom: 55px;
left: 30px;
width: 200px;
background-color: var(--popup-background-color);
border: 1px solid var(--border-color);
border-radius: 6px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
display: none;
z-index: 1000;
overflow: hidden;

&.active {
display: block;
}

.user-menu-header {
padding: 12px;
border-bottom: 1px solid var(--border-color);

.user-menu-name {
font-weight: 500;
margin-bottom: 4px;

.badge {
display: inline-flex;
align-items: center;
background-color: var(--popup-background-color);
background-color: color-mix(in srgb,
var(--error-text-color) 20%,
transparent);
color: var(--error-text-color);
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
margin-left: 4px;

&.verified {
color: var(--active-color);
background-color: transparent;
padding: 0;
}
}
}

.user-menu-email {
font-size: 12px;
color: var(--popup-text-color);
color: color-mix(in srgb, var(--popup-text-color) 70%, transparent);
}
}

.user-menu-item {
padding: 10px 12px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;

&:hover {
background-color: var(--active-icon-color);
}
}

.user-menu-separator {
height: 1px;
background-color: var(--border-color);
margin: 4px 0;
}
}

@supports not (gap: 1px) {
.user-menu-item > * + * { margin-left: 8px; }
}
21 changes: 21 additions & 0 deletions src/lang/ar-ye.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,27 @@
"plugin-review:error-max-length": "يجب ألا يتجاوز التقييم {max} حرفًا.",
"plugin-review:error-downvote-comment": "أخبر المطوّر بما يمكن تحسينه.",
"plugin-review:error-empty": "أضف تعليقًا أو اختر «أعجبني».",
"profile not signed in": "Not signed in",
"profile sign in prompt": "Sign in with your Acode account.",
"acode account": "Acode account",
"member since": "Member since {date}",
"activity": "Activity",
"top languages": "Top languages",
"last 12 months": "Last 12 months",
"coding time": "Coding time",
"streak": "Streak",
"active days": "Active days",
"less": "Less",
"today time": "Today {time}",
"nothing yet today": "Nothing yet today",
"no activity on": "No activity on {date}",
"languages empty": "Languages show up here as you code.",
"reset activity": "Reset activity",
"reset activity warning": "This clears the time, lines, files and streaks tracked on this device.",
"activity reset": "Activity reset",
"logout confirm": "Are you sure you want to log out of your Acode account?",
"best streak": "Best streak",
"this week": "This week",
"plugin-review:unrated": "غير مقيّم",
"wrapped line indent": "Word wrap indentation",
"wrap-indent-same": "Same",
Expand Down
23 changes: 22 additions & 1 deletion src/lang/az-az.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,5 +915,26 @@
"files saved count": "Files saved: {count}",
"files not saved count": "Files not saved: {count}",
"use native index": "Use native index",
"use native index hint": "Search local folders faster using the native file index."
"use native index hint": "Search local folders faster using the native file index.",
"profile not signed in": "Not signed in",
"profile sign in prompt": "Sign in with your Acode account.",
"acode account": "Acode account",
"member since": "Member since {date}",
"activity": "Activity",
"top languages": "Top languages",
"last 12 months": "Last 12 months",
"coding time": "Coding time",
"streak": "Streak",
"active days": "Active days",
"less": "Less",
"today time": "Today {time}",
"nothing yet today": "Nothing yet today",
"no activity on": "No activity on {date}",
"languages empty": "Languages show up here as you code.",
"reset activity": "Reset activity",
"reset activity warning": "This clears the time, lines, files and streaks tracked on this device.",
"activity reset": "Activity reset",
"logout confirm": "Are you sure you want to log out of your Acode account?",
"best streak": "Best streak",
"this week": "This week"
}
21 changes: 21 additions & 0 deletions src/lang/be-by.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,27 @@
"plugin-review:error-max-length": "Водгук павінен змяшчаць не больш за {max} сімвалаў.",
"plugin-review:error-downvote-comment": "Раскажыце распрацоўшчыку, што можна палепшыць.",
"plugin-review:error-empty": "Дадайце каментарый або выберыце «Падабаецца».",
"profile not signed in": "Not signed in",
"profile sign in prompt": "Sign in with your Acode account.",
"acode account": "Acode account",
"member since": "Member since {date}",
"activity": "Activity",
"top languages": "Top languages",
"last 12 months": "Last 12 months",
"coding time": "Coding time",
"streak": "Streak",
"active days": "Active days",
"less": "Less",
"today time": "Today {time}",
"nothing yet today": "Nothing yet today",
"no activity on": "No activity on {date}",
"languages empty": "Languages show up here as you code.",
"reset activity": "Reset activity",
"reset activity warning": "This clears the time, lines, files and streaks tracked on this device.",
"activity reset": "Activity reset",
"logout confirm": "Are you sure you want to log out of your Acode account?",
"best streak": "Best streak",
"this week": "This week",
"plugin-review:unrated": "Без ацэнкі",
"wrapped line indent": "Word wrap indentation",
"wrap-indent-same": "Same",
Expand Down
21 changes: 21 additions & 0 deletions src/lang/bn-bd.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,27 @@
"plugin-review:error-max-length": "পর্যালোচনা {max} অক্ষর বা তার কম হতে হবে।",
"plugin-review:error-downvote-comment": "কী উন্নত করা যায় তা ডেভেলপারকে জানান।",
"plugin-review:error-empty": "একটি মন্তব্য যোগ করুন বা পছন্দ নির্বাচন করুন।",
"profile not signed in": "Not signed in",
"profile sign in prompt": "Sign in with your Acode account.",
"acode account": "Acode account",
"member since": "Member since {date}",
"activity": "Activity",
"top languages": "Top languages",
"last 12 months": "Last 12 months",
"coding time": "Coding time",
"streak": "Streak",
"active days": "Active days",
"less": "Less",
"today time": "Today {time}",
"nothing yet today": "Nothing yet today",
"no activity on": "No activity on {date}",
"languages empty": "Languages show up here as you code.",
"reset activity": "Reset activity",
"reset activity warning": "This clears the time, lines, files and streaks tracked on this device.",
"activity reset": "Activity reset",
"logout confirm": "Are you sure you want to log out of your Acode account?",
"best streak": "Best streak",
"this week": "This week",
"plugin-review:unrated": "এখনও মূল্যায়ন নেই",
"wrapped line indent": "Word wrap indentation",
"wrap-indent-same": "Same",
Expand Down
Loading