TopicPreview

Превью топика, используется в поиске/сортировке на главной странице в журнале

Props

topic

  • type: TopicPreview
  • required: true

Объект темы

tag

  • type: string
  • default: 'div'

Тег корневого элемента

tagSelectable

  • type: boolean
  • default: false

Можно ли кликать по тегу

favoriteType

  • type: string
  • default: 'topic'
  • values: page, topic

Events

Event namePropertiesDescription
select-tagid id - тега по которому кликнулиКлик по тегу
toggle-ratetopicId number - id топика
isRateUp boolean - статус изменения рейтинга
Изменение рейтинга
toggle-favoritetopicId number - id топика
isFavorite boolean - статус изменения избранного
Изменение избранного

Types

import type { AvatarLinkUser } from '#sf/components/user/avatar-link/types';
import type { EduLink } from '#sf/services/link';

import type { TopicPreviewFile, GetTagsApiTag } from '#sf/sections/journal/api';

export type TopicPreview = {
  id: number;
  imageFile: null | TopicPreviewFile;
  topic: string;
  description: string;
  intro: string;
  text: string;
  tags: GetTagsApiTag[];
  createdAt: Date;
  publishedAt: null | Date;
  views: number;
  newViews: number;
  comments: number;
  rate_good: number;
  rate_bad: number;
  favorite: boolean;
  pinned: boolean;
  voting: boolean;
  topicUrl: string | EduLink;
  commentsUrl: string | EduLink;
  author?: AvatarLinkUser;
};

Test data

import { testTags } from '#sf/components/tag-filter/test-data';
import { testUserAvatarLink } from '#sf/components/user/avatar-link/test-data';

import type { TopicPreview } from './types';

export const testTopicPreview: TopicPreview = {
  id: 0,
  imageFile: {
    id: 0,
    directUrl: process.env.EDU_STATIC_PATH + '/samples/sample.jpg',
  },
  topic: 'Укрепить иммунитет?',
  intro:
    'Как не заболеть весной и осенью? Как питаться, чтобы не болеть? Как быстро вылечиться, если уже заболел?',
  description: '',
  text: 'Foo<b>bar</b>baz',
  tags: [],
  author: testUserAvatarLink,
  createdAt: new Date(),
  publishedAt: null,
  views: 100,
  newViews: 10,
  comments: 15,
  rate_good: 10,
  rate_bad: 5,
  favorite: false,
  pinned: true,
  voting: false,
  topicUrl: 'topic-url',
  commentsUrl: 'comments-url',
};

export const testTopicPreview2: TopicPreview = {
  ...testTopicPreview,
  topic: 'Укрепить иммунитет или как быстро вылечиться, если уже заболел?',
  intro: '',
  description:
    'Как не заболеть весной и осенью? Как питаться, чтобы не болеть? Как быстро вылечиться, если уже заболел? Да что вообще делать то ёк-макарек, а?',
  text: '',
  favorite: true,
  pinned: true,
  voting: true,
  createdAt: new Date(2022, 3, 2),
  publishedAt: new Date(2022, 4, 2),
  tags: testTags,
  author: undefined,
};