Skip to content

Commit

Permalink
Merge pull request #103 from unimal-jp/update-content
Browse files Browse the repository at this point in the history
Add content-type-id props to spearly-content
  • Loading branch information
akoarum authored Aug 17, 2023
2 parents f2fad09 + bf2b08a commit 6278b70
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ $ npm i -S @spearly/nuxt-module
$ yarn add @spearly/nuxt-module
```

####

### Setup

#### nuxt.config.(j|t)s
Expand Down Expand Up @@ -165,9 +163,12 @@ export default {}

### Content

> **Warning**
> `content-type-id` props have been required since v0.10.0
```vue
<template>
<spearly-content id="CONTENT_PUBLIC_UID">
<spearly-content content-type-id="CONTENT_TYPE_ID" id="CONTENT_PUBLIC_UID">
<template v-slot="content">
<header>
<h1>{{ content.values.title }}</h1>
Expand All @@ -192,7 +193,7 @@ Specify a component name for `loading` prop.

```vue
<template>
<spearly-content loading="Loading" id="CONTENT_PUBLIC_UID">
<spearly-content loading="Loading" content-type-id="CONTENT_TYPE_ID" id="CONTENT_PUBLIC_UID">
<template v-slot="content">
<header>
<h1>{{ content.values.title }}</h1>
Expand All @@ -213,7 +214,7 @@ You can preview the draft content by specifying `preview-token` and `id`.

```vue
<template>
<spearly-content :id="$route.query.content_id" :preview-token="$route.query.preview_token">
<spearly-content content-type-id="CONTENT_TYPE_ID" :id="$route.query.content_id" :preview-token="$route.query.preview_token">
<template v-slot="content">
<header>
<h1>{{ content.values.title }}</h1>
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"dependencies": {
"@nuxt/types": "^2.15.7",
"@spearly/sdk-js": "^1.3.3",
"@spearly/sdk-js": "^2.0.0",
"@types/node-fetch": "^2.5.12",
"@vue/compiler-sfc": "^3.2.2",
"node-fetch": "^2.6.1",
Expand Down
10 changes: 8 additions & 2 deletions src/components/spearly-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { Content, GetContentParams } from '@spearly/sdk-js'
export type Props = {
id: string
contentTypeId: string
previewToken?: string
loading?: string
patternName?: 'a' | 'b'
Expand All @@ -35,6 +36,7 @@ export type Data = {
export default Vue.extend<Data, unknown, unknown, Props>({
props: {
id: { type: String, required: true },
contentTypeId: { type: String, required: true },
loading: { type: String },
previewToken: { type: String },
patternName: { type: String as PropType<'a' | 'b'> },
Expand Down Expand Up @@ -69,11 +71,15 @@ export default Vue.extend<Data, unknown, unknown, Props>({
params.patternName = this.$props.patternName
}
const res = await this.$spearly.getContent(this.$props.id, params)
const res = await this.$spearly.getContent(this.$props.contentTypeId, this.$props.id, params)
this.content = res
this.isLoaded = true
} else {
const res = await this.$spearly.getContentPreview(this.$props.id, this.$props.previewToken)
const res = await this.$spearly.getContentPreview(
this.$props.contentTypeId,
this.$props.id,
this.$props.previewToken
)
this.content = res
this.isLoaded = true
}
Expand Down
1 change: 1 addition & 0 deletions src/specs/components/spearly-content.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('SpearlyContent', () => {
pageViewMock = jest.fn()
wrapper = shallowMount(SpearlyContent, {
propsData: {
contentTypeId: 'CONTENT_TYPE_ID',
id: 'CONTENT_ID',
},
mocks: {
Expand Down

0 comments on commit 6278b70

Please sign in to comment.