mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem Launch Week 16 is promoted on www but needs the same promotion in hosted Studio. ## Solution Add a low-priority card to the existing bottom-right Banner Stack across project, organisation, and account pages. It uses the shared dot artwork from #54511, links to the Launch Week site, saves dismissal, and expires after December 11 in San Francisco. Signed-out and self-hosted Studio do not show it. | After | | --- | | <img width="995" height="584" alt="1211" src="https://github.com/user-attachments/assets/ff1a60a3-6a4e-4b32-a3df-7fdfe74f4afb" /> | | <img width="995" height="584" alt="68318" src="https://github.com/user-attachments/assets/3a41c56a-fe59-4800-ae14-82ec42c6f260" /> | ## Review instructions 1. Open a hosted project, organisation, or account page on the Studio preview. If another notice is in front, expand the Banner Stack to find **Launch Week 16**. 2. Check the artwork, copy, and **Claim your ticket** button in light and dark mode. The button opens the Launch Week site in a new tab and dismisses the card. 3. Close the card and reload. It should stay dismissed.
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'
|
|
|
|
export const BANNER_ID = {
|
|
INDEX_ADVISOR: 'index-advisor-banner',
|
|
TABLE_EDITOR_QUEUE_OPERATIONS: 'table-editor-queue-operations-banner',
|
|
RLS_EVENT_TRIGGER: 'rls-event-trigger-banner',
|
|
FREE_MICRO_UPGRADE: 'free-micro-upgrade-banner',
|
|
EXPLORER: 'explorer-banner',
|
|
STORAGE_VERSIONING: 'storage-versioning-banner',
|
|
ONBOARDING_SURVEY_FOLLOW_UP: 'onboarding-survey-follow-up-banner',
|
|
LAUNCH_WEEK_16: 'launch-week-16-banner',
|
|
} as const
|
|
|
|
export type BannerId = (typeof BANNER_ID)[keyof typeof BANNER_ID]
|
|
|
|
export interface Banner {
|
|
id: BannerId
|
|
content: React.ReactNode
|
|
isDismissed: boolean
|
|
priority?: number
|
|
onDismiss?: () => void
|
|
}
|
|
|
|
interface BannerStackContextType {
|
|
banners: Banner[]
|
|
addBanner: (banner: Banner) => void
|
|
dismissBanner: (id: BannerId) => void
|
|
}
|
|
|
|
const BannerStackContext = createContext<BannerStackContextType | undefined>(undefined)
|
|
|
|
export const BannerStackProvider = ({ children }: { children: React.ReactNode }) => {
|
|
const [banners, setBanners] = useState<Banner[]>([])
|
|
const removalTimeouts = useRef(new Set<ReturnType<typeof setTimeout>>())
|
|
|
|
useEffect(() => {
|
|
const timeouts = removalTimeouts.current
|
|
return () => {
|
|
timeouts.forEach(clearTimeout)
|
|
timeouts.clear()
|
|
}
|
|
}, [])
|
|
|
|
const addBanner = useCallback((banner: Banner) => {
|
|
setBanners((prev) => {
|
|
const existingIndex = prev.findIndex((b) => b.id === banner.id)
|
|
if (existingIndex !== -1) {
|
|
if (!prev[existingIndex].isDismissed) return prev
|
|
const revived = [...prev]
|
|
revived[existingIndex] = banner
|
|
return revived.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
|
}
|
|
const newBanners = [...prev, banner]
|
|
return newBanners.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
|
})
|
|
}, [])
|
|
|
|
const dismissBanner = useCallback((id: string) => {
|
|
setBanners((prev) => prev.map((b) => (b.id === id ? { ...b, isDismissed: true } : b)))
|
|
const timeout = setTimeout(() => {
|
|
removalTimeouts.current.delete(timeout)
|
|
// A later addBanner can revive this id before the exit animation
|
|
// finishes. Drop it only if it is still dismissed.
|
|
setBanners((prev) => prev.filter((b) => b.id !== id || !b.isDismissed))
|
|
}, 300)
|
|
removalTimeouts.current.add(timeout)
|
|
}, [])
|
|
|
|
return (
|
|
<BannerStackContext.Provider value={{ banners, addBanner, dismissBanner }}>
|
|
{children}
|
|
</BannerStackContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const useBannerStack = () => {
|
|
const context = useContext(BannerStackContext)
|
|
if (!context) throw new Error('useBannerStack must be used within BannerStackProvider')
|
|
return context
|
|
}
|