mirror of
https://github.com/dergigi/boris.git
synced 2025-12-19 15:44:20 +01:00
refactor(ui): move user info to top-right app header
- Create UserHeader component to display user info and logout button - Move 'Logged in as: user' from sidebar to app-header in top-right - Remove user info display from BookmarkList and Bookmarks components - Simplify bookmarks-header layout (only contains collapse button now) - Update CSS to display user info and logout button inline with proper spacing
This commit is contained in:
13
src/App.tsx
13
src/App.tsx
@@ -4,10 +4,9 @@ import { EventStore } from 'applesauce-core'
|
|||||||
import { AccountManager } from 'applesauce-accounts'
|
import { AccountManager } from 'applesauce-accounts'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { createAddressLoader } from 'applesauce-loaders/loaders'
|
import { createAddressLoader } from 'applesauce-loaders/loaders'
|
||||||
import { faRightFromBracket } from '@fortawesome/free-solid-svg-icons'
|
|
||||||
import Login from './components/Login'
|
import Login from './components/Login'
|
||||||
import Bookmarks from './components/Bookmarks'
|
import Bookmarks from './components/Bookmarks'
|
||||||
import IconButton from './components/IconButton'
|
import UserHeader from './components/UserHeader'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [eventStore, setEventStore] = useState<EventStore | null>(null)
|
const [eventStore, setEventStore] = useState<EventStore | null>(null)
|
||||||
@@ -66,15 +65,7 @@ function App() {
|
|||||||
<AccountsProvider manager={accountManager}>
|
<AccountsProvider manager={accountManager}>
|
||||||
<div className="app">
|
<div className="app">
|
||||||
{isAuthenticated && (
|
{isAuthenticated && (
|
||||||
<div className="app-header">
|
<UserHeader onLogout={() => setIsAuthenticated(false)} />
|
||||||
<IconButton
|
|
||||||
icon={faRightFromBracket}
|
|
||||||
onClick={() => setIsAuthenticated(false)}
|
|
||||||
title="Logout"
|
|
||||||
ariaLabel="Logout"
|
|
||||||
variant="ghost"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
{!isAuthenticated ? (
|
{!isAuthenticated ? (
|
||||||
<Login onLogin={() => setIsAuthenticated(true)} />
|
<Login onLogin={() => setIsAuthenticated(true)} />
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faChevronLeft, faChevronRight } from '@fortawesome/free-solid-svg-icons'
|
import { faChevronLeft, faChevronRight } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { Bookmark, ActiveAccount } from '../types/bookmarks'
|
import { Bookmark } from '../types/bookmarks'
|
||||||
import { BookmarkItem } from './BookmarkItem'
|
import { BookmarkItem } from './BookmarkItem'
|
||||||
import { formatDate, renderParsedContent } from '../utils/bookmarkUtils'
|
import { formatDate, renderParsedContent } from '../utils/bookmarkUtils'
|
||||||
|
|
||||||
interface BookmarkListProps {
|
interface BookmarkListProps {
|
||||||
bookmarks: Bookmark[]
|
bookmarks: Bookmark[]
|
||||||
activeAccount: ActiveAccount | null
|
|
||||||
formatUserDisplay: () => string
|
|
||||||
onSelectUrl?: (url: string) => void
|
onSelectUrl?: (url: string) => void
|
||||||
isCollapsed: boolean
|
isCollapsed: boolean
|
||||||
onToggleCollapse: () => void
|
onToggleCollapse: () => void
|
||||||
@@ -16,8 +14,6 @@ interface BookmarkListProps {
|
|||||||
|
|
||||||
export const BookmarkList: React.FC<BookmarkListProps> = ({
|
export const BookmarkList: React.FC<BookmarkListProps> = ({
|
||||||
bookmarks,
|
bookmarks,
|
||||||
activeAccount,
|
|
||||||
formatUserDisplay,
|
|
||||||
onSelectUrl,
|
onSelectUrl,
|
||||||
isCollapsed,
|
isCollapsed,
|
||||||
onToggleCollapse
|
onToggleCollapse
|
||||||
@@ -40,12 +36,6 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className="bookmarks-container">
|
<div className="bookmarks-container">
|
||||||
<div className="bookmarks-header">
|
<div className="bookmarks-header">
|
||||||
<div>
|
|
||||||
{activeAccount && (
|
|
||||||
<p className="user-info">Logged in as: {formatUserDisplay()}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="header-actions">
|
|
||||||
<button
|
<button
|
||||||
onClick={onToggleCollapse}
|
onClick={onToggleCollapse}
|
||||||
className="toggle-sidebar-btn"
|
className="toggle-sidebar-btn"
|
||||||
@@ -55,7 +45,6 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
<FontAwesomeIcon icon={faChevronLeft} />
|
<FontAwesomeIcon icon={faChevronLeft} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{bookmarks.length === 0 ? (
|
{bookmarks.length === 0 ? (
|
||||||
<div className="empty-state">
|
<div className="empty-state">
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { Hooks } from 'applesauce-react'
|
import { Hooks } from 'applesauce-react'
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
|
||||||
import { Models } from 'applesauce-core'
|
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { Bookmark } from '../types/bookmarks'
|
import { Bookmark } from '../types/bookmarks'
|
||||||
import { BookmarkList } from './BookmarkList'
|
import { BookmarkList } from './BookmarkList'
|
||||||
@@ -23,9 +21,6 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool }) => {
|
|||||||
const activeAccount = Hooks.useActiveAccount()
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
const accountManager = Hooks.useAccountManager()
|
const accountManager = Hooks.useAccountManager()
|
||||||
|
|
||||||
// Use ProfileModel to get user profile information
|
|
||||||
const profile = useEventModel(Models.ProfileModel, activeAccount ? [activeAccount.pubkey] : null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('Bookmarks useEffect triggered')
|
console.log('Bookmarks useEffect triggered')
|
||||||
console.log('relayPool:', !!relayPool)
|
console.log('relayPool:', !!relayPool)
|
||||||
@@ -72,38 +67,9 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool }) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const formatUserDisplay = () => {
|
|
||||||
if (!activeAccount) return 'Unknown User'
|
|
||||||
|
|
||||||
// Debug profile loading
|
|
||||||
console.log('Profile data:', profile)
|
|
||||||
console.log('Active account pubkey:', activeAccount.pubkey)
|
|
||||||
|
|
||||||
// Use profile data from ProfileModel if available
|
|
||||||
if (profile?.name) {
|
|
||||||
return profile.name
|
|
||||||
}
|
|
||||||
if (profile?.display_name) {
|
|
||||||
return profile.display_name
|
|
||||||
}
|
|
||||||
if (profile?.nip05) {
|
|
||||||
return profile.nip05
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to formatted public key to avoid sticky loading text
|
|
||||||
return `${activeAccount.pubkey.slice(0, 8)}...${activeAccount.pubkey.slice(-8)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className="bookmarks-container">
|
<div className="bookmarks-container">
|
||||||
<div className="bookmarks-header">
|
|
||||||
<div>
|
|
||||||
{activeAccount && (
|
|
||||||
<p className="user-info">Logged in as: {formatUserDisplay()}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="loading">Loading bookmarks...</div>
|
<div className="loading">Loading bookmarks...</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -114,8 +80,6 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool }) => {
|
|||||||
<div className="pane sidebar">
|
<div className="pane sidebar">
|
||||||
<BookmarkList
|
<BookmarkList
|
||||||
bookmarks={bookmarks}
|
bookmarks={bookmarks}
|
||||||
activeAccount={activeAccount || null}
|
|
||||||
formatUserDisplay={formatUserDisplay}
|
|
||||||
onSelectUrl={handleSelectUrl}
|
onSelectUrl={handleSelectUrl}
|
||||||
isCollapsed={isCollapsed}
|
isCollapsed={isCollapsed}
|
||||||
onToggleCollapse={() => setIsCollapsed(!isCollapsed)}
|
onToggleCollapse={() => setIsCollapsed(!isCollapsed)}
|
||||||
|
|||||||
47
src/components/UserHeader.tsx
Normal file
47
src/components/UserHeader.tsx
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Hooks } from 'applesauce-react'
|
||||||
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
|
import { Models } from 'applesauce-core'
|
||||||
|
import { faRightFromBracket } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import IconButton from './IconButton'
|
||||||
|
|
||||||
|
interface UserHeaderProps {
|
||||||
|
onLogout: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const UserHeader: React.FC<UserHeaderProps> = ({ onLogout }) => {
|
||||||
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
|
const profile = useEventModel(Models.ProfileModel, activeAccount ? [activeAccount.pubkey] : null)
|
||||||
|
|
||||||
|
const formatUserDisplay = () => {
|
||||||
|
if (!activeAccount) return 'Unknown User'
|
||||||
|
|
||||||
|
if (profile?.name) {
|
||||||
|
return profile.name
|
||||||
|
}
|
||||||
|
if (profile?.display_name) {
|
||||||
|
return profile.display_name
|
||||||
|
}
|
||||||
|
if (profile?.nip05) {
|
||||||
|
return profile.nip05
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${activeAccount.pubkey.slice(0, 8)}...${activeAccount.pubkey.slice(-8)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="app-header">
|
||||||
|
<p className="user-info">Logged in as: {formatUserDisplay()}</p>
|
||||||
|
<IconButton
|
||||||
|
icon={faRightFromBracket}
|
||||||
|
onClick={onLogout}
|
||||||
|
title="Logout"
|
||||||
|
ariaLabel="Logout"
|
||||||
|
variant="ghost"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UserHeader
|
||||||
|
|
||||||
@@ -36,6 +36,13 @@ body {
|
|||||||
top: 1rem;
|
top: 1rem;
|
||||||
right: 2rem;
|
right: 2rem;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header .user-info {
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app header {
|
.app header {
|
||||||
@@ -107,28 +114,13 @@ body {
|
|||||||
|
|
||||||
.bookmarks-header {
|
.bookmarks-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: flex-start;
|
||||||
align-items: flex-start;
|
align-items: center;
|
||||||
margin-bottom: 2rem;
|
margin-bottom: 1rem;
|
||||||
padding-bottom: 1rem;
|
padding-bottom: 1rem;
|
||||||
border-bottom: 1px solid #333;
|
border-bottom: 1px solid #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bookmarks-header > div {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bookmarks-header h2 {
|
|
||||||
margin: 0;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-actions {
|
|
||||||
display: flex;
|
|
||||||
gap: 0.5rem;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.toggle-sidebar-btn {
|
.toggle-sidebar-btn {
|
||||||
background: #2a2a2a;
|
background: #2a2a2a;
|
||||||
color: #ddd;
|
color: #ddd;
|
||||||
|
|||||||
Reference in New Issue
Block a user