Merge pull request #3259 from urbit/mp/publish-reads

publish: send reads on nav, distinguish unreads
This commit is contained in:
matildepark 2020-08-06 20:59:02 -04:00 committed by GitHub
commit e15d54d163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -12,7 +12,8 @@ export class Note extends Component {
constructor(props) {
super(props);
this.state = {
deleting: false
deleting: false,
sentRead: false
};
moment.updateLocale('en', {
relativeTime: {
@ -46,16 +47,19 @@ export class Note extends Component {
}
componentDidUpdate(prevProps) {
const { props } = this;
const { props, state } = this;
if ((prevProps && prevProps.api !== props.api) || props.api) {
if (!(props.notebooks[props.ship]?.[props.book]?.notes?.[props.note]?.file)) {
props.api.publish.fetchNote(props.ship, props.book, props.note);
}
if (prevProps) {
if ((prevProps.book !== props.book) ||
(prevProps.note !== props.note) ||
(prevProps.ship !== props.ship)) {
if (prevProps && prevProps.note !== props.note) {
this.setState({ sentRead: false });
}
if (!state.sentRead &&
props.notebooks?.[props.ship]?.[props.book]?.notes?.[props.note] &&
!props.notebooks[props.ship][props.book].notes[props.note].read) {
const readAction = {
read: {
who: props.ship.slice(1),
@ -63,9 +67,10 @@ export class Note extends Component {
note: props.note
}
};
props.api.publish.publishAction(readAction);
this.setState({ sentRead: true }, () => {
props.api.publish.publishAction(readAction);
});
}
}
}
}

View File

@ -84,7 +84,7 @@ export class NotebookPosts extends Component {
' gray2 mr3'}
title={note.author}
>{name}</div>
<div className="gray2 mr3">{date}</div>
<div className={((note.read) ? "gray2 " : "green2 ") + "mr3"}>{date}</div>
<div className="gray2">{comment}</div>
</div>
</div>