aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/Thread.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src/ui/Thread.js')
-rw-r--r--vnext/src/ui/Thread.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/vnext/src/ui/Thread.js b/vnext/src/ui/Thread.js
index de1d74b2..2919e830 100644
--- a/vnext/src/ui/Thread.js
+++ b/vnext/src/ui/Thread.js
@@ -6,7 +6,7 @@ import Message from './Message';
import MessageInput from './MessageInput';
import Spinner from './Spinner';
-import { getMessages, comment, update } from '../api';
+import { getMessages, comment, update, post } from '../api';
import { useVisitor } from './VisitorContext';
import { Helmet } from 'react-helmet';
/**
@@ -104,6 +104,26 @@ export default function Thread(props) {
const loaders = Math.min(message.replies || 0, 10);
const pageTitle = `${params.user} ${message && message.tags || 'thread'}`;
+ /** @type { import('./Message').ToggleSubscriptionCallback } */
+ const handleSubsciptionToggle = (message) => {
+ if (message.subscribed) {
+ if (confirm('Unsubscribe?')) {
+ post(`U #${message.mid}`).then((response) => {
+ if (response.status === 200) {
+ setMessage({...message, subscribed: false});
+ }
+ }).catch(console.error);
+ }
+ } else {
+ if (confirm('Subscribe?')) {
+ post(`S #${message.mid}`).then((response) => {
+ if (response.status === 200) {
+ setMessage({...message, subscribed: true});
+ }
+ }).catch(console.error);
+ }
+ }
+ };
return (
<>
<Helmet>
@@ -111,7 +131,7 @@ export default function Thread(props) {
</Helmet>
{
message.mid ? (
- <Message data={message}>
+ <Message key={message.mid} data={message} isThread={true} onToggleSubscription={handleSubsciptionToggle}>
{active === (message.rid || 0) && <MessageInput data={message} text={editing.body || ''} onSend={postComment}>Write a comment...</MessageInput>}
</Message>
) : (