在context中新增selectedCategory
This commit is contained in:
parent
ca74829c2d
commit
e902920669
|
|
@ -4,16 +4,16 @@ import { useHomeContext } from './context/homeContext';
|
|||
import EssaysByLabel from './essays/byLabel';
|
||||
|
||||
const FrontendBody = () => {
|
||||
const { selectedTagId } = useHomeContext();
|
||||
const { selectedLabelId } = useHomeContext();
|
||||
|
||||
return (
|
||||
<div>
|
||||
{!selectedTagId ? (
|
||||
{!selectedLabelId ? (
|
||||
<Essays oakPath='essays'></Essays>
|
||||
) : (
|
||||
<EssaysByLabel
|
||||
oakPath='essaysByLabel'
|
||||
oakId={selectedTagId!}
|
||||
oakId={selectedLabelId!}
|
||||
></EssaysByLabel>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@ import React from 'react';
|
|||
import { createContext } from 'react';
|
||||
|
||||
type HomeContextType = {
|
||||
selectedTagId: string | undefined;
|
||||
setSelectedTagId: (tagId: string | null) => void;
|
||||
// label selection
|
||||
selectedLabelId: string | undefined;
|
||||
setSelectedLabelId: (tagId: string | null) => void;
|
||||
// category selection
|
||||
selectedCategoryId: string | undefined;
|
||||
setSelectedCategoryId: (categoryId: string | null) => void;
|
||||
};
|
||||
|
||||
const HomeContext = createContext<HomeContextType | undefined>(undefined);
|
||||
|
|
@ -11,15 +15,24 @@ const HomeContext = createContext<HomeContextType | undefined>(undefined);
|
|||
export const HomeProvider: React.FC<{
|
||||
children: React.ReactNode;
|
||||
}> = ({ children }) => {
|
||||
const [selectedTagId, _setSelectedTagId] = React.useState<string>();
|
||||
const setSelectedTagId = (tagId: string | null) => {
|
||||
_setSelectedTagId(tagId || undefined);
|
||||
const [selectedLabelId, _setSelectedLabelId] = React.useState<string>();
|
||||
const setSelectedLabelId = (tagId: string | null) => {
|
||||
_setSelectedLabelId(tagId || undefined);
|
||||
};
|
||||
|
||||
const [selectedCategoryId, _setSelectedCategoryId] =
|
||||
React.useState<string>();
|
||||
const setSelectedCategoryId = (categoryId: string | null) => {
|
||||
_setSelectedCategoryId(categoryId || undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
<HomeContext.Provider
|
||||
value={{
|
||||
selectedTagId,
|
||||
setSelectedTagId,
|
||||
selectedLabelId,
|
||||
setSelectedLabelId,
|
||||
selectedCategoryId,
|
||||
setSelectedCategoryId,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const LabelList = (
|
|||
const { list, oakFullpath, labelClassName } = props.data;
|
||||
const { t } = props.methods;
|
||||
|
||||
const { selectedTagId, setSelectedTagId } = useHomeContext();
|
||||
const { selectedLabelId, setSelectedLabelId } = useHomeContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
@ -35,15 +35,15 @@ const LabelList = (
|
|||
labelClassName={`${labelClassName}`}
|
||||
labelStyle={{
|
||||
border:
|
||||
selectedTagId === item.id
|
||||
selectedLabelId === item.id
|
||||
? '2px solid #000'
|
||||
: '2px solid #fff',
|
||||
}}
|
||||
onClick={() => {
|
||||
if (selectedTagId === item.id) {
|
||||
setSelectedTagId(null);
|
||||
if (selectedLabelId === item.id) {
|
||||
setSelectedLabelId(null);
|
||||
} else {
|
||||
setSelectedTagId(item.id!);
|
||||
setSelectedLabelId(item.id!);
|
||||
}
|
||||
}}
|
||||
key={item.id}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ const i18ns: I18n[] = [
|
|||
"summary": "文章摘要",
|
||||
"author": "作者",
|
||||
"action": {
|
||||
"updateLabels": "修改标签",
|
||||
"createLabels": "新建标签"
|
||||
"setting": "设置"
|
||||
},
|
||||
"label": {
|
||||
"selectLabels": "选择标签"
|
||||
|
|
@ -35,7 +34,8 @@ const i18ns: I18n[] = [
|
|||
"essay": {
|
||||
"isTop": "已置顶",
|
||||
"notTop": "未置顶"
|
||||
}
|
||||
},
|
||||
"cover": "封面"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -126,6 +126,17 @@ const i18ns: I18n[] = [
|
|||
"userLogin": "用户登录"
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "803dd2892be9bb5973f8da5b83a35bc1",
|
||||
namespace: "new-demo-c-console-category-selector",
|
||||
language: "zh-CN",
|
||||
module: "new-demo",
|
||||
position: "src/components/console/category/selector",
|
||||
data: {
|
||||
"placeholder": "请选择分类",
|
||||
"blank": "无分类"
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "592037eadc9833a3b3307d6881daf2fb",
|
||||
namespace: "new-demo-c-console-essay-editor",
|
||||
|
|
@ -137,7 +148,8 @@ const i18ns: I18n[] = [
|
|||
"error": {
|
||||
"titleCannotBeEmpty": "文章标题不能为空",
|
||||
"contentCannotBeEmpty": "文章内容不能为空"
|
||||
}
|
||||
},
|
||||
"setting": "设置"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue