-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFeed.stories.tsx
More file actions
91 lines (80 loc) · 2.43 KB
/
Copy pathFeed.stories.tsx
File metadata and controls
91 lines (80 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from 'react';
import {PageConstructor} from '@gravity-ui/page-constructor';
import {Meta, Story} from '@storybook/react/types-6-0';
import {isEqual} from 'lodash';
import {getDefaultStoryArgs} from '../../../../.mocks/utils';
import customBlocks from '../../../constructor/blocksMap';
import {FeedContext} from '../../../contexts/FeedContext';
import {BLOCKS} from '../../../demo/constants';
import {FeedProps} from '../../../models/blocks';
import {
BlockStandsAloneType,
GetPostsRequest,
GetPostsType,
PostsProps,
Service,
Tag,
} from '../../../models/common';
import {Feed} from '../Feed';
import mockedPosts from '../../../../.mocks/posts.json';
import mockedServices from '../../../../.mocks/services.json';
import mockedTags from '../../../../.mocks/tags.json';
export default {
title: `${BLOCKS}/Feed`,
component: Feed,
args: {
theme: 'light',
},
} as Meta;
type FeedModel = {
type: BlockStandsAloneType.Feed;
} & FeedProps;
const getPosts: GetPostsType = async (query: GetPostsRequest) => {
const filteredPosts = mockedPosts.posts
.filter(
(post) =>
!query.tags ||
isEqual(
post.tags.map((tag) => tag.id.toString()),
query.tags.split(','),
),
)
.filter(
(post) =>
!query.services ||
isEqual(
post.services.map((service) => service.id.toString()),
query.services.split(','),
),
)
.filter(
(post) =>
!query.search ||
post.metaTitle.includes(query.search) ||
post.content.includes(query.search),
);
return {
...mockedPosts,
posts: filteredPosts,
count: filteredPosts.length,
totalCount: mockedPosts.totalCount,
} as unknown as PostsProps;
};
const contextData = {
...mockedPosts,
services: mockedServices as Service[],
tags: mockedTags as Tag[],
getPosts,
};
const DefaultTemplate: Story<FeedModel> = (args) => (
<FeedContext.Provider value={contextData}>
<PageConstructor content={{blocks: [args]}} custom={customBlocks} />
</FeedContext.Provider>
);
export const Default = DefaultTemplate.bind({});
Default.args = {
type: BlockStandsAloneType.Feed,
color: '#000',
imageSize: 'm',
...getDefaultStoryArgs(),
};