remove grid logic from post component

This commit is contained in:
Alina Beck 2019-08-18 18:28:48 +01:00
parent 76be960c03
commit 0aa1b8046b

View File

@ -1,73 +1,71 @@
<template> <template>
<ds-grid-item ref="postCard" :rowSpan="rowSpan"> <ds-card
<ds-card :image="post.image | proxyApiUrl"
:image="post.image | proxyApiUrl" :class="{ 'post-card': true, 'disabled-content': post.disabled }"
:class="{ 'post-card': true, 'disabled-content': post.disabled }" >
<!-- Post Link Target -->
<nuxt-link
class="post-link"
:to="{ name: 'post-id-slug', params: { id: post.id, slug: post.slug } }"
> >
<!-- Post Link Target --> {{ post.title }}
<nuxt-link </nuxt-link>
class="post-link" <ds-space margin-bottom="small" />
:to="{ name: 'post-id-slug', params: { id: post.id, slug: post.slug } }" <!-- Username, Image & Date of Post -->
> <div>
{{ post.title }} <no-ssr>
</nuxt-link> <hc-user :user="post.author" :trunc="35" :date-time="post.createdAt" />
<ds-space margin-bottom="small" /> </no-ssr>
<!-- Username, Image & Date of Post --> <hc-ribbon :text="$t('post.name')" />
<div> </div>
<no-ssr> <ds-space margin-bottom="small" />
<hc-user :user="post.author" :trunc="35" :date-time="post.createdAt" /> <!-- Post Title -->
</no-ssr> <ds-heading tag="h3" no-margin>{{ post.title }}</ds-heading>
<hc-ribbon :text="$t('post.name')" /> <ds-space margin-bottom="small" />
<!-- Post Content Excerpt -->
<!-- eslint-disable vue/no-v-html -->
<!-- TODO: replace editor content with tiptap render view -->
<div class="hc-editor-content" v-html="excerpt" />
<!-- eslint-enable vue/no-v-html -->
<!-- Footer o the Post -->
<template slot="footer">
<div style="display: inline-block; opacity: .5;">
<!-- Categories -->
<hc-category
v-for="category in post.categories"
:key="category.id"
v-tooltip="{
content: category.name,
placement: 'bottom-start',
delay: { show: 500 },
}"
:icon="category.icon"
/>
</div> </div>
<ds-space margin-bottom="small" /> <no-ssr>
<!-- Post Title --> <div style="display: inline-block; float: right">
<ds-heading tag="h3" no-margin>{{ post.title }}</ds-heading> <!-- Shouts Count -->
<ds-space margin-bottom="small" /> <span :style="{ opacity: post.shoutedCount ? 1 : 0.5 }">
<!-- Post Content Excerpt --> <ds-icon name="bullhorn" />
<!-- eslint-disable vue/no-v-html --> <small>{{ post.shoutedCount }}</small>
<!-- TODO: replace editor content with tiptap render view --> </span>
<div class="hc-editor-content" v-html="excerpt" /> &nbsp;
<!-- eslint-enable vue/no-v-html --> <!-- Comments Count -->
<!-- Footer o the Post --> <span :style="{ opacity: post.commentsCount ? 1 : 0.5 }">
<template slot="footer"> <ds-icon name="comments" />
<div style="display: inline-block; opacity: .5;"> <small>{{ post.commentsCount }}</small>
<!-- Categories --> </span>
<hc-category <!-- Menu -->
v-for="category in post.categories" <content-menu
:key="category.id" resource-type="contribution"
v-tooltip="{ :resource="post"
content: category.name, :modalsData="menuModalsData"
placement: 'bottom-start', :is-owner="isAuthor"
delay: { show: 500 },
}"
:icon="category.icon"
/> />
</div> </div>
<no-ssr> </no-ssr>
<div style="display: inline-block; float: right"> </template>
<!-- Shouts Count --> </ds-card>
<span :style="{ opacity: post.shoutedCount ? 1 : 0.5 }">
<ds-icon name="bullhorn" />
<small>{{ post.shoutedCount }}</small>
</span>
&nbsp;
<!-- Comments Count -->
<span :style="{ opacity: post.commentsCount ? 1 : 0.5 }">
<ds-icon name="comments" />
<small>{{ post.commentsCount }}</small>
</span>
<!-- Menu -->
<content-menu
resource-type="contribution"
:resource="post"
:modalsData="menuModalsData"
:is-owner="isAuthor"
/>
</div>
</no-ssr>
</template>
</ds-card>
</ds-grid-item>
</template> </template>
<script> <script>
@ -97,11 +95,6 @@ export default {
default: () => {}, default: () => {},
}, },
}, },
data() {
return {
rowSpan: 10,
}
},
computed: { computed: {
...mapGetters({ ...mapGetters({
user: 'auth/user', user: 'auth/user',
@ -132,26 +125,6 @@ export default {
this.$toast.error(err.message) this.$toast.error(err.message)
} }
}, },
calculateItemHeight() {
const grid = document.querySelector('.ds-grid')
const rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'))
const rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap'))
grid.style.gridAutoRows = 'auto'
grid.style.alignItems = 'self-start'
const itemHeight = this.$refs.postCard.$el.clientHeight
this.rowSpan = Math.ceil((itemHeight + rowGap) / (rowHeight + rowGap))
grid.style.gridAutoRows = `${rowHeight}px`
grid.style.alignItems = 'stretch'
},
},
mounted() {
const image = this.$refs.postCard.$el.querySelector('img')
if (image) {
image.onload = this.calculateItemHeight
} else {
// use timeout to make sure layout is set up before executing
setTimeout(this.calculateItemHeight, 0)
}
}, },
} }
</script> </script>