Skip to content

Commit

Permalink
Merge pull request #28 from returnone-x/postquestion
Browse files Browse the repository at this point in the history
complete show answer and answer vote and post new answer
  • Loading branch information
yorukot authored Jan 1, 2024
2 parents efc12c2 + 5cbd9b9 commit 7bd5d95
Show file tree
Hide file tree
Showing 21 changed files with 735 additions and 271 deletions.
14 changes: 14 additions & 0 deletions api/question/answer/deleteQuestionVote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { API_URL } from "@/config/config";
import axios from "axios";

export async function DeleteQuestionAnserVote(answerId: string) {
let config = {
method: "delete",
maxBodyLength: Infinity,
url: API_URL + `/user/question/deletevote/${answerId}`,
validateStatus: function () {
return true;
},
};
return await axios.request(config);
}
24 changes: 24 additions & 0 deletions api/question/answer/newQuestionAnswer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { API_URL } from "@/config/config";
import axios from "axios";

export async function NewQuestionAnswer(
quesitonId: string,
content: string
) {
let data = JSON.stringify({
content: content,
});
let config = {
method: "post",
maxBodyLength: Infinity,
url: API_URL + "/user/question/answer/new/" + quesitonId,
headers: {
"Content-Type": "application/json",
},
data: data,
validateStatus: function () {
return true;
},
};
return await axios.request(config);
}
17 changes: 17 additions & 0 deletions api/question/answer/questionAnsweDownVote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { API_URL } from "@/config/config";
import axios from "axios";

export async function QuestionAnswerDownVote(answerId: string) {
let config = {
method: "post",
maxBodyLength: Infinity,
url: API_URL + `/user/question/answer/downvote/${answerId}`,
headers: {
"Content-Type": "application/json",
},
validateStatus: function () {
return true;
},
};
return await axios.request(config);
}
17 changes: 17 additions & 0 deletions api/question/answer/questionAnsweUpVote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { API_URL } from "@/config/config";
import axios from "axios";

export async function QuestionAnswerUpVote(answerId: string) {
let config = {
method: "post",
maxBodyLength: Infinity,
url: API_URL + `/user/question/answer/upvote/${answerId}`,
headers: {
"Content-Type": "application/json",
},
validateStatus: function () {
return true;
},
};
return await axios.request(config);
}
31 changes: 31 additions & 0 deletions api/question/comment/newComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { API_URL } from "@/config/config";
import axios from "axios";

type TagInfo = {
tag: string;
version: string;
};

export async function NewQuestionComment(
quesitonId: string,
content: string,
reply: string,
) {
let data = JSON.stringify({
content: content,
reply: reply,
});
let config = {
method: "post",
maxBodyLength: Infinity,
url: API_URL + "/user/question/comment/new/" + quesitonId,
headers: {
"Content-Type": "application/json",
},
data: data,
validateStatus: function () {
return true;
},
};
return await axios.request(config);
}
5 changes: 0 additions & 5 deletions api/question/newQuestion.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { API_URL } from "@/config/config";
import axios from "axios";

type TagInfo = {
tag: string;
version: string;
};

