diff --git a/components/ProfileSeriesBlock.tsx b/components/ProfileSeriesBlock.tsx index 52aa399..194d3df 100644 --- a/components/ProfileSeriesBlock.tsx +++ b/components/ProfileSeriesBlock.tsx @@ -1,5 +1,9 @@ +import { useState } from 'react' import Link from 'next/link' import { SeriesSection } from './SeriesSection' +import { CreateSeriesModal } from './CreateSeriesModal' +import { useNostrAuth } from '@/hooks/useNostrAuth' +import { t } from '@/lib/i18n' interface ProfileSeriesBlockProps { currentPubkey: string @@ -8,12 +12,22 @@ interface ProfileSeriesBlockProps { } export function ProfileSeriesBlock({ currentPubkey, onSelectSeries, selectedSeriesId }: ProfileSeriesBlockProps): React.ReactElement { + const { pubkey, isUnlocked } = useNostrAuth() + const [showCreateModal, setShowCreateModal] = useState(false) + const [refreshKey, setRefreshKey] = useState(0) + const isAuthor = pubkey === currentPubkey && isUnlocked + + const handleSeriesCreated = (): void => { + setRefreshKey((prev) => prev + 1) + } + return (
-

Séries

+ setShowCreateModal(true)} /> {selectedSeriesId && ( @@ -23,6 +37,31 @@ export function ProfileSeriesBlock({ currentPubkey, onSelectSeries, selectedSeri
)} + { + setShowCreateModal(false) + }} + onSuccess={handleSeriesCreated} + authorPubkey={currentPubkey} + /> + + ) +} + +function ProfileSeriesHeader({ isAuthor, onCreate }: { isAuthor: boolean; onCreate: () => void }): React.ReactElement { + return ( +
+

Séries

+ {isAuthor && ( + + )}
) } diff --git a/components/SeriesSection.tsx b/components/SeriesSection.tsx index 5560a96..b0f9249 100644 --- a/components/SeriesSection.tsx +++ b/components/SeriesSection.tsx @@ -9,10 +9,11 @@ interface SeriesSectionProps { authorPubkey: string onSelect: (seriesId: string | undefined) => void selectedId?: string | undefined + refreshKey?: number | undefined } -export function SeriesSection({ authorPubkey, onSelect, selectedId }: SeriesSectionProps): React.ReactElement { - const [{ series, loading, error, aggregates }, load] = useSeriesData(authorPubkey) +export function SeriesSection({ authorPubkey, onSelect, selectedId, refreshKey }: SeriesSectionProps): React.ReactElement { + const [{ series, loading, error, aggregates }, load] = useSeriesData(authorPubkey, refreshKey) if (loading) { return

Chargement des séries...

@@ -83,7 +84,7 @@ function SeriesAggregatesList({ ) } -function useSeriesData(authorPubkey: string): [ +function useSeriesData(authorPubkey: string, refreshKey?: number | undefined): [ { series: Series[] loading: boolean @@ -113,7 +114,7 @@ function useSeriesData(authorPubkey: string): [ useEffect(() => { void load() - }, [load]) + }, [load, refreshKey]) return [{ series, loading, error, aggregates }, load] }