From 817d61a66383dbab126860e8411887eaad4076b9 Mon Sep 17 00:00:00 2001 From: Artemiy Solopov Date: Sat, 5 Sep 2026 23:10:55 +0300 Subject: [PATCH] Simple auctions index --- src/components/auctions/Index.vue | 38 +++++++++++++++++++++++++++++++ src/components/lib/check_user.js | 5 ++++ src/components/lib/gateway.js | 20 +++++++++++++++- src/pages/auctions.astro | 11 +++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/components/auctions/Index.vue create mode 100644 src/components/lib/check_user.js create mode 100644 src/pages/auctions.astro diff --git a/src/components/auctions/Index.vue b/src/components/auctions/Index.vue new file mode 100644 index 0000000..f757262 --- /dev/null +++ b/src/components/auctions/Index.vue @@ -0,0 +1,38 @@ + + + + + \ No newline at end of file diff --git a/src/components/lib/check_user.js b/src/components/lib/check_user.js new file mode 100644 index 0000000..ae9059c --- /dev/null +++ b/src/components/lib/check_user.js @@ -0,0 +1,5 @@ +import {$token, Anonymous} from "../stores/token.js"; + +$token.subscribe(token => { + if(token === Anonymous) { location.replace("/login") } +}) \ No newline at end of file diff --git a/src/components/lib/gateway.js b/src/components/lib/gateway.js index a8c496c..513ad35 100644 --- a/src/components/lib/gateway.js +++ b/src/components/lib/gateway.js @@ -1,3 +1,5 @@ +import { ref, computed } from 'vue' + export async function request(path, options) { options ||= {} if(path.startsWith('/')) { @@ -9,7 +11,7 @@ export async function request(path, options) { searchParams.forEach((v, k) => url.searchParams.append(k, v)) const safeFetch = (options.method === 'GET') || (options.method === 'HEAD') - const authorization = (options.token) ? `Bearer ${options.token}` : null + const authorization = (options.token) ? `Bearer ${options.token}` : '' const fetchInit = { method: options.method || 'GET', @@ -24,5 +26,21 @@ export async function request(path, options) { } } + // TODO: add processing for 4xx and 5xx return await fetch(url, fetchInit) } + +const Pending = Symbol('pending') + +export function useRequest(path, options) { + let responseRef = ref(Pending) + request(path, options).then(e => responseRef.value = {error: null, headers: e.headers, data: e.json()}) + .catch(reason => responseRef.value = {error: reason}) + + return { + isPending: computed(() => responseRef.value === Pending), + data: computed(() => responseRef.value.data), + error: computed(() => responseRef.value.error), + rref: responseRef + } +} \ No newline at end of file diff --git a/src/pages/auctions.astro b/src/pages/auctions.astro new file mode 100644 index 0000000..3e87df6 --- /dev/null +++ b/src/pages/auctions.astro @@ -0,0 +1,11 @@ +--- +import Layout from '../layouts/Layout.astro'; + +import Auctions from '../components/auctions/Index.vue' +--- + + + + + + \ No newline at end of file