Compare commits

..
8 Commits
Author SHA1 Message Date
artemis fbf667762d Merge branch 'preparing-css' 2026-09-09 17:29:33 +03:00
artemis ff81b5b9bb Auctions index card 2026-09-09 17:29:12 +03:00
artemis 1879ec67f1 Added Bootstrap's top nav 2026-09-08 15:35:44 +03:00
artemis 3b6b0bbf9a Added Bootstrap and Sass 2026-09-08 13:00:03 +03:00
artemis cddfc1e24b Removed the token store 2026-09-07 23:55:57 +03:00
artemis 817d61a663 Simple auctions index 2026-09-05 23:10:55 +03:00
artemis b88095fd4f Renamed user store to token store 2026-09-04 15:20:36 +03:00
artemis 47440d44ec Updated Astro and Vue 2026-09-02 16:47:32 +03:00
21 changed files with 2455 additions and 2392 deletions
+14 -1
View File
@@ -5,5 +5,18 @@ import vue from '@astrojs/vue';
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [vue()] integrations: [vue()],
vite: {
css: {
preprocessorOptions: {
scss: {
quietDeps: true,
silenceDeprecations: [
// For Bootstrap
'import',
],
}
}
}
}
}); });
+6 -3
View File
@@ -9,11 +9,14 @@
"astro": "astro" "astro": "astro"
}, },
"dependencies": { "dependencies": {
"@astrojs/vue": "^5.1.3", "@astrojs/vue": "^7.0.2",
"@nanostores/vue": "^1.0.1", "@nanostores/vue": "^1.0.1",
"astro": "^5.16.6", "@popperjs/core": "^2.11.8",
"astro": "^7.2.10",
"bootstrap": "^5.3.8",
"nanostores": "^1.1.0", "nanostores": "^1.1.0",
"vue": "^3.5.26" "sass-embedded": "^1.104.0",
"vue": "^3.5.42"
}, },
"devDependencies": { "devDependencies": {
"@nanostores/logger": "^1.0.0" "@nanostores/logger": "^1.0.0"
+2276 -2240
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,6 +1,6 @@
<script setup> <script setup>
import {ref} from "vue"; import {ref} from "vue";
import {setLoggedInUser} from "./stores/user.js"; import {saveToken} from "./scripts/load_token.js";
import * as gateway from "./lib/gateway.js"; import * as gateway from "./lib/gateway.js";
const formData = ref({username: '', password: ''}) const formData = ref({username: '', password: ''})
@@ -17,7 +17,7 @@ async function formSubmit() {
if(response.status === 200) { if(response.status === 200) {
const responseData = await response.json() const responseData = await response.json()
console.log(responseData) console.log(responseData)
setLoggedInUser(responseData.token, responseData.expiresAt) saveToken(responseData)
} }
} }
</script> </script>
+11 -30
View File
@@ -3,34 +3,15 @@ import Link from './top_nav/Link.astro'
import UserAction from './top_nav/UserAction.vue' import UserAction from './top_nav/UserAction.vue'
--- ---
<nav> <nav class="navbar navbar-expand bg-primary-subtle">
<a class="brand" href="/">NV</a> <div class="container-fluid">
<ul class="center"> <a class="brand p-2" href="/">NV</a>
<li><Link href="/auctions">Auctions</Link></li>
</ul>
<ul class="right">
<li><UserAction client:load /></li>
</ul>
</nav>
<style> <ul class="navbar-nav me-auto">
nav { <li class="nav-item"><Link href="/auctions">Auctions</Link></li>
display: flex; </ul>
flex-flow: row nowrap; <ul class="navbar-nav">
width: 100%; <UserAction client:load />
</ul>
> ul { </div>
list-style: none; </nav>
display: flex;
flex-flow: row nowrap;
}
> .center {
margin-inline: auto;
}
> .right {
margin-left: auto;
}
}
</style>
+46 -20
View File
@@ -1,31 +1,57 @@
<script setup> <script setup>
import {ref, watch} from 'vue' import {ref, computed, onMounted} from "vue";
import {useStore} from '@nanostores/vue' import {request} from "../lib/gateway.js";
import {$user} from '../stores/user' import {loadToken} from "../scripts/load_token.js";
import * as gateway from '../lib/gateway.js'
const user = useStore($user) const pending = Symbol('pending')
const auctions = ref([])
watch(user, async (userVal) => { const qref = ref(pending)
if(userVal == null) return; const isPending = computed(() => qref.value === pending)
const data = computed(() => qref.value.data)
const response = await gateway.request('/auctions', async function loadAuctions() { // TODO: add params
{cors: true, token: userVal.token, searchParams: {page: 1, per: 50}} let token = loadToken()
) if(!token.token) return;
if (response.ok) { try {
auctions.value = await response.json() let response = await request("/auctions", {cors: true, token: token.token})
qref.value = {error: null, headers: response.headers, data: await response.json()}
} catch (error) {
qref.value = {error}
} }
}, {immediate: true}) }
onMounted(async () => {
await loadAuctions()
})
function formatPrice(price) {
const fmt = new Intl.NumberFormat("en-US", {style: "currency", currency: "USD"}) // TODO: maybe load currency from backend or env
return fmt.format(price)
}
</script> </script>
<template> <template>
<ul> <template v-if="isPending">
<li v-for="auction in auctions" :key="auction.id"> <div class="spinner-border me-1" role="status"></div>
<h3>{{ auction.summary }}</h3> <span>Loading…</span>
<a :href="`/auctions/auction?id=${auction.id}`">See more</a> </template>
</li> <div v-else-if="!isPending && data != null && data.length > 0" class="auctions-section" role="list">
</ul> <div v-for="auction in data" :key="auction.id" class="card" role="listitem">
<div class="card-body">
<h2 class="h5">{{ auction.name }}</h2>
<p class="text-end">{{ formatPrice(auction.current_bid || auction.starting_price) }}</p>
</div>
</div>
</div>
<p v-else>No auctions available</p>
</template> </template>
<style scoped>
.auctions-section {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(20em, 1fr));
gap: 1em;
}
</style>
-17
View File
@@ -1,17 +0,0 @@
<script setup>
import {useStore} from "@nanostores/vue";
import {$user} from "../stores/user.js";
const id = new URL(location).searchParams.get("id")
</script>
<template>
<template v-if="id">
<span>{{ id }}</span>
</template>
<div v-else>ERROR</div>
</template>
<style scoped>
</style>
+3
View File
@@ -0,0 +1,3 @@
import {loadToken, Anonymous} from "../scripts/load_token.js";
if(loadToken() === Anonymous) { location.replace("/login") }
+20 -1
View File
@@ -1,3 +1,5 @@
import { ref, computed } from 'vue'
export async function request(path, options) { export async function request(path, options) {
options ||= {} options ||= {}
if(path.startsWith('/')) { if(path.startsWith('/')) {
@@ -9,7 +11,7 @@ export async function request(path, options) {
searchParams.forEach((v, k) => url.searchParams.append(k, v)) searchParams.forEach((v, k) => url.searchParams.append(k, v))
const safeFetch = (options.method === 'GET') || (options.method === 'HEAD') 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 = { const fetchInit = {
method: options.method || 'GET', method: options.method || 'GET',
@@ -19,9 +21,26 @@ export async function request(path, options) {
headers: { headers: {
'Content-Type': options.contentType || 'Content-Type': options.contentType ||
(safeFetch ? null : 'application/json'), (safeFetch ? null : 'application/json'),
'X-Requested-With': 'fetch',
'Authorization': authorization 'Authorization': authorization
} }
} }
// TODO: add processing for 4xx and 5xx
return await fetch(url, fetchInit) 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
}
}
+1
View File
@@ -0,0 +1 @@
import * as bootstrap from 'bootstrap'
+26
View File
@@ -0,0 +1,26 @@
const LOCAL_STORAGE_KEY="token"
export const Anonymous = Symbol("anonymous")
class Token {
constructor({token, expiresAt}) {
this.token = token
this.expiresAt = new Date(expiresAt)
}
}
export function loadToken() {
let data = localStorage[LOCAL_STORAGE_KEY]
if (data == null) { return Anonymous }
data = JSON.parse(data)
if (data == null || data.token == null) { return Anonymous }
let token = new Token(data)
if(token.expiresAt < new Date()) { return Anonymous }
return token
}
export function saveToken(value) {
if(value == null || !value.token) return;
localStorage[LOCAL_STORAGE_KEY] = JSON.stringify(value)
}
-18
View File
@@ -1,18 +0,0 @@
import {$user, setAnonUser, setLoggedInUser} from "../stores/user.js";
const LOCAL_STORAGE_KEY="user"
$user.subscribe(value => {
if(value == null || !value.initialized) return;
localStorage[LOCAL_STORAGE_KEY] = JSON.stringify(value)
})
window.addEventListener('load', () => {
let data = localStorage[LOCAL_STORAGE_KEY]
if (data == null) { return setAnonUser() }
data = JSON.parse(data)
if (data == null || data.token == null) { return setAnonUser() }
if(Date.parse(data.expiresAt) < Date()) { return setAnonUser() }
setLoggedInUser(data.token, data.expiresAt)
})
-11
View File
@@ -1,11 +0,0 @@
import { atom } from 'nanostores'
export const $user = atom({})
export function setAnonUser() {
$user.set({initialized: true})
}
export function setLoggedInUser(token, expiresAt) {
$user.set({initialized: true, loggedIn: true, token: token, expiresAt: expiresAt})
}
+1 -1
View File
@@ -3,6 +3,6 @@ const {href} = Astro.props
const isActive = Astro.url.pathname.startsWith(href) const isActive = Astro.url.pathname.startsWith(href)
--- ---
<a class:list={[{active: isActive}]} href={href}> <a class:list={["nav-link", {active: isActive}]} href={href}>
<slot></slot> <slot></slot>
</a> </a>
+23 -12
View File
@@ -1,21 +1,32 @@
<script setup> <script setup>
import {useStore} from '@nanostores/vue' import {ref, onMounted} from "vue";
import {$user} from "../stores/user.js"; import {loadToken, Anonymous} from "../scripts/load_token.js";
const user = useStore($user) const Loading = Symbol("loading")
const token = ref(Loading)
onMounted(() => {
token.value = loadToken()
})
</script> </script>
<template> <template>
<div v-if="!user.initialized" class="placeholder"></div> <!-- TODO: replace with an actual placeholder --> <li :class="['nav-item', {'dropdown': (token !== Loading && token !== Anonymous)}]">
<a href="/login" v-else-if="!user.loggedIn">Login</a> <div v-if="token === Loading" class="placeholder"></div>
<span v-else>{{ user.username || "Username" }}</span> <a v-else-if="token === Anonymous" class="nav-link" href="/login">Login</a>
<template v-else>
<a href="#" class="btn btn-secondary dropdown-toggle" role="button"
data-bs-toggle="dropdown">{{ token.username || "Username" }}</a>
<ul class="dropdown-menu dropdown-menu-end">
<li><a href="#" class="dropdown-item">Logout</a></li>
</ul>
</template>
</li>
</template> </template>
<style scoped> <style scoped>
.placeholder { .placeholder {
display: inline-block; display: inline-block;
width: 2em; width: 2em;
height: 1em; }
background: gray;
}
</style> </style>
+8 -6
View File
@@ -1,5 +1,6 @@
--- ---
import '../styles/app.css' import '../styles/app.scss'
import TopNav from '../components/TopNav.astro' import TopNav from '../components/TopNav.astro'
const {title} = Astro.props const {title} = Astro.props
@@ -13,21 +14,22 @@ const {title} = Astro.props
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/> <link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
<meta name="generator" content={Astro.generator}/> <meta name="generator" content={Astro.generator}/>
<title>Neon Vertigo</title> <title>Neon Vertigo</title>
<script src="../components/scripts/user_store.js"></script> <script src="../components/scripts/load_bootstrap.js"></script>
</head> </head>
<body> <body>
<header> <header>
<TopNav /> <TopNav />
</header> </header>
<h1>{title}</h1> <main class="container">
<slot/> <h1>{title}</h1>
<slot/>
</main>
{import.meta.env.DEV && {import.meta.env.DEV &&
<script> <script>
import {logger} from '@nanostores/logger' import {logger} from '@nanostores/logger'
import {$user} from "../components/stores/user";
let _destroy = logger({user: $user}) let _destroy = logger({})
</script> </script>
} }
</body> </body>
+11
View File
@@ -0,0 +1,11 @@
---
import Layout from '../layouts/Layout.astro';
import Auctions from '../components/auctions/Index.vue'
---
<Layout title="Auctions">
<Auctions client:load />
<script src="../components/lib/check_user.js"></script>
</Layout>
-8
View File
@@ -1,8 +0,0 @@
---
import Layout from "../../layouts/Layout.astro";
import AuctionShow from "../../components/auctions/Show.vue"
---
<Layout title="See auction">
<AuctionShow client:only />
</Layout>
-8
View File
@@ -1,8 +0,0 @@
---
import Layout from "../../layouts/Layout.astro";
import AuctionsIndex from '../../components/auctions/Index.vue'
---
<Layout title="Auctions">
<AuctionsIndex client:load />
</Layout>
-14
View File
@@ -1,14 +0,0 @@
@layer reset, base, components;
@layer reset {
html, body {
margin: 0;
min-height: 100%;
}
}
@layer base {
body {
font-family: Optima, Candara, 'Noto Sans', source-sans-pro, sans-serif;
}
}
+7
View File
@@ -0,0 +1,7 @@
@import "bootstrap/scss/bootstrap";
/* Minor adjustments */
.card-body > p:last-child {
margin-bottom: 0;
}