|
|
@ -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">
|
|
|
|
{!disableReply && (
|
|
|
|
{timeSinceNow(createdAt)} ago
|
|
|
|
|
|
|
|
</span>{' '}
|
|
|
|
|
|
|
|
{replyLength > 0 && (
|
|
|
|
|
|
|
|
<>
|
|
|
|
|
|
|
|
<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"
|
|
|
|
type="button"
|
|
|
|
type="button"
|
|
|
|
onClick={handleExpanded}>
|
|
|
|
onClick={() => setIsReplying(!isReplying)}>
|
|
|
|
{isExpanded ? `Hide replies` : `View replies (${replyLength})`}
|
|
|
|
Reply
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
{!disableReply && (
|
|
|
|
{replyLength > 0 && (
|
|
|
|
<>
|
|
|
|
|
|
|
|
<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"
|
|
|
|
type="button"
|
|
|
|
type="button"
|
|
|
|
onClick={() => setIsReplying(!isReplying)}>
|
|
|
|
onClick={handleExpanded}>
|
|
|
|
Reply
|
|
|
|
{isExpanded
|
|
|
|
|
|
|
|
? `Hide ${replyLength === 1 ? 'reply' : 'replies'}`
|
|
|
|
|
|
|
|
: `Show ${replyLength} ${
|
|
|
|
|
|
|
|
replyLength === 1 ? 'reply' : 'replies'
|
|
|
|
|
|
|
|
}`}
|
|
|
|
</button>
|
|
|
|
</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,24 +227,30 @@ 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
|
|
|
|
|
|
|
|
disabled={createCommentMutation.isLoading}
|
|
|
|
|
|
|
|
label="Cancel"
|
|
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
|
|
variant="tertiary"
|
|
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
setIsReplying(false);
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
disabled={
|
|
|
|
disabled={
|
|
|
|
!currentReply.length ||
|
|
|
|
!currentReply.length ||
|
|
|
|
createCommentMutation.isLoading ||
|
|
|
|
createCommentMutation.isLoading ||
|
|
|
|
deleteCommentMutation.isLoading
|
|
|
|
deleteCommentMutation.isLoading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
display="block"
|
|
|
|
|
|
|
|
isLabelHidden={false}
|
|
|
|
isLabelHidden={false}
|
|
|
|
isLoading={createCommentMutation.isLoading}
|
|
|
|
isLoading={createCommentMutation.isLoading}
|
|
|
|
label="Reply"
|
|
|
|
label="Submit"
|
|
|
|
size="sm"
|
|
|
|
size="sm"
|
|
|
|
variant="primary"
|
|
|
|
variant="primary"
|
|
|
|
onClick={handleReply}
|
|
|
|
onClick={handleReply}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|