about summary refs log tree commit diff
path: root/components/PostList
diff options
context:
space:
mode:
Diffstat (limited to 'components/PostList')
-rw-r--r--components/PostList/PostList.vue49
-rw-r--r--components/PostList/PurePostList.stories.js31
-rw-r--r--components/PostList/PurePostList.vue76
-rw-r--r--components/PostList/index.js3
4 files changed, 159 insertions, 0 deletions
diff --git a/components/PostList/PostList.vue b/components/PostList/PostList.vue
new file mode 100644
index 0000000..206a73f
--- /dev/null
+++ b/components/PostList/PostList.vue
@@ -0,0 +1,49 @@
+<template>
+  <pure-post-list :posts="posts" :loading="loading" />
+</template>
+
+<script>
+import PurePostList from './PurePostList'
+
+export default {
+  name: 'PostList',
+  components: { PurePostList },
+  props: {
+    max: {
+      type: Number,
+      required: false
+    }
+  },
+  data() {
+    return {
+      loading: true,
+      rawPosts: []
+    }
+  },
+  mounted() {
+    this.loadPostsClient()
+  },
+  computed: {
+    posts() {
+      if (this.max) {
+        return this.rawPosts.slice(0, this.max)
+      }
+      return this.rawPosts
+    }
+  },
+  methods: {
+    async loadPostsClient() {
+      let posts = await this.$axios.get(
+        `${window.location.origin}/api/posts.json`
+      )
+      this.rawPosts = posts.data
+      this.rawPosts = this.rawPosts.map(post => ({
+        title: post.content.meta.title,
+        description: post.content.description,
+        route: post.route
+      }))
+      this.loading = false
+    }
+  }
+}
+</script>
\ No newline at end of file
diff --git a/components/PostList/PurePostList.stories.js b/components/PostList/PurePostList.stories.js
new file mode 100644
index 0000000..cf812f7
--- /dev/null
+++ b/components/PostList/PurePostList.stories.js
@@ -0,0 +1,31 @@
+import { storiesOf } from '@storybook/vue'
+import { center } from '../../.storybook/decorators'
+
+import { postLink } from '../PostLink.stories'
+
+import PurePostList from './PurePostList'
+
+export const posts = Array(5).fill(postLink)
+console.log(posts)
+
+storiesOf('PurePostList', module)
+  .addDecorator(center)
+  .add('default', () => {
+    return {
+      components: { PurePostList },
+      template: `<pure-post-list :posts="posts"/>`,
+      data: () => ({ posts })
+    }
+  })
+  .add('loading', () => {
+    return {
+      components: { PurePostList },
+      template: `<pure-post-list :posts="posts" loading/>`
+    }
+  })
+  .add('no posts', () => {
+    return {
+      components: { PurePostList },
+      template: `<pure-post-list :posts="posts"/>`
+    }
+  })
diff --git a/components/PostList/PurePostList.vue b/components/PostList/PurePostList.vue
new file mode 100644
index 0000000..7e70db8
--- /dev/null
+++ b/components/PostList/PurePostList.vue
@@ -0,0 +1,76 @@
+<template>
+  <div class="post-list">
+    <div v-if="loading" class="post-list-container">
+      <div class="loading-post" v-for="(_, index) in 4" :key="index"></div>
+    </div>
+    <div v-else-if="posts" class="post-list-container">
+      <post-link
+        v-for="(post, index) in posts"
+        :key="index"
+        :route="post.route"
+        :title="post.title"
+        :description="post.description"
+      />
+    </div>
+    <div v-else class="no-posts">Brak wpisów</div>
+  </div>
+</template>
+
+<script>
+import PostLink from '../PostLink'
+
+export default {
+  name: 'PurePostList',
+  components: { PostLink },
+  props: {
+    posts: {
+      type: Array,
+      required: true
+    },
+    loading: {
+      type: Boolean,
+      required: false,
+      default: () => false
+    }
+  }
+}
+</script>
+
+<style scoped>
+.post-list {
+  width: 100%;
+  max-width: 900px;
+  justify-content: center;
+  margin: 0 auto;
+}
+
+.post-list-container {
+  display: flex;
+  flex-wrap: wrap;
+  justify-content: initial;
+}
+
+@keyframes loading {
+  0%,
+  100% {
+    opacity: 1;
+  }
+  50% {
+    opacity: 0.5;
+  }
+}
+
+.loading-post {
+  background: #efefef;
+  animation: loading 1.5s ease-in-out infinite;
+  margin: 20px;
+  flex-basis: 410px;
+  width: 410px;
+  height: 250px;
+  text-align: left;
+}
+
+.no-posts {
+  text-align: center;
+}
+</style>
\ No newline at end of file
diff --git a/components/PostList/index.js b/components/PostList/index.js
new file mode 100644
index 0000000..dbb515e
--- /dev/null
+++ b/components/PostList/index.js
@@ -0,0 +1,3 @@
+import PostList from './PostList'
+
+export default PostList