Skip to content

Commit

Permalink
chore: fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
tewshi committed Dec 5, 2023
1 parent 5ff39a5 commit 8ceb319
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
16 changes: 6 additions & 10 deletions components/testimonials/TestimonialCarousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { Autoplay } from 'swiper/modules';
import { SwiperSlide } from 'swiper/vue';
import { type Swiper, type SwiperOptions } from 'swiper/types';
import { get, set } from '@vueuse/core';
import { useMarkdownContent } from '~/composables/markdown';
import { type TestimonialMarkdownContent } from '~/composables/markdown';
const { loadTestimonials, testimonials } = useMarkdownContent();
defineProps<{
testimonials: TestimonialMarkdownContent[];
}>();
const css = useCssModule();
const swiper = ref<Swiper>();
const pages = ref(get(swiper)?.snapGrid.length ?? 1);
const activeIndex = ref((get(swiper)?.activeIndex ?? 0) + 1);
const pages = computed(() => get(swiper)?.snapGrid.length ?? 1);
const activeIndex = computed(() => (get(swiper)?.activeIndex ?? 0) + 1);
const breakpoints: Record<number, SwiperOptions> = {
// when window width is >= 320px
320: {
Expand Down Expand Up @@ -41,13 +43,7 @@ const breakpoints: Record<number, SwiperOptions> = {
const onSwiperUpdate = (s: Swiper) => {
set(swiper, s);
set(activeIndex, s.activeIndex + 1);
set(pages, s.snapGrid.length);
};
onMounted(async () => {
await loadTestimonials();
});
</script>

<template>
Expand Down
8 changes: 7 additions & 1 deletion components/testimonials/Testimonials.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<script setup lang="ts">
import { useMarkdownContent } from '~/composables/markdown';
const { t } = useI18n();
const css = useCssModule();
const { loadTestimonials, testimonials } = useMarkdownContent();
await loadTestimonials();
</script>

<template>
<div :class="css.testimonials">
<div :class="css.wrapper">
<div :class="css.title">{{ t('home.testimonials.title') }}</div>
<div :class="css.detail">{{ t('home.testimonials.detail') }}</div>
<TestimonialCarousel />
<TestimonialCarousel :testimonials="testimonials" />
</div>
</div>
</template>
Expand Down
64 changes: 36 additions & 28 deletions composables/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,49 @@ export const useMarkdownContent = () => {
* fetches all markdown files within the jobs directory
*/
const loadJobs = async () => {
const path = `/jobs`;
const path = '/jobs';

const { data, prefix } = await loadAll<JobMarkdownContent>(path);

set(
jobs,
data?.map((job) => {
job.link = replacePathPrefix(prefix, job._path);
return job;
}) ?? [],
);
try {
const { data, prefix } = await loadAll<JobMarkdownContent>(path);

set(
jobs,
data?.map((job) => {
job.link = replacePathPrefix(prefix, job._path);
return job;
}) ?? [],
);
} catch (e) {
logger.error(e);
}
};

/**
* fetches all markdown files within the testimonials directory
*/
const loadTestimonials = async () => {
const path = `/testimonials`;

const { data } = await loadAll<TestimonialMarkdownContent>(path, {
visible: true,
});

set(
testimonials,
data.map((testimonial) =>
objectPick(testimonial, [
'avatar',
'visible',
'body',
'username',
'url',
]),
),
);
const path = '/testimonials';

try {
const { data } = await loadAll<TestimonialMarkdownContent>(path, {
visible: true,
});

set(
testimonials,
data.map((testimonial) =>
objectPick(testimonial, [
'avatar',
'visible',
'body',
'username',
'url',
]),
),
);
} catch (e) {
logger.error(e);
}
};

const queryPrefixForJob = async (
Expand Down

0 comments on commit 8ceb319

Please sign in to comment.