Skip to content

Commit

Permalink
Import readItem from plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkvanzanten committed Jul 25, 2023
1 parent 4eaacae commit bd13fea
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 45 deletions.
5 changes: 2 additions & 3 deletions components/Block/CardGroup.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { BlockCardGroup } from '~/types/schema';
import type { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
Expand All @@ -15,7 +14,7 @@ const variants: Record<BlockCardGroup['variant'], ReturnType<typeof resolveCompo
const { data: block } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_cardgroup', props.uuid, {
$readItem('block_cardgroup', props.uuid, {
fields: [
'variant',
{
Expand Down
5 changes: 2 additions & 3 deletions components/Block/Columns.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { ComponentType } from '../../types/schema';
import type { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: block } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_columns', props.uuid, {
$readItem('block_columns', props.uuid, {
fields: [
{
col_one: ['id', 'collection', 'item'],
Expand Down
5 changes: 2 additions & 3 deletions components/Block/FeatureGrid.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: comp } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_featuregrid', props.uuid, {
$readItem('block_featuregrid', props.uuid, {
fields: ['features'],
})
)
Expand Down
5 changes: 2 additions & 3 deletions components/Block/HeroForm.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: block } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_hero_form', props.uuid, {
$readItem('block_hero_form', props.uuid, {
fields: ['heading', 'subheading', 'form'],
})
)
Expand Down
5 changes: 2 additions & 3 deletions components/Block/HeroHeadline.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: block } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_hero_headline', props.uuid, {
$readItem('block_hero_headline', props.uuid, {
fields: ['heading', 'subheading', { button_group: [{ buttons: ['page', 'external_url', 'variant', 'label'] }] }],
})
)
Expand Down
5 changes: 2 additions & 3 deletions components/Block/MediaFullWidth.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: block } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_media_fullwidth', props.uuid, {
$readItem('block_media_fullwidth', props.uuid, {
fields: ['type', 'embed', { video: ['url'], image: ['id', 'title'] }],
})
)
Expand Down
5 changes: 2 additions & 3 deletions components/Block/PageHeader.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import { BlockProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: comp } = useAsyncData(() =>
$directus.request(
readItem('block_pageheader', props.uuid, {
$readItem('block_pageheader', props.uuid, {
fields: [
'preheading',
'heading',
Expand Down
5 changes: 2 additions & 3 deletions components/Block/Showcase.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
import type { BlockProps } from './types';
const timerLength = 5000;
const selectedIdx = ref(0);
const beenClicked = ref(false);
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<BlockProps>();
const { data: block } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('block_showcase', props.uuid, {
$readItem('block_showcase', props.uuid, {
fields: [
{
items: ['heading', 'icon', 'subheading', { image: ['id', 'description'] }],
Expand Down
5 changes: 2 additions & 3 deletions components/Comp/ButtonGroup.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { CompProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<CompProps>();
const { data: comp } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('comp_button_groups', props.uuid, {
$readItem('comp_button_groups', props.uuid, {
fields: [
{
buttons: ['id', 'external_url', 'page', 'variant', 'label'],
Expand Down
5 changes: 2 additions & 3 deletions components/Comp/Heading.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { CompProps } from './types';
const props = defineProps<CompProps>();
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const { data: comp } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('comp_heading', props.uuid, {
$readItem('comp_heading', props.uuid, {
fields: ['heading', 'preheading', 'subheading'],
})
)
Expand Down
5 changes: 2 additions & 3 deletions components/Comp/Media.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { CompProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<CompProps>();
const { data: comp } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('comp_media', props.uuid, {
$readItem('comp_media', props.uuid, {
fields: [
'type',
'embed',
Expand Down
5 changes: 2 additions & 3 deletions components/Comp/Metrics.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { CompProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<CompProps>();
const { data: comp } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('comp_metrics', props.uuid, {
$readItem('comp_metrics', props.uuid, {
fields: ['id', 'items'],
})
)
Expand Down
5 changes: 2 additions & 3 deletions components/Comp/Quote.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { readItem } from '@directus/sdk';
import type { CompProps } from './types';
const { $directus } = useNuxtApp();
const { $directus, $readItem } = useNuxtApp();
const props = defineProps<CompProps>();
const { data: comp } = useAsyncData(props.uuid, () =>
$directus.request(
readItem('comp_quote', props.uuid, {
$readItem('comp_quote', props.uuid, {
fields: ['company_logo', 'person_image', 'person_name', 'person_title', 'quote'],
})
)
Expand Down
6 changes: 2 additions & 4 deletions pages/[...permalink].vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script setup lang="ts">
import { readItems } from '@directus/sdk';
const { $directus } = useNuxtApp();
const { $directus, $readItems } = useNuxtApp();
const { path } = useRoute();
const pageFilter = computed(() => {
Expand All @@ -13,7 +11,7 @@ const { data: page } = await useAsyncData(
path,
() => {
return $directus.request(
readItems('pages', {
$readItems('pages', {
filter: unref(pageFilter),
fields: [
'title',
Expand Down
4 changes: 2 additions & 2 deletions plugins/directus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDirectus, rest, staticToken } from '@directus/sdk';
import { createDirectus, readItem, readItems, rest, staticToken } from '@directus/sdk';
import type { Schema } from '~/types/schema';

export default defineNuxtPlugin(() => {
Expand All @@ -7,5 +7,5 @@ export default defineNuxtPlugin(() => {

const directus = createDirectus<Schema>(directusUrl).with(staticToken(directusToken)).with(rest());

return { provide: { directus } };
return { provide: { directus, readItem, readItems } };
});

0 comments on commit bd13fea

Please sign in to comment.