Clicking an item marks it read, show repost and likes as refs

This commit is contained in:
Peter Stuifzand 2018-08-30 20:52:05 +02:00
parent d8cf6cf959
commit dc72d1bdaa
3 changed files with 70 additions and 19 deletions

View File

@ -9,7 +9,6 @@
- Preview - Preview
- Follow, Unfollow feeds - Follow, Unfollow feeds
- Channels create, update, delete - Channels create, update, delete
- References to other posts: "refs"
- Channel ordering - Channel ordering
- Different interfaces (perhaps Twitter, Mastodon like) - Different interfaces (perhaps Twitter, Mastodon like)
- Better responsive interface - Better responsive interface
@ -24,6 +23,9 @@
- Micropub - Micropub
- Like - Like
- Repost - Repost
- Reply
- Posting
- References to other posts: "refs" (likes and reposts)
## Ideas ## Ideas

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<div :class="classes"> <div :class="classes" @click="markRead">
<div class="card-image" v-if="photo_first"> <div class="card-image" v-if="photo_first">
<figure class="image"> <figure class="image">
<img :src="photo_first"/> <img :src="photo_first"/>
@ -15,7 +15,12 @@
</figure> </figure>
</div> </div>
<div class="content"> <div v-if="isRef">
<div><a :href="author_url">{{ author_name }}</a> reposted:</div>
<Entry :item="innerRef" :isMainEntry="false"></Entry>
</div>
<div class="content" v-else>
<div><a :href="author_url">{{ author_name }}</a></div> <div><a :href="author_url">{{ author_name }}</a></div>
<h3 class="title is-6" v-if="item.name" v-text="item.name"></h3> <h3 class="title is-6" v-if="item.name" v-text="item.name"></h3>
<div class="content" v-html="main_content"></div> <div class="content" v-html="main_content"></div>
@ -26,19 +31,17 @@
</div> </div>
</div> </div>
<div class="debug" v-text="item" v-if="this.$store.state.debug"></div>
<a :href="item.url" target="_new"> <a :href="item.url" target="_new">
<span class="published" v-html="item.published"></span> <span class="published" v-html="item.published"></span>
</a> </a>
</div> </div>
</div> </div>
</div> </div>
<footer class="card-footer"> <footer class="card-footer" v-if="showFooterButtons">
<a class="card-footer-item" @click="debug">Debug</a> <a class="card-footer-item" @click.prevent="debug">Debug</a>
<a class="card-footer-item" @click="like">Like</a> <a class="card-footer-item" @click.prevent="like">Like</a>
<a class="card-footer-item" @click="repost">Repost</a> <a class="card-footer-item" @click.prevent="repost">Repost</a>
<a class="card-footer-item" @click="openReply">Reply</a> <a class="card-footer-item" @click.prevent="openReply">Reply</a>
</footer> </footer>
</div> </div>
<div class="card" v-if="replying"> <div class="card" v-if="replying">
@ -55,12 +58,13 @@
<script> <script>
export default { export default {
name: "Entry", name: "Entry",
props: ['item'], props: ['item', 'is-main-entry'],
data() { data() {
return { return {
'replying': false, 'replying': false,
'replyText': '' 'replyText': '',
'showFooterButtons': true
} }
}, },
@ -71,6 +75,9 @@
openReply() { openReply() {
this.replying = true this.replying = true
}, },
markRead() {
this.$emit('markRead', this.item)
},
reply() { reply() {
this.$store.dispatch('micropubPost', { this.$store.dispatch('micropubPost', {
'type': ['h-entry'], 'type': ['h-entry'],
@ -98,12 +105,45 @@
'repost-of': [this.item.url] 'repost-of': [this.item.url]
}, },
}) })
} },
hasRef(key) {
if (this.item.hasOwnProperty(key) && this.item.hasOwnProperty('refs')) {
if (this.item.refs.hasOwnProperty(this.item[key])) {
return true
}
}
return false
},
},
mounted() {
this.showFooterButtons = this.isMainEntry
}, },
computed: { computed: {
classes() { classes() {
return {'entry': true, 'card': true, 'mb-20': true, 'unread': !this.item._is_read} return {
'entry': true,
'card': true,
'mb-20': this.isMainEntry,
'unread': this.isMainEntry && !this.item._is_read
}
},
innerRef() {
if (this.isLike) {
return this.item.refs[this.item['like-of']]
} else if (this.isRepost) {
return this.item.refs[this.item['repost-of']]
}
},
isRef() {
return this.isLike || this.isRepost
},
isLike() {
return this.hasRef('like-of')
},
isRepost() {
return this.hasRef('repost-of')
}, },
main_content() { main_content() {
let content = this.item.content let content = this.item.content
@ -171,13 +211,19 @@
</script> </script>
<style scoped> <style scoped>
.entry { .entry.unread {
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 3px;
} }
.unread { .unread {
box-shadow: 0 4px 8px 0 rgba(255, 255, 0, 0.8), 0 6px 20px 0 rgba(255, 255, 0, 0.5); box-shadow: 0 4px 8px 0 rgba(255, 255, 0, 0.8), 0 6px 20px 0 rgba(255, 255, 0, 0.5);
} }
.media .entry {
margin-top: 0.75rem;
}
.media .entry .media {
margin-top: 0;
}
.photos { .photos {
display: grid; display: grid;

View File

@ -15,7 +15,7 @@
</div> </div>
<div class="timeline--item" v-for="item in items" :key="item.id"> <div class="timeline--item" v-for="item in items" :key="item.id">
<TimelineEntry :item="item" @debug="debug"/> <TimelineEntry :item="item" @debug="debug" @markRead="markRead(channel.uid, ...arguments)" :is-main-entry="true"/>
</div> </div>
<div class="level"> <div class="level">
<div class="level-item"> <div class="level-item">
@ -78,8 +78,11 @@
prevPage() { prevPage() {
this.$emit('getPage', {uid: this.channel.uid, before: this.timeline.paging.before}) this.$emit('getPage', {uid: this.channel.uid, before: this.timeline.paging.before})
}, },
markRead(channel, id) { markRead(channel, item) {
return this.$store.dispatch('markRead', {channel: channel, entry: id}) return this.$store.dispatch('markRead', {channel: channel, entry: item._id})
.then(() => {
item._is_read = true
})
} }
}, },