export async function newQuestionPost(
title: string,
content: string,
Expand Down
5 changes: 0 additions & 5 deletions api/question/questionDownVote.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { API_URL } from "@/config/config";
import axios from "axios";

type TagInfo = {
tag: string;
version: string;
};

export async function QuestionDownVote(
question_id: string,
) {
Expand Down
5 changes: 0 additions & 5 deletions api/question/questionUpVote.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { API_URL } from "@/config/config";
import axios from "axios";

type TagInfo = {
tag: string;
version: string;
};

export async function QuestionUpvote(
question_id: string,
) {
Expand Down
5 changes: 3 additions & 2 deletions app/[locale]/question/[questionId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export default function questionPage({
edited: t("edited"),
loadMore: t("loadMore"),
vote: t("vote"),
voted: t("voted")
voted: t("voted"),
answer: t("answer")
};


return (
<Container size="xl">
<Container size="1450px">
<QuestionDetill questionId={questionId} t={signipLoginTranslate}/>
</Container>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
right: 0;
margin: 14px;
}

.codeblock {
background-color: #ffffff;
border-radius: 10px; /* 你可以調整這個值以改變圓潤的程度 */
}
24 changes: 4 additions & 20 deletions components/editor/codeBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import "./codeBlock.css";
import React from "react";
import { NodeViewContent, NodeViewWrapper } from "@tiptap/react";
import { CopyButton, ActionIcon } from "@mantine/core";
import { HiClipboard, HiClipboardCheck } from "react-icons/hi";
import classes from './Codeblock.module.css'

interface CodeBlockProps {
node: {
Expand All @@ -29,23 +27,9 @@ const CodeBlockComponent: React.FC<CodeBlockProps> = ({
extension,
}) => {
return (
<NodeViewWrapper className="code-block">
<div className="copy-button-container">
<CopyButton value={"test"}>
{({ copied, copy }) => (
<ActionIcon
variant="outline"
color={copied ? "green" : "gray"}
aria-label="Settings"
onClick={copy}
>
{copied ? <HiClipboardCheck /> : <HiClipboard />}
</ActionIcon>
)}
</CopyButton>
</div>
<pre>
<NodeViewContent as="code" />
<NodeViewWrapper className={classes.codeblock}>
<pre className={classes.codeblock}>
<NodeViewContent as="code" className={classes.codeblock} />
</pre>
</NodeViewWrapper>
);
Expand Down
2 changes: 2 additions & 0 deletions components/editor/codeLowLight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import coffeescript from "highlight.js/lib/languages/coffeescript";
export const Registerlowlight = createLowlight(common);

Registerlowlight.register("ts", ts);
Registerlowlight.register("tsx", ts);
Registerlowlight.register("js", js);
Registerlowlight.register("jsx", js);
Registerlowlight.register("py", py);
Registerlowlight.register("go", go);
Registerlowlight.register("rust", rust);
Expand Down
5 changes: 1 addition & 4 deletions components/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { BiCodeBlock } from "react-icons/bi";
import { Registerlowlight } from "./codeLowLight";
import CodeBlockComponent from "./codeBlock";
import { Dispatch, SetStateAction } from "react";

const lowlight = Registerlowlight;

const content = ""
Expand Down Expand Up @@ -41,19 +40,17 @@ export function TiptapEditor({changeContent}: {changeContent: Dispatch<SetStateA
});

return (
<RichTextEditor editor={editor} spellCheck={false}>
<RichTextEditor editor={editor} spellCheck={false} withCodeHighlightStyles>
<RichTextEditor.Toolbar sticky stickyOffset={60}>
<RichTextEditor.ControlsGroup>
<RichTextEditor.Bold />
<RichTextEditor.Italic />
<RichTextEditor.Strikethrough />
<RichTextEditor.H2 />
<RichTextEditor.Code />
<RichTextEditor.CodeBlock icon={BiCodeBlock} />
</RichTextEditor.ControlsGroup>

<RichTextEditor.ControlsGroup>
<RichTextEditor.Blockquote />
<RichTextEditor.Hr />
<RichTextEditor.BulletList />
<RichTextEditor.OrderedList />
Expand Down
68 changes: 68 additions & 0 deletions components/editor/simpleEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use client";
import "@mantine/tiptap/styles.css";

import { RichTextEditor, Link } from "@mantine/tiptap";
import { ReactNodeViewRenderer, useEditor } from "@tiptap/react";
import Highlight from "@tiptap/extension-highlight";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
import TextAlign from "@tiptap/extension-text-align";
import SubScript from "@tiptap/extension-subscript";
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
import { BiCodeBlock } from "react-icons/bi";
import { Registerlowlight } from "./codeLowLight";
import CodeBlockComponent from "./codeBlock";
import { Dispatch, SetStateAction } from "react";
const lowlight = Registerlowlight;

const content = ""
export function SimpleEditor({changeContent}: {changeContent: Dispatch<SetStateAction<string>>}) {
const editor = useEditor({
extensions: [
Underline,
Link,
SubScript,
Highlight,
TextAlign.configure({ types: ["heading", "paragraph"] }),
StarterKit.configure({ codeBlock: false }),
CodeBlockLowlight.extend({
addNodeView() {
return ReactNodeViewRenderer(CodeBlockComponent);
},
}).configure({ lowlight }),
],
content: content,
onUpdate: ({ editor }) => {
const html = editor.getHTML()
changeContent(html)
},

});

return (
<RichTextEditor editor={editor} spellCheck={false}>
<RichTextEditor.Toolbar sticky stickyOffset={60}>
<RichTextEditor.ControlsGroup>
<RichTextEditor.Bold />
<RichTextEditor.Italic />
<RichTextEditor.Strikethrough />
<RichTextEditor.Code />
<RichTextEditor.CodeBlock icon={BiCodeBlock} />
</RichTextEditor.ControlsGroup>

<RichTextEditor.ControlsGroup>
<RichTextEditor.Hr />
<RichTextEditor.BulletList />
<RichTextEditor.OrderedList />
</RichTextEditor.ControlsGroup>

<RichTextEditor.ControlsGroup>
<RichTextEditor.Link />
<RichTextEditor.Unlink />
</RichTextEditor.ControlsGroup>
</RichTextEditor.Toolbar>

<RichTextEditor.Content />
</RichTextEditor>
);
}
58 changes: 58 additions & 0 deletions components/editor/simpleViewContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use client";
import "./Editor.module.css";

import { RichTextEditor, Link } from "@mantine/tiptap";
import { ReactNodeViewRenderer, useEditor } from "@tiptap/react";
import Highlight from "@tiptap/extension-highlight";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
import TextAlign from "@tiptap/extension-text-align";
import SubScript from "@tiptap/extension-subscript";
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
import { Registerlowlight } from "./codeLowLight";
import CodeBlockComponent from "./codeBlock";
import classess from "./Editor.module.css";
const lowlight = Registerlowlight;

export function SimpleViewContent({ content }: { content: string }) {
const editor = useEditor({
extensions: [
Underline,
Link,
SubScript,
Highlight,
TextAlign.configure({ types: ["heading", "paragraph"] }),
StarterKit.configure({ codeBlock: false }),
CodeBlockLowlight.extend({
addNodeView() {
return ReactNodeViewRenderer(CodeBlockComponent);
},
}).configure({ lowlight }),
],
content: content,
editable: false,
});

return (
<RichTextEditor
editor={editor}
spellCheck={false}
style={{ padding: 0 }}
styles={{
root: {
border: "0px",
padding: 0,
},
typographyStylesProvider: {
padding: 0,
}
}}
>
<RichTextEditor.Content
style={{
padding: "0px",
}}
/>
</RichTextEditor>
);
}
Loading

0 comments on commit 7bd5d95

Please sign in to comment.