mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
Merge pull request #48 from dergigi/profile-three-dot-menu
Add three-dot menu to profile view
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect, useCallback, useMemo } from 'react'
|
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faHighlighter, faPenToSquare } from '@fortawesome/free-solid-svg-icons'
|
import { faHighlighter, faPenToSquare, faEllipsisH, faCopy, faShare, faExternalLinkAlt, faMobileAlt } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
@@ -9,6 +9,7 @@ import { HighlightItem } from './HighlightItem'
|
|||||||
import { BlogPostPreview } from '../services/exploreService'
|
import { BlogPostPreview } from '../services/exploreService'
|
||||||
import { KINDS } from '../config/kinds'
|
import { KINDS } from '../config/kinds'
|
||||||
import AuthorCard from './AuthorCard'
|
import AuthorCard from './AuthorCard'
|
||||||
|
import CompactButton from './CompactButton'
|
||||||
import BlogPostCard from './BlogPostCard'
|
import BlogPostCard from './BlogPostCard'
|
||||||
import { BlogPostSkeleton, HighlightSkeleton } from './Skeletons'
|
import { BlogPostSkeleton, HighlightSkeleton } from './Skeletons'
|
||||||
import { useStoreTimeline } from '../hooks/useStoreTimeline'
|
import { useStoreTimeline } from '../hooks/useStoreTimeline'
|
||||||
@@ -20,6 +21,7 @@ import { Hooks } from 'applesauce-react'
|
|||||||
import { readingProgressController } from '../services/readingProgressController'
|
import { readingProgressController } from '../services/readingProgressController'
|
||||||
import { writingsController } from '../services/writingsController'
|
import { writingsController } from '../services/writingsController'
|
||||||
import { highlightsController } from '../services/highlightsController'
|
import { highlightsController } from '../services/highlightsController'
|
||||||
|
import { getProfileUrl } from '../config/nostrGateways'
|
||||||
|
|
||||||
interface ProfileProps {
|
interface ProfileProps {
|
||||||
relayPool: RelayPool
|
relayPool: RelayPool
|
||||||
@@ -38,6 +40,8 @@ const Profile: React.FC<ProfileProps> = ({
|
|||||||
const activeAccount = Hooks.useActiveAccount()
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
const [activeTab, setActiveTab] = useState<'highlights' | 'writings'>(propActiveTab || 'highlights')
|
const [activeTab, setActiveTab] = useState<'highlights' | 'writings'>(propActiveTab || 'highlights')
|
||||||
const [refreshTrigger, setRefreshTrigger] = useState(0)
|
const [refreshTrigger, setRefreshTrigger] = useState(0)
|
||||||
|
const [showProfileMenu, setShowProfileMenu] = useState(false)
|
||||||
|
const profileMenuRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
// Reading progress state (naddr -> progress 0-1)
|
// Reading progress state (naddr -> progress 0-1)
|
||||||
const [readingProgressMap, setReadingProgressMap] = useState<Map<string, number>>(new Map())
|
const [readingProgressMap, setReadingProgressMap] = useState<Map<string, number>>(new Map())
|
||||||
@@ -168,6 +172,68 @@ const Profile: React.FC<ProfileProps> = ({
|
|||||||
const npub = nip19.npubEncode(pubkey)
|
const npub = nip19.npubEncode(pubkey)
|
||||||
const showSkeletons = cachedHighlights.length === 0 && sortedWritings.length === 0
|
const showSkeletons = cachedHighlights.length === 0 && sortedWritings.length === 0
|
||||||
|
|
||||||
|
// Close menu when clicking outside
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (profileMenuRef.current && !profileMenuRef.current.contains(event.target as Node)) {
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showProfileMenu) {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside)
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside)
|
||||||
|
}
|
||||||
|
}, [showProfileMenu])
|
||||||
|
|
||||||
|
// Profile menu handlers
|
||||||
|
const handleMenuToggle = () => {
|
||||||
|
setShowProfileMenu(!showProfileMenu)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCopyProfileLink = async () => {
|
||||||
|
try {
|
||||||
|
const borisUrl = `${window.location.origin}/p/${npub}`
|
||||||
|
await navigator.clipboard.writeText(borisUrl)
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Copy failed', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleShareProfile = async () => {
|
||||||
|
try {
|
||||||
|
const borisUrl = `${window.location.origin}/p/${npub}`
|
||||||
|
if ((navigator as { share?: (d: { title?: string; url?: string }) => Promise<void> }).share) {
|
||||||
|
await (navigator as { share: (d: { title?: string; url?: string }) => Promise<void> }).share({
|
||||||
|
title: 'Profile',
|
||||||
|
url: borisUrl
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await navigator.clipboard.writeText(borisUrl)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Share failed', e)
|
||||||
|
} finally {
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenPortal = () => {
|
||||||
|
const portalUrl = getProfileUrl(npub)
|
||||||
|
window.open(portalUrl, '_blank', 'noopener,noreferrer')
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenNative = () => {
|
||||||
|
const nativeUrl = `nostr:${npub}`
|
||||||
|
window.location.href = nativeUrl
|
||||||
|
setShowProfileMenu(false)
|
||||||
|
}
|
||||||
|
|
||||||
const renderTabContent = () => {
|
const renderTabContent = () => {
|
||||||
switch (activeTab) {
|
switch (activeTab) {
|
||||||
case 'highlights':
|
case 'highlights':
|
||||||
@@ -236,7 +302,51 @@ const Profile: React.FC<ProfileProps> = ({
|
|||||||
pullPosition={pullPosition}
|
pullPosition={pullPosition}
|
||||||
/>
|
/>
|
||||||
<div className="explore-header">
|
<div className="explore-header">
|
||||||
|
<div className="profile-header-wrapper">
|
||||||
|
<div className="profile-card-with-menu">
|
||||||
<AuthorCard authorPubkey={pubkey} clickable={false} />
|
<AuthorCard authorPubkey={pubkey} clickable={false} />
|
||||||
|
<div className="profile-card-menu-wrapper" ref={profileMenuRef}>
|
||||||
|
<CompactButton
|
||||||
|
icon={faEllipsisH}
|
||||||
|
onClick={handleMenuToggle}
|
||||||
|
title="More options"
|
||||||
|
ariaLabel="Profile menu"
|
||||||
|
/>
|
||||||
|
{showProfileMenu && (
|
||||||
|
<div className="profile-card-menu">
|
||||||
|
<button
|
||||||
|
className="profile-card-menu-item"
|
||||||
|
onClick={handleCopyProfileLink}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faCopy} />
|
||||||
|
<span>Copy Link</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-card-menu-item"
|
||||||
|
onClick={handleShareProfile}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faShare} />
|
||||||
|
<span>Share</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-card-menu-item"
|
||||||
|
onClick={handleOpenPortal}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
||||||
|
<span>Open with njump</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="profile-card-menu-item"
|
||||||
|
onClick={handleOpenNative}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faMobileAlt} />
|
||||||
|
<span>Open with Native App</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="me-tabs">
|
<div className="me-tabs">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -73,7 +73,8 @@
|
|||||||
|
|
||||||
/* Align highlight list width with profile card width on /my */
|
/* Align highlight list width with profile card width on /my */
|
||||||
.me-highlights-list { padding-left: 0; padding-right: 0; }
|
.me-highlights-list { padding-left: 0; padding-right: 0; }
|
||||||
.explore-header .author-card { max-width: 600px; margin: 0 auto; width: 100%; }
|
.explore-header .profile-header-wrapper { max-width: 600px; margin: 0 auto; width: 100%; }
|
||||||
|
.explore-header .author-card { max-width: none; margin: 0; width: auto; flex: 1; }
|
||||||
|
|
||||||
/* Hide tab labels on mobile to save space */
|
/* Hide tab labels on mobile to save space */
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
|
|||||||
@@ -10,6 +10,71 @@
|
|||||||
.author-card-name { font-size: 1rem; font-weight: 600; color: var(--color-text); margin-bottom: 0.5rem; text-align: left; }
|
.author-card-name { font-size: 1rem; font-weight: 600; color: var(--color-text); margin-bottom: 0.5rem; text-align: left; }
|
||||||
.author-card-bio { font-size: 0.9rem; color: var(--color-text-secondary); line-height: 1.5; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; text-align: left; }
|
.author-card-bio { font-size: 0.9rem; color: var(--color-text-secondary); line-height: 1.5; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; text-align: left; }
|
||||||
|
|
||||||
|
/* Profile header */
|
||||||
|
.profile-header-wrapper {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2rem 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove horizontal padding when inside explore-header to match tabs width */
|
||||||
|
.explore-header .profile-header-wrapper {
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card-with-menu {
|
||||||
|
position: relative;
|
||||||
|
max-width: 600px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Profile card menu - inside card, bottom-right */
|
||||||
|
.profile-card-menu-wrapper {
|
||||||
|
position: absolute;
|
||||||
|
right: 1.25rem;
|
||||||
|
top: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card-menu {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: calc(100% + 4px);
|
||||||
|
background: var(--color-bg-elevated);
|
||||||
|
border: 1px solid var(--color-border-subtle);
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||||
|
z-index: 1000;
|
||||||
|
min-width: 180px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card-menu-item {
|
||||||
|
width: 100%;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: var(--color-text);
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
text-align: left;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card-menu-item:hover {
|
||||||
|
background: rgba(99, 102, 241, 0.15);
|
||||||
|
color: var(--color-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card-menu-item svg {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.author-card-container {
|
.author-card-container {
|
||||||
padding: 1.5rem 1rem;
|
padding: 1.5rem 1rem;
|
||||||
@@ -26,5 +91,13 @@
|
|||||||
.author-card-avatar svg { font-size: 2rem; }
|
.author-card-avatar svg { font-size: 2rem; }
|
||||||
.author-card-name { font-size: 0.95rem; }
|
.author-card-name { font-size: 0.95rem; }
|
||||||
.author-card-bio { font-size: 0.85rem; -webkit-line-clamp: 2; }
|
.author-card-bio { font-size: 0.85rem; -webkit-line-clamp: 2; }
|
||||||
}
|
|
||||||
|
|
||||||
|
.profile-header-wrapper {
|
||||||
|
padding-top: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card-menu-wrapper {
|
||||||
|
right: 1rem;
|
||||||
|
top: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user