From 34da06762e81f85c5df29fdec66e2055b8b930a9 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Tue, 3 Dec 2019 13:05:15 +0100 Subject: Add missing stories --- components/Posts/PostList/PostList.vue | 55 ++++++++++++++ components/Posts/PostList/PurePostList.stories.js | 30 ++++++++ components/Posts/PostList/PurePostList.vue | 91 +++++++++++++++++++++++ components/Posts/PostList/index.js | 3 + 4 files changed, 179 insertions(+) create mode 100644 components/Posts/PostList/PostList.vue create mode 100644 components/Posts/PostList/PurePostList.stories.js create mode 100644 components/Posts/PostList/PurePostList.vue create mode 100644 components/Posts/PostList/index.js (limited to 'components/Posts/PostList') diff --git a/components/Posts/PostList/PostList.vue b/components/Posts/PostList/PostList.vue new file mode 100644 index 0000000..781099f --- /dev/null +++ b/components/Posts/PostList/PostList.vue @@ -0,0 +1,55 @@ + + + diff --git a/components/Posts/PostList/PurePostList.stories.js b/components/Posts/PostList/PurePostList.stories.js new file mode 100644 index 0000000..e2c39de --- /dev/null +++ b/components/Posts/PostList/PurePostList.stories.js @@ -0,0 +1,30 @@ +import { storiesOf } from '@storybook/vue' + +import { postLink } from '../PostLink.stories' + +import PurePostList from './PurePostList' + +export const posts = Array(5).fill(postLink) + +storiesOf('Posts/PurePostList', module) + .add('default', () => { + return { + components: { PurePostList }, + template: ``, + data: () => ({ posts }) + } + }) + .add('loading', () => { + return { + components: { PurePostList }, + template: ``, + data: () => ({ posts: [] }) + } + }) + .add('no posts', () => { + return { + components: { PurePostList }, + template: ``, + data: () => ({ posts: [] }) + } + }) diff --git a/components/Posts/PostList/PurePostList.vue b/components/Posts/PostList/PurePostList.vue new file mode 100644 index 0000000..ace069f --- /dev/null +++ b/components/Posts/PostList/PurePostList.vue @@ -0,0 +1,91 @@ + + + + + diff --git a/components/Posts/PostList/index.js b/components/Posts/PostList/index.js new file mode 100644 index 0000000..dbb515e --- /dev/null +++ b/components/Posts/PostList/index.js @@ -0,0 +1,3 @@ +import PostList from './PostList' + +export default PostList -- cgit 1.4.1 From 29a4e2488151861c10abeb0a05622e4d06e07c60 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Thu, 5 Dec 2019 17:34:44 +0100 Subject: Fix SSR on PostList --- components/Posts/PostList/PostList.vue | 45 +++++++++----------------------- components/Posts/PostList/README.md | 42 +++++++++++++++++++++++++++++ components/Posts/PostList/index.js | 19 ++++++++++++++ components/Posts/PostList/parentMixin.js | 9 +++++++ package-lock.json | 8 +++--- package.json | 1 + pages/index.vue | 6 +++-- pages/kronika/index.vue | 6 +++-- 8 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 components/Posts/PostList/README.md create mode 100644 components/Posts/PostList/parentMixin.js (limited to 'components/Posts/PostList') diff --git a/components/Posts/PostList/PostList.vue b/components/Posts/PostList/PostList.vue index 781099f..80369a8 100644 --- a/components/Posts/PostList/PostList.vue +++ b/components/Posts/PostList/PostList.vue @@ -1,9 +1,8 @@ +``` + +Or by using the mixin + +```html + + + +``` diff --git a/components/Posts/PostList/index.js b/components/Posts/PostList/index.js index dbb515e..11d44ff 100644 --- a/components/Posts/PostList/index.js +++ b/components/Posts/PostList/index.js @@ -1,3 +1,22 @@ +import axios from 'axios' + +import k from '~/api' import PostList from './PostList' +export const getPosts = async () => { + if (process.client) { + let posts = await axios.get(`${window.location.origin}/api/posts.json`) + return parsePosts(posts.data) + } else { + return parsePosts(k.getPosts()) + } +} + +export const parsePosts = posts => + posts.map(post => ({ + title: post.content.meta.title, + description: post.content.description, + route: post.route + })) + export default PostList diff --git a/components/Posts/PostList/parentMixin.js b/components/Posts/PostList/parentMixin.js new file mode 100644 index 0000000..e5b06ed --- /dev/null +++ b/components/Posts/PostList/parentMixin.js @@ -0,0 +1,9 @@ +import { getPosts } from './index' + +export default { + async asyncData() { + return { + posts: await getPosts() + } + } +} diff --git a/package-lock.json b/package-lock.json index dc75e41..3c259df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4150,7 +4150,7 @@ "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", "requires": { "follow-redirects": "1.5.10", - "is-buffer": "2.0.3" + "is-buffer": "2.0.4" }, "dependencies": { "debug": { @@ -4170,9 +4170,9 @@ } }, "is-buffer": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", - "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", + "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" }, "ms": { "version": "2.0.0", diff --git a/package.json b/package.json index d7925a2..6522e9d 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "@nuxtjs/axios": "^5.3.6", "@nuxtjs/pwa": "^3.0.0-0", + "axios": "^0.19.0", "esm": "^3.2.25", "front-matter": "^3.0.2", "jsdom": "^15.1.1", diff --git a/pages/index.vue b/pages/index.vue index 3a19237..045025d 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -3,7 +3,7 @@

Ostatnie wpisy z kroniki

- +
@@ -13,9 +13,11 @@ import JoinUs from '~/components/JoinUs.vue' import FacebookFeed from '~/components/Facebook/FacebookFeed.vue' import PostList from '~/components/Posts/PostList' +import postListParentMixin from '~/components/Posts/PostList/parentMixin' export default { name: 'HomeView', - components: { JoinUs, FacebookFeed, PostList } + components: { JoinUs, FacebookFeed, PostList }, + mixins: [postListParentMixin] } diff --git a/pages/kronika/index.vue b/pages/kronika/index.vue index 86344c3..8142a6c 100644 --- a/pages/kronika/index.vue +++ b/pages/kronika/index.vue @@ -1,16 +1,18 @@ -- cgit 1.4.1