Skip to content

Commit

Permalink
Merge branch '61-content-component-profile-view' into 69-deduplicate-…
Browse files Browse the repository at this point in the history
…text-windwos
  • Loading branch information
Lev Z Király authored and Lev Z Király committed Nov 28, 2023
2 parents e47aab7 + a262b27 commit a2fa6e9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
36 changes: 36 additions & 0 deletions components/profile-window-content.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script lang="ts" setup>
interface Props {
params: ProfileWindowItem["params"];
}
const props = defineProps<Props>();
const { params } = toRefs(props);
const { data, isPending, isPlaceholderData } = useProfileById(params);
const openNewWindowFromAnchor = useAnchorClickHandler();
const isLoading = computed(() => {
return isPending.value || isPlaceholderData.value;
});
</script>

<template>
<div
class="relative isolate grid h-full w-full overflow-auto"
:class="{ 'opacity-50 grayscale': isLoading }"
>
<!-- eslint-disable-next-line vue/no-v-html, vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
<div v-if="data" class="prose max-w-3xl p-8" @click="openNewWindowFromAnchor" v-html="data" />

<Centered v-if="isLoading">
<LoadingIndicator />
</Centered>
</div>
</template>

<style>
/* stylelint-disable-next-line selector-class-pattern */
.tbHeader {
margin: 0;
}
</style>
4 changes: 2 additions & 2 deletions components/text-window-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const props = defineProps<Props>();
const { params } = toRefs(props);
const { data, isPending, isPlaceholderData } = useTextById(params);
const onClick = useAnchorClickHandler();
const openNewWindowFromAnchor = useAnchorClickHandler();
const isLoading = computed(() => {
return isPending.value || isPlaceholderData.value;
Expand All @@ -20,7 +20,7 @@ const isLoading = computed(() => {
:class="{ 'opacity-50 grayscale': isLoading }"
>
<!-- eslint-disable-next-line vue/no-v-html, vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
<div v-if="data" class="prose max-w-3xl p-8" @click="onClick" v-html="data" />
<div v-if="data" class="prose max-w-3xl p-8" @click="openNewWindowFromAnchor" v-html="data" />

<Centered v-if="isLoading">
<LoadingIndicator />
Expand Down
1 change: 1 addition & 0 deletions components/window-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ const props = defineProps<Props>();
<template>
<GeoMapWindowContent v-if="props.item.kind === 'geo-map'" :params="props.item.params" />
<TextWindowContent v-if="props.item.kind === 'text'" :params="props.item.params" />
<ProfileWindowContent v-if="props.item.kind === 'profile'" :params="props.item.params" />
<pre v-else>{{ props }}</pre>
</template>
4 changes: 2 additions & 2 deletions composables/use-anchor-click-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useAnchorClickHandler() {
/**
* Intercept anchor clicks to open window instead of navigating.
*/
function onClick(event: MouseEvent) {
function openNewWindowFromAnchor(event: MouseEvent) {
const element = event.target;

if (element instanceof HTMLAnchorElement) {
Expand All @@ -31,5 +31,5 @@ export function useAnchorClickHandler() {
}
}

return onClick;
return openNewWindowFromAnchor;
}
16 changes: 16 additions & 0 deletions composables/use-profile-by-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useQuery } from "@tanstack/vue-query";

export function useProfileById(params: MaybeRef<{ id: string }>, options?: { enabled?: boolean }) {
const api = useApiClient();

return useQuery({
enabled: options?.enabled,
queryKey: ["get-profile-by-id", params] as const,
async queryFn({ queryKey: [, params] }) {
const response = await api.vicav.getProfile(params, {
headers: { accept: "application/xml" },
});
return response.text();
},
});
}
8 changes: 8 additions & 0 deletions stores/use-windows-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export interface TextWindowItem extends WindowItemBase {
};
}

export interface ProfileWindowItem extends WindowItemBase {
kind: "profile";
params: {
id: string;
};
}

export type WindowItem =
| BibliographyQueryWindowItem
| CorpusQueryWindowItem
Expand All @@ -75,6 +82,7 @@ export type WindowItem =
| DictionaryEntryWindowItem
| DictionaryQueryWindowItem
| GeoMapWindowItem
| ProfileWindowItem
| SampleTextWindowItem
| TextWindowItem;

Expand Down
1 change: 1 addition & 0 deletions utils/is-window-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const windowTypeMap: Record<WindowType, WindowItemKind> = {
SampleText: "sample-text",
Text: "text",
WMap: "geo-map",
Profile: "profile",
};

export function isWindowType(value: string | undefined): value is WindowType {
Expand Down

0 comments on commit a2fa6e9

Please sign in to comment.