import faker from '@faker-js/faker' import { storiesOf } from '@storybook/vue' import { withA11y } from '@storybook/addon-a11y' import HcEmpty from '~/components/Empty/Empty' import MasonryGrid from '~/components/MasonryGrid/MasonryGrid' import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem' import PostTeaser from '~/components/PostTeaser/PostTeaser' import TabNavigation from '~/components/_new/generic/TabNavigation/TabNavigation' import UserTeaser from '~/components/UserTeaser/UserTeaser' import HcHashtag from '~/components/Hashtag/Hashtag' import helpers from '~/storybook/helpers' import { post } from '~/components/PostTeaser/PostTeaser.story.js' import { user } from '~/components/UserTeaser/UserTeaser.story.js' helpers.init() const postMock = (fields) => { return { ...post, id: faker.random.uuid(), createdAt: faker.date.past(), updatedAt: faker.date.recent(), deleted: false, disabled: false, typename: 'Post', ...fields, } } const userMock = (fields) => { return { ...user, id: faker.random.uuid(), createdAt: faker.date.past(), updatedAt: faker.date.recent(), deleted: false, disabled: false, typename: 'User', ...fields, } } const posts = [ postMock(), postMock({ author: user }), postMock({ title: faker.lorem.sentence() }), postMock({ contentExcerpt: faker.lorem.paragraph() }), postMock({ author: user }), postMock({ title: faker.lorem.sentence() }), postMock({ author: user }), ] const users = [ userMock(), userMock({ slug: 'louie-rider', name: 'Louie Rider' }), userMock({ slug: 'louicinda-johnson', name: 'Louicinda Jonhson' }), userMock({ slug: 'sam-louie', name: 'Sam Louie' }), userMock({ slug: 'loucette', name: 'Loucette Rider' }), userMock({ slug: 'louis', name: 'Louis' }), userMock({ slug: 'louanna', name: 'Louanna' }), ] storiesOf('TabNavigator', module) .addDecorator(withA11y) .addDecorator(helpers.layout) .add('given search results of posts, users, hashtags', () => ({ components: { TabNavigation, HcEmpty, MasonryGrid, MasonryGridItem, PostTeaser, UserTeaser, HcHashtag, }, store: helpers.store, data: () => ({ posts: posts, users: users, hashtags: [], postCount: posts.length, userCount: users.length, hashtagCount: 0, activeTab: 'Post', }), computed: { activeResources() { if (this.activeTab === 'Post') return this.posts if (this.activeTab === 'User') return this.users if (this.activeTab === 'Hashtag') return this.hashtags return [] }, activeResourceCount() { if (this.activeTab === 'Post') return this.postCount if (this.activeTab === 'User') return this.userCount if (this.activeTab === 'Hashtag') return this.hashtagCount return 0 }, tabOptions() { return [ { type: 'Post', title: this.$t('search.heading.Post', {}, this.postCount), count: this.postCount, disabled: this.postCount === 0, }, { type: 'User', title: this.$t('search.heading.User', {}, this.userCount), count: this.userCount, disabled: this.userCount === 0, }, { type: 'Hashtag', title: this.$t('search.heading.Tag', {}, this.hashtagCount), count: this.hashtagCount, disabled: this.hashtagCount === 0, }, ] }, searchCount() { return this.postCount + this.userCount + this.hashtagCount }, }, methods: { switchTab(tabType) { if (this.activeTab !== tabType) { this.activeTab = tabType } }, }, template: `