/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useMemo, useState } from 'react';
import Joyride, { EVENTS, STATUS } from 'react-joyride';
import { useTranslation } from 'react-i18next';
// 首次引导(WP C-4,方案 §4.4):3 步轻引导(写描述 → 选模型 → 生成),复用秘钥管理页
// 已有的新手引导能力(react-joyride)。每种创作页只展示一次(localStorage)。
export const guideStorageKeyOf = (kind) => `creation.${kind}.guide.v1`;
const readSeen = (kind) => {
try {
return window.localStorage.getItem(guideStorageKeyOf(kind)) === '1';
} catch (e) {
// 存储不可用时不展示,避免每次进入都弹
return true;
}
};
const writeSeen = (kind) => {
try {
window.localStorage.setItem(guideStorageKeyOf(kind), '1');
} catch (e) {
// ignore
}
};
// 引导目标:收起态 / 展开态都带 data-guide;模型选择器为创作台内的触发 chip
const TARGETS = {
prompt: '.cs-dock-wrap [data-guide="prompt"]',
model: '.cs-dock-wrap .mp-trigger',
generate: '.cs-dock-wrap [data-guide="generate"]',
};
const StepBody = ({ index, title, text }) => (
);
/**
* @param {{ kind: 'image'|'video', ready: boolean }} props
* ready:模型列表已加载、创作台已渲染(引导目标存在)时才开始
*/
const CreationGuide = ({ kind, ready }) => {
const { t } = useTranslation();
const [run, setRun] = useState(false);
useEffect(() => {
if (!ready || readSeen(kind)) return undefined;
// 等创作台布局稳定(展开 / 收起态判定、字体加载)后再开始
const timer = setTimeout(() => setRun(true), 800);
return () => clearTimeout(timer);
}, [ready, kind]);
const steps = useMemo(
() => [
{
target: TARGETS.prompt,
disableBeacon: true,
placement: 'top',
content: (
),
},
{
target: TARGETS.model,
placement: 'top',
content: (
),
},
{
target: TARGETS.generate,
placement: 'top',
content: (
),
},
],
[kind, t],
);
const handleCallback = ({ status, type }) => {
if (
status === STATUS.FINISHED ||
status === STATUS.SKIPPED ||
type === EVENTS.TOUR_END
) {
writeSeen(kind);
setRun(false);
}
// 目标不存在(如移动端收起态布局变化):直接结束,不再打扰
if (type === EVENTS.TARGET_NOT_FOUND) {
writeSeen(kind);
setRun(false);
}
};
if (!run) return null;
return (
);
};
export default CreationGuide;