MCPcopy Index your code
hub / github.com/code100x/cms / PostCard

Function PostCard

src/components/posts/PostCard.tsx:45–264  ·  view source on GitHub ↗
({
  post,
  sessionUser,
  questionId,
  reply = false,
  enableLink = false,
  isAnswer = true,
  parentAuthorName,
})

Source from the content-addressed store, hash-verified

43 return (post as ExtendedQuestion).slug !== undefined;
44};
45const PostCard: React.FC<IProps> = ({
46 post,
47 sessionUser,
48 questionId,
49 reply = false,
50 enableLink = false,
51 isAnswer = true,
52 parentAuthorName,
53}) => {
54 const { theme } = useTheme();
55 const [markDownValue, setMarkDownValue] = useState('');
56 const [enableReply, setEnableReply] = useState(false);
57 const handleMarkdownChange = (newValue?: string) => {
58 if (typeof newValue === 'string') {
59 setMarkDownValue(newValue);
60 }
61 };
62
63 const handleEditorClick = (e: React.MouseEvent) => {
64 e.stopPropagation();
65 };
66
67 const router = useRouter();
68
69 const [isPending, startTransition] = useTransition();
70
71 const { execute, fieldErrors } = useAction(createAnswer, {
72 onSuccess: () => {
73 toast.success(`Reply added`);
74 if (!fieldErrors?.content) {
75 setEnableReply(false);
76 setMarkDownValue('');
77 }
78 },
79 onError: (error) => {
80 toast.error(error);
81 },
82 });
83
84 const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
85 event.preventDefault();
86 execute({
87 content: markDownValue,
88 questionId,
89 parentId: isAnswer ? post?.id : undefined,
90 });
91 };
92
93 const formatNumber = (num: number) => {
94 if (num >= 1000) {
95 return `${(num / 1000).toFixed(1).replace(/\.0$/, '')}K`;
96 }
97 return num.toString();
98 };
99
100 return (
101 <div
102 className={`flex w-full cursor-pointer flex-col gap-4 p-3 transition-all duration-300 sm:p-5 ${!post.content && !isAnswer

Callers

nothing calls this directly

Calls 3

useActionFunction · 0.90
isExtendedQuestionFunction · 0.85
formatNumberFunction · 0.70

Tested by

no test coverage detected