read-only mode nav avatar icon and text
Some checks are pending
continuous-integration/drone/push Build is running

This commit is contained in:
Martti Malmi 2023-11-30 14:40:46 +02:00
parent 96e49dac41
commit 91a10024e0
4 changed files with 31 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import { useUserProfile } from "@snort/system-react";
import { useMemo, useSyncExternalStore } from "react"; import { useMemo, useSyncExternalStore } from "react";
import { base64 } from "@scure/base"; import { base64 } from "@scure/base";
import { unwrap } from "@snort/shared"; import { unwrap } from "@snort/shared";
import { FormattedMessage } from "react-intl"; import { FormattedMessage, useIntl } from "react-intl";
import SearchBox from "@/Element/SearchBox"; import SearchBox from "@/Element/SearchBox";
import { ProfileLink } from "@/Element/User/ProfileLink"; import { ProfileLink } from "@/Element/User/ProfileLink";
import Avatar from "@/Element/User/Avatar"; import Avatar from "@/Element/User/Avatar";
@ -17,6 +17,7 @@ import { Notifications } from "@/Cache";
const AccountHeader = () => { const AccountHeader = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const { formatMessage } = useIntl();
useKeyboardShortcut("/", event => { useKeyboardShortcut("/", event => {
// if event happened in a form element, do nothing, otherwise focus on search input // if event happened in a form element, do nothing, otherwise focus on search input
@ -76,6 +77,13 @@ const AccountHeader = () => {
</button> </button>
); );
} }
const readOnlyIcon = readonly && (
<span style={{ transform: "rotate(135deg)" }} title={formatMessage({ defaultMessage: "Read-only", id: "djNL6D" })}>
<Icon name="openeye" className="text-nostr-red" size={20} />
</span>
);
return ( return (
<div className="header-actions"> <div className="header-actions">
{!location.pathname.startsWith("/search") ? <SearchBox /> : <div className="grow"></div>} {!location.pathname.startsWith("/search") ? <SearchBox /> : <div className="grow"></div>}
@ -90,7 +98,7 @@ const AccountHeader = () => {
<HasNotificationsMarker /> <HasNotificationsMarker />
</Link> </Link>
<ProfileLink pubkey={publicKey} user={profile}> <ProfileLink pubkey={publicKey} user={profile}>
<Avatar pubkey={publicKey} user={profile} /> <Avatar pubkey={publicKey} user={profile} icons={readOnlyIcon} />
</ProfileLink> </ProfileLink>
</div> </div>
); );

View File

@ -6,7 +6,7 @@ import Avatar from "../../Element/User/Avatar";
import useLogin from "../../Hooks/useLogin"; import useLogin from "../../Hooks/useLogin";
import { useUserProfile } from "@snort/system-react"; import { useUserProfile } from "@snort/system-react";
import { NoteCreatorButton } from "../../Element/Event/Create/NoteCreatorButton"; import { NoteCreatorButton } from "../../Element/Event/Create/NoteCreatorButton";
import { FormattedMessage } from "react-intl"; import { FormattedMessage, useIntl } from "react-intl";
import classNames from "classnames"; import classNames from "classnames";
import { HasNotificationsMarker } from "@/Pages/Layout/AccountHeader"; import { HasNotificationsMarker } from "@/Pages/Layout/AccountHeader";
import { getCurrentSubscription } from "@/Subscription"; import { getCurrentSubscription } from "@/Subscription";
@ -65,19 +65,27 @@ const getNavLinkClass = (isActive: boolean, narrow: boolean) => {
}; };
export default function NavSidebar({ narrow = false }) { export default function NavSidebar({ narrow = false }) {
const { publicKey, subscriptions } = useLogin(s => ({ const { publicKey, subscriptions, readonly } = useLogin(s => ({
publicKey: s.publicKey, publicKey: s.publicKey,
subscriptions: s.subscriptions, subscriptions: s.subscriptions,
readonly: s.readonly,
})); }));
const profile = useUserProfile(publicKey); const profile = useUserProfile(publicKey);
const navigate = useNavigate(); const navigate = useNavigate();
const sub = getCurrentSubscription(subscriptions); const sub = getCurrentSubscription(subscriptions);
const { formatMessage } = useIntl();
const className = classNames( const className = classNames(
{ "xl:w-56 xl:gap-3 xl:items-start": !narrow }, { "xl:w-56 xl:gap-3 xl:items-start": !narrow },
"overflow-y-auto hide-scrollbar sticky items-center border-r border-neutral-900 top-0 z-20 h-screen max-h-screen hidden md:flex flex-col px-2 py-4 flex-shrink-0 gap-2", "overflow-y-auto hide-scrollbar sticky items-center border-r border-neutral-900 top-0 z-20 h-screen max-h-screen hidden md:flex flex-col px-2 py-4 flex-shrink-0 gap-2",
); );
const readOnlyIcon = readonly && (
<span style={{ transform: "rotate(135deg)" }} title={formatMessage({ defaultMessage: "Read-only", id: "djNL6D" })}>
<Icon name="openeye" className="text-nostr-red" size={20} />
</span>
);
return ( return (
<div className={className}> <div className={className}>
<LogoHeader showText={!narrow} /> <LogoHeader showText={!narrow} />
@ -121,17 +129,20 @@ export default function NavSidebar({ narrow = false }) {
)} )}
</div> </div>
</div> </div>
{publicKey ? ( {publicKey && (
<> <>
<ProfileLink pubkey={publicKey} user={profile}> <ProfileLink pubkey={publicKey} user={profile}>
<div className="flex flex-row items-center font-bold text-md"> <div className="flex flex-row items-center font-bold text-md">
<Avatar pubkey={publicKey} user={profile} size={40} /> <Avatar pubkey={publicKey} user={profile} size={40} icons={readOnlyIcon} />
{!narrow && <span className="hidden xl:inline ml-3">{profile?.name}</span>} {!narrow && <span className="hidden xl:inline ml-3">{profile?.name}</span>}
</div> </div>
</ProfileLink> </ProfileLink>
{readonly && (
<div className="hidden xl:block text-nostr-red text-sm">
<FormattedMessage defaultMessage="Read-only" id="djNL6D" />
</div>
)}
</> </>
) : (
""
)} )}
</div> </div>
); );

View File

@ -1032,6 +1032,9 @@
"deEeEI": { "deEeEI": {
"defaultMessage": "Register" "defaultMessage": "Register"
}, },
"djNL6D": {
"defaultMessage": "Read-only"
},
"dmsiLv": { "dmsiLv": {
"defaultMessage": "A default Zap Pool split of {n} has been configured for {site} developers, you can disable it at any time in {link}" "defaultMessage": "A default Zap Pool split of {n} has been configured for {site} developers, you can disable it at any time in {link}"
}, },

View File

@ -339,6 +339,7 @@
"dOQCL8": "Display name", "dOQCL8": "Display name",
"ddd3JX": "Popular Hashtags", "ddd3JX": "Popular Hashtags",
"deEeEI": "Register", "deEeEI": "Register",
"djNL6D": "Read-only",
"dmsiLv": "A default Zap Pool split of {n} has been configured for {site} developers, you can disable it at any time in {link}", "dmsiLv": "A default Zap Pool split of {n} has been configured for {site} developers, you can disable it at any time in {link}",
"e61Jf3": "Coming soon", "e61Jf3": "Coming soon",
"e7VmYP": "Enter pin to unlock your private key", "e7VmYP": "Enter pin to unlock your private key",