-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
244 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ pnpm-debug.log* | |
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
*.key* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script> | ||
import {questionApi} from "@modules/qna/api"; | ||
let form = { | ||
topic: null | ||
} | ||
async function createTopic() { | ||
const response = await questionApi('/page', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
title: form.topic | ||
}) | ||
}) | ||
window.location.href=`topic?id=${response.id}` | ||
} | ||
</script> | ||
|
||
<form on:submit|preventDefault={createTopic}> | ||
<input type="text" placeholder="Topic" bind:value={form.topic}> | ||
<input type="submit" value="Create"> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script> | ||
import {onMount} from 'svelte' | ||
import {questionApi} from "@modules/qna/api"; | ||
const url = new URL(window.location.href) | ||
const id = parseInt(url.searchParams.get('id')) | ||
let topic | ||
onMount(async () => { | ||
topic = await questionApi(`/page/${id}/questions`); | ||
}) | ||
let form = { | ||
question: null | ||
} | ||
async function addQuestion(x) { | ||
const question = await questionApi(`/question`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
title: form.question, | ||
pageId: id | ||
}) | ||
}); | ||
topic.questions = [...topic.questions, question] | ||
form.question = null | ||
} | ||
</script> | ||
|
||
<div> | ||
{#if topic} | ||
<h1>{topic.title}</h1> | ||
{/if} | ||
<form on:submit|preventDefault={() => addQuestion('test')}> | ||
<input type="text" bind:value={form.question} placeholder="What is your question?"> | ||
<input type="submit" value="Add Question" /> | ||
</form> | ||
|
||
{#if topic} | ||
<ul> | ||
{#each topic.questions as question} | ||
<li> | ||
{question.title} <br /> | ||
Votes: {question.voteCount} | Answers: {question.answerCount} | ||
</li> | ||
{/each} | ||
</ul> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
import { onMount } from 'svelte'; | ||
import { questionApi } from '@modules/qna/api'; | ||
let topics = [] | ||
onMount(async () => { | ||
topics = await questionApi('/pages'); | ||
}); | ||
</script> | ||
|
||
<div> | ||
<h2>Topics <a href="/tools/question-answer/new" style="float: right; font-size: 1rem">+ New Topic</a></h2> | ||
<ul> | ||
{#each topics as topic (topic.id)} | ||
<li><a href="/tools/question-answer/topic?id={topic.id}">{topic.title}</a></li> | ||
{/each} | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const baseUrl = import.meta.env.PUBLIC_API_URL; | ||
|
||
export function questionApi(endPoint: string, options: any) { | ||
return fetch(`${baseUrl}${endPoint}`, options).then((res) => res.json()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
import BaseHead from '../../../components/BaseHead.astro'; | ||
import Header from '../../../components/Header.astro'; | ||
import Footer from '../../../components/Footer.astro'; | ||
import { SITE_TITLE, SITE_DESCRIPTION } from '../../../config'; | ||
import Topics from "../../../modules/qna/Topics.svelte"; | ||
const pageTitle = 'Question and Answers'; | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<BaseHead title={pageTitle} description={SITE_DESCRIPTION} /> | ||
</head> | ||
<body> | ||
<Header title={SITE_TITLE} /> | ||
<main> | ||
<h1>🏁 {pageTitle}</h1> | ||
<Topics client:only /> | ||
</main> | ||
<Footer /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
import BaseHead from '../../../components/BaseHead.astro'; | ||
import Header from '../../../components/Header.astro'; | ||
import Footer from '../../../components/Footer.astro'; | ||
import { SITE_TITLE, SITE_DESCRIPTION } from '../../../config'; | ||
import NewTopic from '@modules/qna/NewTopic.svelte'; | ||
const pageTitle = 'Question and Answers'; | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<BaseHead title={pageTitle} description={SITE_DESCRIPTION} /> | ||
</head> | ||
<body> | ||
<Header title={SITE_TITLE} /> | ||
<main> | ||
<h1>🏁 {pageTitle}</h1> | ||
<NewTopic client:only /> | ||
</main> | ||
<Footer /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
import BaseHead from '../../../components/BaseHead.astro'; | ||
import Header from '../../../components/Header.astro'; | ||
import Footer from '../../../components/Footer.astro'; | ||
import { SITE_TITLE, SITE_DESCRIPTION } from '../../../config'; | ||
import Topic from "@modules/qna/Topic.svelte"; | ||
const pageTitle = 'Question and Answers'; | ||
--- | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<BaseHead title={pageTitle} description={SITE_DESCRIPTION} /> | ||
</head> | ||
<body> | ||
<Header title={SITE_TITLE} /> | ||
<main> | ||
<h1>🏁 {pageTitle}</h1> | ||
<Topic client:only /> | ||
</main> | ||
<Footer /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters