Skip to content

Commit 1880558

Browse files
committed
fix(): Fixing the markdown links issue
1 parent 898ca4d commit 1880558

10 files changed

Lines changed: 136 additions & 5 deletions

File tree

src/components/MdPreview/MdPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MdPreviewProps } from './types';
55

66
const MdPreview = ({ mdString }: MdPreviewProps) => {
77
return (
8-
<Box width={'100%'} maxW={'70vw'} data-color-mode={'dark'}>
8+
<Box width={'100%'} maxW={'70vw'} data-color-mode={'dark'} zIndex={1}>
99
<MarkdownPreview className={markdownStyle.markdown} source={mdString} />
1010
</Box>
1111
);

src/components/MdPreview/__tests__/__snapshots__/MdPreview.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`MdPreview should render MdPreview 1`] = `
44
<div>
55
<div
6-
class="css-1npfbn5"
6+
class="css-uf6hy9"
77
data-color-mode="dark"
88
>
99
<markdown-preview
@@ -16,7 +16,7 @@ exports[`MdPreview should render MdPreview 1`] = `
1616
exports[`MdPreview should render MdPreview 2`] = `
1717
<div>
1818
<div
19-
class="css-1npfbn5"
19+
class="css-uf6hy9"
2020
data-color-mode="dark"
2121
>
2222
<markdown-preview

src/components/MdPreview/css/Markdown.module.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
border-radius: 6px;
66
font-size: 1rem;
77
color: #fffffff0;
8+
z-index: 10;
89
background-color: transparent;
910
line-height: 1.5;
1011
}
1112

1213
.markdown a {
1314
color: #ffffffa0;
14-
text-decoration: none;
15+
text-decoration: underline;
1516
font-weight: 600;
1617
}
1718

src/components/Noise/Noise.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const Noise = ({ type = 'bg' }: { type?: 'bg' | 'fg' }) => {
22
return (
33
<div
4-
className={`${type === 'bg' ? 'absolute inset-0 w-full h-full' : 'w-[100%] h-[100%]'} transform opacity-10 [mask-image:radial-gradient(#fff,transparent,75%)]`}
4+
className={`${type === 'bg' ? 'absolute inset-0 w-full h-full' : 'w-[100%] h-[100%]'} transform opacity-10 [mask-image:radial-gradient(#fff,transparent,75%)]
5+
z-0 pointer-events-none`}
56
style={{
67
backgroundImage: 'url(/noise.webp)',
78
backgroundSize: '15%',

src/screens/articleEditor/ArticleEditor.tsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import {
2+
AlertDialog,
3+
AlertDialogBody,
4+
AlertDialogContent,
5+
AlertDialogFooter,
6+
AlertDialogHeader,
7+
AlertDialogOverlay,
28
Box,
39
Button,
410
Divider,
@@ -8,6 +14,7 @@ import {
814
RadioGroup,
915
Text,
1016
Textarea,
17+
useDisclosure,
1118
VStack,
1219
} from '@chakra-ui/react';
1320
import '@mdxeditor/editor/style.css';
@@ -18,9 +25,77 @@ import { ArticleWithContent } from './types';
1825
import { getRequestObject, isValidArticle } from './utils';
1926
import {
2027
useAddArticle,
28+
useDeleteArticle,
2129
useGetEditorArticleData,
2230
useUpdateArticle,
2331
} from '@services';
32+
import React from 'react';
33+
import { isEmpty } from 'lodash';
34+
35+
const DeleteArticleButton = ({
36+
articleKey,
37+
onDelete,
38+
}: {
39+
articleKey: string;
40+
onDelete: () => void;
41+
}) => {
42+
const { mutate } = useDeleteArticle();
43+
const { isOpen, onOpen, onClose } = useDisclosure();
44+
const cancelRef = React.useRef<HTMLButtonElement>(null);
45+
const [articleKeyValidation, setArticleKeyValidation] = useState<string>('');
46+
47+
return (
48+
<>
49+
<Button
50+
colorScheme="red"
51+
onClick={onOpen}
52+
isDisabled={isEmpty(articleKey)}
53+
>
54+
Delete Article
55+
</Button>
56+
<AlertDialog
57+
isOpen={isOpen}
58+
leastDestructiveRef={cancelRef}
59+
onClose={onClose}
60+
>
61+
<AlertDialogOverlay>
62+
<AlertDialogContent>
63+
<AlertDialogHeader fontSize="lg" fontWeight="bold">
64+
Delete Customer
65+
</AlertDialogHeader>
66+
67+
<AlertDialogBody>
68+
{`Are you sure of deleting the article? You can't undo this action afterwards.`}
69+
<Input
70+
mt={3}
71+
placeholder={`Type ${articleKey} to confirm`}
72+
value={articleKeyValidation}
73+
onChange={(e) => setArticleKeyValidation(e.target.value)}
74+
/>
75+
</AlertDialogBody>
76+
<AlertDialogFooter>
77+
<Button ref={cancelRef} onClick={onClose}>
78+
Cancel
79+
</Button>
80+
<Button
81+
colorScheme="red"
82+
onClick={() => {
83+
mutate({ articleKey });
84+
onClose();
85+
onDelete();
86+
}}
87+
isDisabled={articleKeyValidation !== articleKey}
88+
ml={3}
89+
>
90+
Delete
91+
</Button>
92+
</AlertDialogFooter>
93+
</AlertDialogContent>
94+
</AlertDialogOverlay>
95+
</AlertDialog>
96+
</>
97+
);
98+
};
2499

25100
const ArticleEditor = () => {
26101
const { setCursorType } = useCursor();
@@ -191,6 +266,10 @@ const ArticleEditor = () => {
191266
Preload
192267
</Button>
193268
</HStack>
269+
<DeleteArticleButton
270+
articleKey={state.article_key}
271+
onDelete={() => setState(ARTICLE_DEFAULT)}
272+
/>
194273
<ArticleCard {...state} />
195274
</VStack>
196275
</HStack>

src/services/backend/articles/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const ADD_ARTICLE_URL = `/add_article`;
1212
export const DELETE_ARTICLE_URL = `/delete_article`;
1313
export const UPDATE_ARTICLE_URL = `/update_article`;
1414
export const ADD_COMMENT_URL = `/add_comment`;
15+
export const DELETE_COMMENT_URL = `/delete_comment`;
1516

1617
// Editor
1718
export const EDITOR_ARTICLES_URL = `/get_editor_article`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { GetRequest } from '../client/client';
2+
import { DELETE_ARTICLE_URL } from './constants';
3+
import { StandardResponse } from './types';
4+
5+
const deleteArticle = async (data: any): Promise<StandardResponse> => {
6+
return await GetRequest(
7+
DELETE_ARTICLE_URL + '?articleKey=' + data.articleKey,
8+
);
9+
};
10+
11+
export default deleteArticle;

src/services/backend/articles/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ export { default as getComments } from './getComments';
99
export { default as getEditorArticleData } from './getEditorArticleData';
1010
export { default as updateArticle } from './updateArticle';
1111

12+
export { default as deleteArticle } from './deleteArticle';
13+
1214
export { default as pingTest } from './pingTest';

src/services/hooks/articles/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export { default as useAddArticle } from './useAddArticle';
66
export { default as useAddComment } from './useAddComment';
77
export { default as useGetComments } from './useGetComments';
88
export { default as useUpdateArticle } from './useUpdateArticle';
9+
export { default as useDeleteArticle } from './useDeleteArticle';
910

1011
export { default as usePingTest } from './usePingTest';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useToast } from '@chakra-ui/react';
2+
import { deleteArticle } from '../../backend';
3+
import { useCallSBMutation } from '../common';
4+
import { useQueryClient } from '@tanstack/react-query';
5+
6+
const useDeleteArticle = () => {
7+
const toast = useToast();
8+
const queryClient = useQueryClient();
9+
return useCallSBMutation({
10+
method: (data) => deleteArticle(data),
11+
mutationOptions: {
12+
onSuccess: (_data, variables: any) => {
13+
toast({
14+
title: 'Article removed.',
15+
status: 'success',
16+
duration: 3000,
17+
isClosable: true,
18+
});
19+
queryClient.invalidateQueries({
20+
queryKey: ['comments', variables.articleKey],
21+
});
22+
},
23+
onError: (error) => {
24+
toast({
25+
title: 'Error.' + error.message,
26+
status: 'error',
27+
duration: 3000,
28+
isClosable: true,
29+
});
30+
},
31+
},
32+
});
33+
};
34+
35+
export default useDeleteArticle;

0 commit comments

Comments
 (0)