feat: ️ 新增推送视频状态控制及国际化支持,优化热点新闻数据加载逻辑

This commit is contained in:
LittleBoy 2025-04-07 23:24:53 +08:00
parent 64ee960846
commit 500c849140
2 changed files with 19 additions and 11 deletions

View File

@ -15,6 +15,7 @@ type Props = {
id?: number;
type: 'news' | 'video';
onClose?: (saved?: boolean) => void;
onRefresh?: ()=>void
}
const DEFAULT_STATE = {
@ -106,7 +107,7 @@ function checkHotNewsValid(hotNews: HotNewsData,modal:ModalHookAPI,t:TFunction<"
}
export default function ArticleEditModal(props: Props) {
const {t} = useTranslation()
const {t,i18n} = useTranslation()
const {modal} = App.useApp()
const [groups, setGroups] = useState<BlockContent[][]>([]);
const [title, setTitle] = useState('')
@ -116,7 +117,8 @@ export default function ArticleEditModal(props: Props) {
})
const [state, setState] = useSetState({
...DEFAULT_STATE,
generating:false
generating:false,
pushed: false,
})
// 保存数据
@ -159,7 +161,7 @@ export default function ArticleEditModal(props: Props) {
});
}
const handlePush2Video = async () =>{
//
if(state.pushed) return;
if (!title) {
// setState({msgTitle: '请输入标题内容'});
return;
@ -187,6 +189,9 @@ export default function ArticleEditModal(props: Props) {
})
push2video([props.id]).then(() => {
showToast(t('news.push_stream_success'), 'success')
setState({pushed:true})
props.onClose?.(true)
// props.onRefresh?.();
// navigate('/create?state=push-success',{
// state: 'push-success'
// })
@ -201,13 +206,15 @@ export default function ArticleEditModal(props: Props) {
// 如果传入了id则获取数据
if (props.id > 0) {
article.getById(props.id).then(res => {
const len = res.hot_news.length
const list = len >= 3 ? res.hot_news :res.hot_news.concat(Array(3 - len).fill(''))
const mode = res.hot_news && res.hot_news.filter(s=>s.length > 0).length == 3 ?'manual':'auto';
setHotNews({
list,
mode
})
if(res.hot_news){
const len = res.hot_news.length
const list = len >= 3 ? res.hot_news :res.hot_news.concat(Array(3 - len).fill(''))
const mode = res.hot_news && res.hot_news.filter(s=>s.length > 0).length == 3 ?'manual':'auto';
setHotNews({
list,
mode
})
}
setGroups(rebuildGroups([[{content: res.metahuman_text, type: "text"}], ...res.content_group]))
setTitle(res.title)
})
@ -260,7 +267,7 @@ export default function ArticleEditModal(props: Props) {
</div>
<div className="modal-control-footer flex justify-end">
<div className="flex gap-10 ">
{props.type == 'news' && props.id ? <button className="text-gray-400 hover:text-gray-800" onClick={handlePush2Video}>{t('news.edit_generate_video')}{state.generating?'推送中...':''}</button> : null}
{props.type == 'news' && props.id ? <button className="text-gray-400 hover:text-gray-800" onClick={handlePush2Video}>{t('news.edit_generate_video')}{state.pushed?`${i18n.language == 'zh-CN'?'中':''}...`:(state.generating?`${i18n.language == 'zh-CN'?'推送中':'Pushing'}...`:'')}</button> : null}
<button className="text-gray-400 hover:text-gray-800" onClick={() => props.onClose?.()}>{t('cancel')}</button>
<button onClick={handleSave} className="text-gray-800 hover:text-blue-500">{props.type == 'news' ? t('confirm_text') : t('news.edit_generate_again')}</button>
</div>

View File

@ -179,6 +179,7 @@ export default function NewEdit() {
<ArticleEditModal
type="news"
id={editId}
onRefresh={refresh}
onClose={(saved) => {
setEditId(-1)
if (saved) refresh()