add interaction api- ui
This commit is contained in:
1
user-interface/.env
Normal file
1
user-interface/.env
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_URL=http://127.0.0.1:8000/
|
||||
1
user-interface/.env.example
Normal file
1
user-interface/.env.example
Normal file
@@ -0,0 +1 @@
|
||||
VITE_API_URL=http://127.0.0.1:8000/
|
||||
1034
user-interface/package-lock.json
generated
1034
user-interface/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@
|
||||
"format": "prettier --write --experimental-cli src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"buetify": "^0.1.7",
|
||||
"buefy": "^3.0.4",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.27",
|
||||
"vue-router": "^5.0.1"
|
||||
@@ -30,15 +30,15 @@
|
||||
"@types/node": "^24.10.9",
|
||||
"@vitejs/plugin-vue": "^6.0.3",
|
||||
"@vitest/eslint-plugin": "^1.6.6",
|
||||
"@vue/eslint-config-typescript": "^14.6.0",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"@vue/eslint-config-typescript": "^14.2.0",
|
||||
"@vue/test-utils": "^2.4.0",
|
||||
"@vue/tsconfig": "^0.8.1",
|
||||
"cypress": "^15.9.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint": "^10.0.1",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-cypress": "^5.2.1",
|
||||
"eslint-plugin-oxlint": "~1.42.0",
|
||||
"eslint-plugin-vue": "~10.7.0",
|
||||
"eslint-plugin-vue": "^10.2.0",
|
||||
"jiti": "^2.6.1",
|
||||
"jsdom": "^27.4.0",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
|
||||
@@ -16,13 +16,13 @@ import AppTopbar from '@/components/AppTopbar.vue'
|
||||
</template>
|
||||
|
||||
<style>
|
||||
/* #app {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
#app {
|
||||
background-color: #FFF4EA;
|
||||
padding-inline: 5%;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
main {
|
||||
/* main {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
10
user-interface/src/assets/variables.sass
Normal file
10
user-interface/src/assets/variables.sass
Normal file
@@ -0,0 +1,10 @@
|
||||
// variables.sass
|
||||
@import '~buetify/src/sass/variables'
|
||||
@import '~bulma/sass/utilities/initial-variables'
|
||||
|
||||
// provide any variable overrides here
|
||||
|
||||
@import '~bulma/sass/utilities/functions'
|
||||
@import '~bulma/sass/utilities/derived-variables'
|
||||
@import '~bulma/sass/utilities/controls'
|
||||
@import '~bulma/sass/utilities/mixins'
|
||||
@@ -1,11 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { BField, BInput, BButton } from "buefy";
|
||||
import { apiClient } from "@/services/api";
|
||||
|
||||
let knowledgeText = ""
|
||||
function postKnowledge(){
|
||||
let knowlegde = {
|
||||
content: knowledgeText,
|
||||
uri: "wiki"
|
||||
}
|
||||
apiClient.post("api/v1/knowledges/", knowlegde)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="container">
|
||||
<h2>Collect Knowledge</h2>
|
||||
<b-field label="Knowledge">
|
||||
<b-input maxlength="1200" type="textarea" v-model="knowledgeText"></b-input>
|
||||
</b-field>
|
||||
<b-button type="is-primary" @click="postKnowledge" >Submit</b-button>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -3,11 +3,14 @@ import { createPinia } from 'pinia'
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import './styles/global.css';
|
||||
|
||||
import Buefy from "buefy";
|
||||
import "buefy/dist/css/buefy.css";
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
app.use(Buefy)
|
||||
|
||||
app.mount('#app')
|
||||
|
||||
74
user-interface/src/services/api.ts
Normal file
74
user-interface/src/services/api.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
class ApiClient {
|
||||
private baseURL: string
|
||||
private defaultHeaders: Record<string, string>
|
||||
|
||||
constructor(baseURL: string) {
|
||||
this.baseURL = baseURL
|
||||
this.defaultHeaders = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
}
|
||||
|
||||
private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
|
||||
const url = `${this.baseURL}${endpoint}`
|
||||
const config: RequestInit = {
|
||||
headers: { ...this.defaultHeaders, ...options.headers },
|
||||
...options,
|
||||
}
|
||||
|
||||
let response
|
||||
|
||||
try {
|
||||
response = await fetch(url, config)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw new HTTPError(`Network error: ${error.message}`)
|
||||
}
|
||||
throw new HTTPError('Unknown network error')
|
||||
}
|
||||
|
||||
if (response?.ok) {
|
||||
return response.json()
|
||||
}
|
||||
|
||||
const errorData = await response.json().catch(() => ({}))
|
||||
throw new HTTPError(
|
||||
errorData.message || `HTTP ${response.status}: ${response.statusText}`,
|
||||
response.status,
|
||||
response,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP Get
|
||||
* @param endpoint
|
||||
* @returns
|
||||
*/
|
||||
|
||||
async get<T>(endpoint: string): Promise<T> {
|
||||
return this.request<T>(endpoint, { method: 'GET' })
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP Post
|
||||
* @param endpoint
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
async post<T>(endpoint: string, data: unknown): Promise<T> {
|
||||
return this.request<T>(endpoint, { method: 'POST', body: JSON.stringify(data) })
|
||||
}
|
||||
}
|
||||
|
||||
class HTTPError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
private status: number | null = null,
|
||||
private reponse: Response | null = null,
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'HTTPError'
|
||||
}
|
||||
}
|
||||
|
||||
export const apiClient = new ApiClient(import.meta.env.VITE_API_URL)
|
||||
@@ -1,4 +0,0 @@
|
||||
body {
|
||||
background-color: #FFF4EA;
|
||||
margin-inline: 5%;
|
||||
}
|
||||
Reference in New Issue
Block a user