add parent navigation

This commit is contained in:
Yisroel Baum 2026-06-22 10:04:58 +03:00
parent 3a9116dc3f
commit efc424183a
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 125 additions and 8 deletions

View file

@ -55,6 +55,9 @@ class ElementController
$result->getChildElements(), $result->getChildElements(),
), ),
'element' => $this->buildElementPayload($element), 'element' => $this->buildElementPayload($element),
'parentElement' => $this->buildElementSummaryPayload(
$element->getParentElement(),
),
'siblingElements' => $this->buildElementSummaryPayloads( 'siblingElements' => $this->buildElementSummaryPayloads(
$result->getSiblingElements(), $result->getSiblingElements(),
), ),
@ -328,16 +331,35 @@ class ElementController
{ {
$payloads = []; $payloads = [];
foreach ($elements as $element) { foreach ($elements as $element) {
$payloads[] = [ $payload = $this->buildElementSummaryPayload($element);
'id' => $element->getId(), if ($payload !== null) {
'title' => $element->getTitle(), $payloads[] = $payload;
'description' => $element->getDescription(), }
];
} }
return $payloads; return $payloads;
} }
/**
* @return array{
* id: int,
* title: string,
* description: string,
* }|null
*/
private function buildElementSummaryPayload(?Element $element): ?array
{
if ($element === null) {
return null;
}
return [
'id' => $element->getId(),
'title' => $element->getTitle(),
'description' => $element->getDescription(),
];
}
private function storageUrl(?string $path, string $folderPrefix): ?string private function storageUrl(?string $path, string $folderPrefix): ?string
{ {
if ($path === null) { if ($path === null) {

View file

@ -0,0 +1,57 @@
<script setup lang="ts">
import { ArrowUp as ArrowUpIcon } from 'lucide-vue-next'
import type { ChildElement } from '@/stores/elements'
type ElementRouteName = 'element' | 'admin-element'
interface Props {
dataCy: string
parentElement: ChildElement
routeName: ElementRouteName
}
defineProps<Props>()
</script>
<template>
<RouterLink
:to="{
name: routeName,
params: { id: parentElement.id },
}"
class="element-parent-link"
:data-cy="dataCy"
>
<ArrowUpIcon :size="16" aria-hidden="true" />
<span>Parent: {{ parentElement.title }}</span>
</RouterLink>
</template>
<style scoped>
.element-parent-link {
display: inline-flex;
align-items: center;
gap: 0.35rem;
min-height: 2.2rem;
padding: 0.35rem 0;
color: var(--color-slate);
font-family: var(--font-sans);
font-size: 0.9rem;
font-weight: 600;
line-height: 1.25;
text-decoration: none;
}
.element-parent-link:hover,
.element-parent-link:focus-visible {
color: var(--color-text);
text-decoration: underline;
text-underline-offset: 0.18em;
}
.element-parent-link:focus-visible {
border-radius: 4px;
outline: 3px solid rgb(61 78 93 / 24%);
outline-offset: 3px;
}
</style>

View file

@ -20,6 +20,7 @@ type ElementFileType = 'iconImage' | 'shortPdf' | 'longPdf'
interface ElementResponse { interface ElementResponse {
element: Element element: Element
childElements: ChildElement[] childElements: ChildElement[]
parentElement: ChildElement | null
siblingElements: ChildElement[] siblingElements: ChildElement[]
} }
@ -63,6 +64,7 @@ const ELEMENT_UPDATE_URL = `${API_BASE_URL}/api/element/update`
export const useElementsStore = defineStore('elements', () => { export const useElementsStore = defineStore('elements', () => {
const element = ref<Element | null>(null) const element = ref<Element | null>(null)
const childElements = ref<ChildElement[]>([]) const childElements = ref<ChildElement[]>([])
const parentElement = ref<ChildElement | null>(null)
const siblingElements = ref<ChildElement[]>([]) const siblingElements = ref<ChildElement[]>([])
const isLoading = ref(false) const isLoading = ref(false)
const error = ref<string | null>(null) const error = ref<string | null>(null)
@ -77,6 +79,7 @@ export const useElementsStore = defineStore('elements', () => {
async function fetchElement(elementId: string): Promise<void> { async function fetchElement(elementId: string): Promise<void> {
element.value = null element.value = null
childElements.value = [] childElements.value = []
parentElement.value = null
siblingElements.value = [] siblingElements.value = []
error.value = null error.value = null
saveError.value = null saveError.value = null
@ -101,9 +104,11 @@ export const useElementsStore = defineStore('elements', () => {
const data: ElementResponse = await response.json() const data: ElementResponse = await response.json()
element.value = data.element element.value = data.element
childElements.value = data.childElements childElements.value = data.childElements
parentElement.value = data.parentElement
siblingElements.value = data.siblingElements siblingElements.value = data.siblingElements
} catch { } catch {
childElements.value = [] childElements.value = []
parentElement.value = null
siblingElements.value = [] siblingElements.value = []
error.value = 'Network error - could not load element' error.value = 'Network error - could not load element'
} finally { } finally {
@ -451,6 +456,7 @@ export const useElementsStore = defineStore('elements', () => {
return { return {
element, element,
childElements, childElements,
parentElement,
siblingElements, siblingElements,
isLoading, isLoading,
error, error,

View file

@ -6,6 +6,7 @@ import {
ChevronUp as ChevronUpIcon, ChevronUp as ChevronUpIcon,
} from 'lucide-vue-next' } from 'lucide-vue-next'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import ElementParentLink from '@/components/ElementParentLink.vue'
import ElementSiblingNavigation from '@/components/ElementSiblingNavigation.vue' import ElementSiblingNavigation from '@/components/ElementSiblingNavigation.vue'
import RichTextEditor from '@/components/RichTextEditor.vue' import RichTextEditor from '@/components/RichTextEditor.vue'
import SiteHeader from '@/components/SiteHeader.vue' import SiteHeader from '@/components/SiteHeader.vue'
@ -30,6 +31,7 @@ const elementsStore = useElementsStore()
const { const {
element, element,
childElements, childElements,
parentElement,
siblingElements, siblingElements,
isLoading, isLoading,
error, error,
@ -352,6 +354,12 @@ function resetInput(changeEvent: Event): void {
<SiteHeader /> <SiteHeader />
<main class="admin-element-page__main" data-cy="admin-element-page"> <main class="admin-element-page__main" data-cy="admin-element-page">
<header class="admin-element-page__header"> <header class="admin-element-page__header">
<ElementParentLink
v-if="parentElement !== null"
:parent-element="parentElement"
data-cy="admin-parent-link"
route-name="admin-element"
/>
<h1 class="admin-element-page__heading">Edit Element</h1> <h1 class="admin-element-page__heading">Edit Element</h1>
</header> </header>
@ -730,7 +738,7 @@ function resetInput(changeEvent: Event): void {
} }
.admin-element-page__heading { .admin-element-page__heading {
margin: 0; margin: 0.35rem 0 0;
color: #2c2c2c; color: #2c2c2c;
font-family: var(--font-serif); font-family: var(--font-serif);
font-size: 2rem; font-size: 2rem;

View file

@ -2,6 +2,7 @@
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { computed, watch } from 'vue' import { computed, watch } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import ElementParentLink from '@/components/ElementParentLink.vue'
import ElementSiblingNavigation from '@/components/ElementSiblingNavigation.vue' import ElementSiblingNavigation from '@/components/ElementSiblingNavigation.vue'
import SiteHeader from '@/components/SiteHeader.vue' import SiteHeader from '@/components/SiteHeader.vue'
import { useElementsStore } from '@/stores/elements' import { useElementsStore } from '@/stores/elements'
@ -10,8 +11,14 @@ type TimestampPart = string | undefined
const route = useRoute() const route = useRoute()
const elementsStore = useElementsStore() const elementsStore = useElementsStore()
const { element, childElements, siblingElements, isLoading, error } = const {
storeToRefs(elementsStore) element,
childElements,
parentElement,
siblingElements,
isLoading,
error,
} = storeToRefs(elementsStore)
const youtubeIframeAllow = [ const youtubeIframeAllow = [
'accelerometer', 'accelerometer',
@ -221,6 +228,17 @@ function isShortYoutubeHost(hostname: string): boolean {
data-cy="element-icon" data-cy="element-icon"
/> />
<div
v-if="parentElement !== null"
class="element-page__parent-navigation"
>
<ElementParentLink
:parent-element="parentElement"
data-cy="element-parent-link"
route-name="element"
/>
</div>
<h1 class="element-page__heading"> <h1 class="element-page__heading">
{{ element.title }} {{ element.title }}
</h1> </h1>
@ -335,6 +353,12 @@ function isShortYoutubeHost(hostname: string): boolean {
object-fit: contain; object-fit: contain;
} }
.element-page__parent-navigation {
display: flex;
justify-content: center;
margin: 0 0 0.5rem;
}
.element-page__heading { .element-page__heading {
margin: 0; margin: 0;
color: #2c2c2c; color: #2c2c2c;