mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(frontend): gate WorkshopScreen edit UI on OAuth login match
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState, useMemo, type ReactNode } from 'react'
|
|||||||
import DOMPurify from 'dompurify'
|
import DOMPurify from 'dompurify'
|
||||||
import type { WidgetSettings, Achievement, PerWidgetSettings } from '../App'
|
import type { WidgetSettings, Achievement, PerWidgetSettings } from '../App'
|
||||||
import { renderAllWidgets, type WidgetData } from '../lib/renderWidgets'
|
import { renderAllWidgets, type WidgetData } from '../lib/renderWidgets'
|
||||||
|
import { signInUrl } from '../lib/auth'
|
||||||
import type { Me } from '../lib/auth'
|
import type { Me } from '../lib/auth'
|
||||||
|
|
||||||
// Defense-in-depth: the client-rendered preview assembles SVG from
|
// Defense-in-depth: the client-rendered preview assembles SVG from
|
||||||
@@ -228,7 +229,9 @@ export function WorkshopScreen({
|
|||||||
fetchDone,
|
fetchDone,
|
||||||
fetchError,
|
fetchError,
|
||||||
widgetData,
|
widgetData,
|
||||||
|
me,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const canEdit = !!me.login && me.login.toLowerCase() === username.toLowerCase()
|
||||||
const [expandedWidget, setExpandedWidget] = useState<string | null>(null)
|
const [expandedWidget, setExpandedWidget] = useState<string | null>(null)
|
||||||
|
|
||||||
const updateSetting = <K extends keyof WidgetSettings>(key: K, val: WidgetSettings[K]) => {
|
const updateSetting = <K extends keyof WidgetSettings>(key: K, val: WidgetSettings[K]) => {
|
||||||
@@ -315,6 +318,17 @@ export function WorkshopScreen({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!canEdit && (
|
||||||
|
<div className="banner">
|
||||||
|
{me.login
|
||||||
|
? `Signed in as ${me.login}. You can only edit your own widget.`
|
||||||
|
: <a href={signInUrl()}>Sign in with GitHub to edit your widget</a>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Theme, Widgets, Achievements editor, Generate — owner-only */}
|
||||||
|
{canEdit && (
|
||||||
|
<>
|
||||||
{/* Theme */}
|
{/* Theme */}
|
||||||
<div className="mb-5">
|
<div className="mb-5">
|
||||||
<div className="text-[10px] uppercase tracking-wider text-gray-400 font-medium mb-3">Theme</div>
|
<div className="text-[10px] uppercase tracking-wider text-gray-400 font-medium mb-3">Theme</div>
|
||||||
@@ -542,6 +556,8 @@ export function WorkshopScreen({
|
|||||||
>
|
>
|
||||||
Generate →
|
Generate →
|
||||||
</button>
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right preview area */}
|
{/* Right preview area */}
|
||||||
|
|||||||
Reference in New Issue
Block a user