|
|
@ -1,10 +1,10 @@
|
|
|
|
|
|
|
|
import { formatDistanceToNow } from 'date-fns';
|
|
|
|
import { signIn, useSession } from 'next-auth/react';
|
|
|
|
import { signIn, useSession } from 'next-auth/react';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { Button, Dialog, TextArea, useToast } from '@tih/ui';
|
|
|
|
import { Button, Dialog, TextArea, useToast } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
|
|
import ProfilePhotoHolder from '~/components/offers/profile/ProfilePhotoHolder';
|
|
|
|
import ProfilePhotoHolder from '~/components/offers/profile/ProfilePhotoHolder';
|
|
|
|
|
|
|
|
|
|
|
|
import { timeSinceNow } from '~/utils/offers/time';
|
|
|
|
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
|
|
import type { Reply } from '~/types/offers';
|
|
|
|
import type { Reply } from '~/types/offers';
|
|
|
@ -135,45 +135,45 @@ export default function CommentCard({
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="text-sm">
|
|
|
|
<div className="flex flex-row items-center space-x-2">
|
|
|
|
<p className="font-medium text-slate-900">
|
|
|
|
<p className="text-sm font-medium text-slate-900">
|
|
|
|
{user?.name ?? 'unknown user'}
|
|
|
|
{user?.name ?? 'Unknown user'}
|
|
|
|
</p>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<span className="font-medium text-slate-500">·</span>
|
|
|
|
|
|
|
|
<div className="text-xs text-slate-500">
|
|
|
|
|
|
|
|
{formatDistanceToNow(createdAt, {
|
|
|
|
|
|
|
|
addSuffix: true,
|
|
|
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-1 text-sm text-slate-700">
|
|
|
|
<div className="mt-1 text-sm text-slate-700">
|
|
|
|
<p className="break-all">{message}</p>
|
|
|
|
<p className="break-all">{message}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mt-2 space-x-2 text-xs">
|
|
|
|
<div className="-ml-2 mt-1 flex h-6 items-center text-xs">
|
|
|
|
<span className="font-medium text-slate-500">
|
|
|
|
|
|
|
|
{timeSinceNow(createdAt)} ago
|
|
|
|
|
|
|
|
</span>{' '}
|
|
|
|
|
|
|
|
{replyLength > 0 && (
|
|
|
|
|
|
|
|
<>
|
|
|
|
|
|
|
|
<span className="font-medium text-slate-500">·</span>{' '}
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
|
|
className="font-medium text-slate-900"
|
|
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
|
|
onClick={handleExpanded}>
|
|
|
|
|
|
|
|
{isExpanded ? `Hide replies` : `View replies (${replyLength})`}
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!disableReply && (
|
|
|
|
{!disableReply && (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
<span className="font-medium text-slate-500">·</span>{' '}
|
|
|
|
className="-my-1 rounded-md px-2 py-1 text-xs font-medium text-slate-500 hover:bg-slate-100 hover:text-slate-600"
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="font-medium text-slate-900"
|
|
|
|
onClick={() => setIsReplying(!isReplying)}>
|
|
|
|
type="button"
|
|
|
|
Reply
|
|
|
|
onClick={() => setIsReplying(!isReplying)}>
|
|
|
|
</button>
|
|
|
|
Reply
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
{replyLength > 0 && (
|
|
|
|
</>
|
|
|
|
<button
|
|
|
|
|
|
|
|
className="-my-1 rounded-md px-2 py-1 text-xs font-medium text-slate-500 hover:bg-slate-100 hover:text-slate-600"
|
|
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
|
|
onClick={handleExpanded}>
|
|
|
|
|
|
|
|
{isExpanded
|
|
|
|
|
|
|
|
? `Hide ${replyLength === 1 ? 'reply' : 'replies'}`
|
|
|
|
|
|
|
|
: `Show ${replyLength} ${
|
|
|
|
|
|
|
|
replyLength === 1 ? 'reply' : 'replies'
|
|
|
|
|
|
|
|
}`}
|
|
|
|
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
{deletable && (
|
|
|
|
{deletable && (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<span className="font-medium text-slate-500">·</span>{' '}
|
|
|
|
|
|
|
|
<button
|
|
|
|
<button
|
|
|
|
className="font-medium text-slate-900"
|
|
|
|
className="-my-1 rounded-md px-2 py-1 text-xs font-medium text-slate-500 hover:bg-slate-100 hover:text-slate-600"
|
|
|
|
disabled={deleteCommentMutation.isLoading}
|
|
|
|
disabled={deleteCommentMutation.isLoading}
|
|
|
|
type="button"
|
|
|
|
type="button"
|
|
|
|
onClick={() => setIsDialogOpen(true)}>
|
|
|
|
onClick={() => setIsDialogOpen(true)}>
|
|
|
@ -210,8 +210,9 @@ export default function CommentCard({
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{!disableReply && isReplying && (
|
|
|
|
{!disableReply && isReplying && (
|
|
|
|
<div className="mt-4 mr-2">
|
|
|
|
<div className="mt-2">
|
|
|
|
<form
|
|
|
|
<form
|
|
|
|
|
|
|
|
className="space-y-2"
|
|
|
|
onSubmit={(event) => {
|
|
|
|
onSubmit={(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
event.stopPropagation();
|
|
|
@ -226,23 +227,29 @@ export default function CommentCard({
|
|
|
|
value={currentReply}
|
|
|
|
value={currentReply}
|
|
|
|
onChange={(value) => setCurrentReply(value)}
|
|
|
|
onChange={(value) => setCurrentReply(value)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<div className="mt-2 flex w-full justify-end">
|
|
|
|
<div className="flex w-full justify-end space-x-2">
|
|
|
|
<div className="w-fit">
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
disabled={createCommentMutation.isLoading}
|
|
|
|
disabled={
|
|
|
|
label="Cancel"
|
|
|
|
!currentReply.length ||
|
|
|
|
size="sm"
|
|
|
|
createCommentMutation.isLoading ||
|
|
|
|
variant="tertiary"
|
|
|
|
deleteCommentMutation.isLoading
|
|
|
|
onClick={() => {
|
|
|
|
}
|
|
|
|
setIsReplying(false);
|
|
|
|
display="block"
|
|
|
|
}}
|
|
|
|
isLabelHidden={false}
|
|
|
|
/>
|
|
|
|
isLoading={createCommentMutation.isLoading}
|
|
|
|
<Button
|
|
|
|
label="Reply"
|
|
|
|
disabled={
|
|
|
|
size="sm"
|
|
|
|
!currentReply.length ||
|
|
|
|
variant="primary"
|
|
|
|
createCommentMutation.isLoading ||
|
|
|
|
onClick={handleReply}
|
|
|
|
deleteCommentMutation.isLoading
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
isLabelHidden={false}
|
|
|
|
|
|
|
|
isLoading={createCommentMutation.isLoading}
|
|
|
|
|
|
|
|
label="Submit"
|
|
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
|
|
variant="primary"
|
|
|
|
|
|
|
|
onClick={handleReply}
|
|
|
|
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|