From ba6bd357e21fa25a9c755688ec0bcafeeab4dcee Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Tue, 26 May 2026 19:51:45 +0300 Subject: [PATCH] fetch element title --- frontend/rabbi_gerzi/src/stores/elements.ts | 50 +++++++++++++++++++ .../rabbi_gerzi/src/views/ElementPage.vue | 46 ++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 frontend/rabbi_gerzi/src/stores/elements.ts diff --git a/frontend/rabbi_gerzi/src/stores/elements.ts b/frontend/rabbi_gerzi/src/stores/elements.ts new file mode 100644 index 0000000..0624751 --- /dev/null +++ b/frontend/rabbi_gerzi/src/stores/elements.ts @@ -0,0 +1,50 @@ +import { ref } from 'vue' +import { defineStore } from 'pinia' + +export interface Element { + id: number + title: string +} + +interface ElementResponse { + element: Element +} + +const API_BASE_URL = import.meta.env.VITE_API_BASE_URL as string + +export const useElementsStore = defineStore('elements', () => { + const element = ref(null) + const isLoading = ref(false) + const error = ref(null) + + async function fetchElement(elementId: string): Promise { + element.value = null + error.value = null + isLoading.value = true + + try { + const encodedElementId = encodeURIComponent(elementId) + const elementUrl = `${API_BASE_URL}/api/elements/${encodedElementId}` + const response = await fetch(elementUrl) + + if (response.status === 404) { + error.value = 'Element not found' + return + } + + if (!response.ok) { + error.value = 'Could not load element' + return + } + + const data: ElementResponse = await response.json() + element.value = data.element + } catch { + error.value = 'Network error - could not load element' + } finally { + isLoading.value = false + } + } + + return { element, isLoading, error, fetchElement } +}) diff --git a/frontend/rabbi_gerzi/src/views/ElementPage.vue b/frontend/rabbi_gerzi/src/views/ElementPage.vue index 22191ce..c222cef 100644 --- a/frontend/rabbi_gerzi/src/views/ElementPage.vue +++ b/frontend/rabbi_gerzi/src/views/ElementPage.vue @@ -1,9 +1,13 @@ @@ -46,6 +72,22 @@ const elementId = computed(() => { text-align: center; } +.element-page__status { + max-width: 48rem; + margin: 0 auto; + padding: 1rem 1.25rem; + color: var(--color-text-muted); + background: var(--color-white); + border: 1px solid var(--color-border); + border-radius: 8px; + font-size: 0.95rem; +} + +.element-page__status--error { + color: #7c2d2d; + border-color: #e5b8b8; +} + @media (max-width: 768px) { .element-page__main { padding: 3rem 1rem;