Like for遍历改some essay top字段改成state

This commit is contained in:
wangtianqi 2024-10-31 16:25:54 +08:00
parent bb3f949a4a
commit 3577c45295
11 changed files with 54 additions and 42 deletions

View File

@ -14,7 +14,7 @@ const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
$or: [{ iState: 'unpublished' }, { iState: 'withdrawn' }],
},
},
// settop的时候只能是isTop为false的
/* // settop的时候只能是isTop为false的
{
entity: 'essay',
action: 'setTop',
@ -31,7 +31,7 @@ const checkers: Checker<EntityDict, 'essay', RuntimeCxt>[] = [
filter: {
isTop: true,
},
},
}, */
// 在删除essay的时候同步删除extraFile和essayLabels还有log
// 注意在checker中为非异步环境这点与trigger不同
{

View File

@ -9,7 +9,7 @@ export default OakComponent({
// 先按置顶排序
sorter: {
$attr: {
isTop: 1,
topState: 1,
},
$direction: 'desc',
},

View File

@ -46,7 +46,7 @@ const EssayItem = (props: {
</div>
<div className={Styles.body}>
<div className={Styles.title}>
{item.isTop && (
{item.topState === 'top' && (
<div className={Styles.top}>
{t('common::top')}
</div>

View File

@ -654,8 +654,7 @@ const i18ns: I18n[] = [
"images": "图片",
"logs": "修改记录",
"category": "分类",
"iState": "状态",
"isTop": "是否置顶"
"iState": "状态"
},
"action": {
"publish": "发布",

View File

@ -17,11 +17,14 @@ export interface Schema extends EntityShape {
images: ExtraFile[];
logs: Log[];
category?: Category;
isTop: Boolean;
}
export type IState = 'unpublished' | 'published' | 'withdrawn';
export type TopState = 'top' | 'notTop';
export type TopAction = 'setTop' | 'cancelTop';
export type IAction = 'publish' | 'withdraw';
export const IActionDef: ActionDef<IAction, IState> = {
@ -32,12 +35,19 @@ export const IActionDef: ActionDef<IAction, IState> = {
is: 'unpublished',
};
export const TopActionDef: ActionDef<TopAction, TopState> = {
stm: {
setTop: ['notTop', 'top'],
cancelTop: ['top', 'notTop'],
},
is: 'notTop',
};
// 用户行为操作
export type CommonAction = 'setTop' | 'cancelTop';
export type LikeAction = 'like' | 'unlike';
type Action = IAction | CommonAction | LikeAction;
type Action = IAction | TopAction | LikeAction;
export const entityDesc: EntityDesc<
Schema,
@ -45,6 +55,7 @@ export const entityDesc: EntityDesc<
'',
{
iState: IState;
topState: TopState;
}
> = {
locales: {
@ -60,7 +71,7 @@ export const entityDesc: EntityDesc<
logs: '修改记录',
category: '分类',
iState: '状态',
isTop: '是否置顶',
topState: '置顶状态',
},
action: {
publish: '发布',
@ -76,6 +87,10 @@ export const entityDesc: EntityDesc<
published: '已发布',
withdrawn: '已撤回',
},
topState: {
top: '已置顶',
notTop: '未置顶',
},
},
},
},
@ -87,6 +102,10 @@ export const entityDesc: EntityDesc<
published: '#87d068',
withdrawn: '#2db7f5',
},
topState: {
top: '#87d068',
notTop: '#f50',
}
},
},
indexes: [

View File

@ -9,7 +9,7 @@ export default OakComponent({
// 先按置顶排序
sorter: {
$attr: {
isTop: 1,
topState: 1,
},
$direction: 'desc',
},

View File

@ -1,17 +1,17 @@
{
"essayList": "文章列表",
"title": "文章标题",
"summary": "文章摘要",
"author": "作者",
"action":{
"setting": "设置"
},
"label": {
"selectLabels": "选择标签"
},
"essay":{
"isTop": "已置顶",
"notTop": "未置顶"
},
"cover": "封面"
}
"essayList": "文章列表",
"title": "文章标题",
"summary": "文章摘要",
"author": "作者",
"action": {
"setting": "设置"
},
"label": {
"selectLabels": "选择标签"
},
"essay": {
"isTop": "已置顶",
"notTop": "未置顶"
},
"cover": "封面"
}

View File

@ -67,7 +67,7 @@ const EssayList = (
render: (row) => {
return (
<>
{row.isTop ? (
{row.topState === 'top' ? (
<Tag color='#f50'>{t('essay.isTop')}</Tag>
) : (
<Tag color='#108ee9'>{t('essay.notTop')}</Tag>
@ -245,7 +245,7 @@ const EssayList = (
/>
</PageHeader>
<Modal
title={t('label:selectLabels')}
title={t('label.selectLabels')}
open={showSelectLabels}
onCancel={() => setShowSelectLabels(false)}
onOk={() => {

View File

@ -9,15 +9,9 @@ export default OakComponent({
const fileIndex = data?.extraFile$entity?.findIndex(
(item) => item.tag1 === 'cover'
);
let isSelfLiked = false;
if (data?.like$essay) {
for (let i = 0; i < data?.like$essay?.length; i++) {
if (data?.like$essay?.[i].creator.id === this.features.token.getUserId()) {
isSelfLiked = true
break
}
}
}
const isSelfLiked = data?.like$essay?.some(
(item) => item.creator.id === features.token.getUserId()
);
if (fileIndex !== undefined && fileIndex > -1) {
const url = this.features.extraFile.getUrl(
data!.extraFile$entity![fileIndex]

View File

@ -15,7 +15,7 @@ const triggers: Trigger<EntityDict, 'essay', BackendRuntimeContext>[] = [
assert(data && !(data instanceof Array));
// 若不存在meta则初始化一个空对象
data.meta = data.meta || {};
data.isTop = data.isTop || false;
/* data.isTop = data.isTop || false; */
assert(data.content, 'content is required');
if (!data.summary) {
// 自动截取前面100个字符加上省略号
@ -27,7 +27,7 @@ const triggers: Trigger<EntityDict, 'essay', BackendRuntimeContext>[] = [
return 1;
},
},
// action setTop的时候设置isTop为true
/* // action setTop的时候设置isTop为true
{
name: '置顶时设置isTop为true',
entity: 'essay',
@ -52,7 +52,7 @@ const triggers: Trigger<EntityDict, 'essay', BackendRuntimeContext>[] = [
data.isTop = false;
return 1;
},
},
}, */
// action: like的时候增加点赞记录
{
name: "like的时候增加点赞记录",

View File

@ -61,7 +61,7 @@ export const essayProjection: EntityDict['essay']['Selection']['data'] = {
name: 1,
},
iState: 1,
isTop: 1,
topState: 1,
// 相关labels
essayLabels$essay: {
$entity: 'essayLabels',