From ecb990fb7779d64f4f23fb46fef4c87ac6ee150b Mon Sep 17 00:00:00 2001 From: Mizah Date: Sun, 17 Nov 2024 12:48:39 +0200 Subject: [PATCH] Added docs to $i, iAmModerator, iAmAdmin. --- packages/frontend/src/account.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index 36186ecac1..fb31fef380 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -22,11 +22,35 @@ type Account = Misskey.entities.MeDetailed & { token: string }; const accountData = miLocalStorage.getItem('account'); // TODO: 外部からはreadonlyに +/** + * Reactive state for the current account. "I" as in "I am logged in". + * Initialized from local storage if available, otherwise null. + * + * @type {Account | null} + */ export const $i = accountData ? reactive(JSON.parse(accountData) as Account) : null; +/** + * Whether the current account is a moderator. + * + * @type {boolean} + */ export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true); + +/** + * Whether the current account is an administrator. + * + * @type {boolean} + */ export const iAmAdmin = $i != null && $i.isAdmin; +/** + * Whether it is necessary to sign in; checks if the current + * account is null and throws an error if so. + * + * @throws {Error} If the current account is null + * @returns {Account} The current account + */ export function signinRequired() { if ($i == null) throw new Error('signin required'); return $i;