mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Get imageUpload working for Posts
This commit is contained in:
parent
7d9e6623ea
commit
be70088dd7
@ -12,7 +12,6 @@ const storeUpload = ({ createReadStream, fileLocation }) =>
|
|||||||
|
|
||||||
export default async function fileUpload(params, { file, url }, uploadCallback = storeUpload) {
|
export default async function fileUpload(params, { file, url }, uploadCallback = storeUpload) {
|
||||||
const upload = params[file]
|
const upload = params[file]
|
||||||
|
|
||||||
if (upload) {
|
if (upload) {
|
||||||
const { createReadStream, filename } = await upload
|
const { createReadStream, filename } = await upload
|
||||||
const { name } = path.parse(filename)
|
const { name } = path.parse(filename)
|
||||||
|
|||||||
@ -7,9 +7,16 @@
|
|||||||
ref="el"
|
ref="el"
|
||||||
id="postdropzone"
|
id="postdropzone"
|
||||||
:use-custom-slot="true"
|
:use-custom-slot="true"
|
||||||
|
@vdropzone-thumbnail="thumbnail"
|
||||||
|
@vdropzone-success="vsuccess"
|
||||||
@vdropzone-error="verror"
|
@vdropzone-error="verror"
|
||||||
>
|
>
|
||||||
<div class="dz-message" @mouseover="hover = true" @mouseleave="hover = false">
|
<div
|
||||||
|
v-if="!teaser"
|
||||||
|
class="dz-message"
|
||||||
|
@mouseover="hover = true"
|
||||||
|
@mouseleave="hover = false"
|
||||||
|
>
|
||||||
<div class="hc-attachments-upload-area">
|
<div class="hc-attachments-upload-area">
|
||||||
<div class="hc-drag-marker">
|
<div class="hc-drag-marker">
|
||||||
<ds-icon v-if="hover" name="image" size="xxx-large" />
|
<ds-icon v-if="hover" name="image" size="xxx-large" />
|
||||||
@ -95,11 +102,13 @@ export default {
|
|||||||
slug: null,
|
slug: null,
|
||||||
users: [],
|
users: [],
|
||||||
dropzoneOptions: {
|
dropzoneOptions: {
|
||||||
url: this.vddrop,
|
url: 'https://httpbin.org/post',
|
||||||
maxFilesize: 5.0,
|
maxFilesize: 5.0,
|
||||||
previewTemplate: this.template(),
|
previewTemplate: this.template(),
|
||||||
},
|
},
|
||||||
hover: false,
|
hover: false,
|
||||||
|
error: false,
|
||||||
|
teaser: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -116,6 +125,12 @@ export default {
|
|||||||
this.form.language = this.locale
|
this.form.language = this.locale
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
error() {
|
||||||
|
let that = this
|
||||||
|
setTimeout(function() {
|
||||||
|
that.error = false
|
||||||
|
}, 2000)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
locale() {
|
locale() {
|
||||||
@ -140,6 +155,7 @@ export default {
|
|||||||
title: this.form.title,
|
title: this.form.title,
|
||||||
content: this.form.content,
|
content: this.form.content,
|
||||||
language: this.form.language ? this.form.language.value : this.$i18n.locale(),
|
language: this.form.language ? this.form.language.value : this.$i18n.locale(),
|
||||||
|
imageUpload: this.form.teaserImage,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@ -172,15 +188,31 @@ export default {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
vddrop(file) {
|
verror(file, message) {
|
||||||
this.form.teaserImage = file[0]
|
this.error = true
|
||||||
|
this.$toast.error(file.status, message)
|
||||||
},
|
},
|
||||||
verror(file, message) {},
|
|
||||||
availableLocales() {
|
availableLocales() {
|
||||||
orderBy(locales, 'name').map(locale => {
|
orderBy(locales, 'name').map(locale => {
|
||||||
this.form.languageOptions.push({ label: locale.name, value: locale.code })
|
this.form.languageOptions.push({ label: locale.name, value: locale.code })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
vsuccess(file, response) {
|
||||||
|
this.form.teaserImage = file
|
||||||
|
},
|
||||||
|
thumbnail: function(file, dataUrl) {
|
||||||
|
this.teaser = true
|
||||||
|
var j, len, ref, thumbnailElement
|
||||||
|
if (file.previewElement) {
|
||||||
|
ref = document.querySelectorAll('#postdropzone')
|
||||||
|
for (j = 0, len = ref.length; j < len; j++) {
|
||||||
|
thumbnailElement = ref[j]
|
||||||
|
thumbnailElement.classList.add('image-preview')
|
||||||
|
thumbnailElement.alt = file.name
|
||||||
|
thumbnailElement.style.backgroundImage = 'url("' + dataUrl + '")'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
User: {
|
User: {
|
||||||
@ -215,10 +247,31 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#postdropzone {
|
#postdropzone {
|
||||||
height: 160px;
|
min-height: 160px;
|
||||||
background-color: $background-color-softest;
|
background-color: $background-color-softest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#postdropzone.image-preview {
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-size: 100%;
|
||||||
|
height: 600px;
|
||||||
|
transition: all 0.2s ease-out;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 400px) {
|
||||||
|
#postdropzone.image-preview {
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (min-width: 401px) and (max-width: 960px) {
|
||||||
|
#postdropzone.image-preview {
|
||||||
|
height: 400px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.hc-attachments-upload-area {
|
.hc-attachments-upload-area {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -269,6 +322,7 @@ export default {
|
|||||||
.hc-attachments-upload-area:hover & {
|
.hc-attachments-upload-area:hover & {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.contribution-form-footer {
|
.contribution-form-footer {
|
||||||
border-top: $border-size-base solid $border-color-softest;
|
border-top: $border-size-base solid $border-color-softest;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,26 +3,45 @@ import gql from 'graphql-tag'
|
|||||||
export default () => {
|
export default () => {
|
||||||
return {
|
return {
|
||||||
CreatePost: gql`
|
CreatePost: gql`
|
||||||
mutation($title: String!, $content: String!, $language: String) {
|
mutation($title: String!, $content: String!, $language: String, $imageUpload: Upload) {
|
||||||
CreatePost(title: $title, content: $content, language: $language) {
|
CreatePost(
|
||||||
|
title: $title
|
||||||
|
content: $content
|
||||||
|
language: $language
|
||||||
|
imageUpload: $imageUpload
|
||||||
|
) {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
slug
|
slug
|
||||||
content
|
content
|
||||||
contentExcerpt
|
contentExcerpt
|
||||||
language
|
language
|
||||||
|
imageUpload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
UpdatePost: gql`
|
UpdatePost: gql`
|
||||||
mutation($id: ID!, $title: String!, $content: String!, $language: String) {
|
mutation(
|
||||||
UpdatePost(id: $id, title: $title, content: $content, language: $language) {
|
$id: ID!
|
||||||
|
$title: String!
|
||||||
|
$content: String!
|
||||||
|
$language: String
|
||||||
|
$imageUpload: Upload
|
||||||
|
) {
|
||||||
|
UpdatePost(
|
||||||
|
id: $id
|
||||||
|
title: $title
|
||||||
|
content: $content
|
||||||
|
language: $language
|
||||||
|
imageUpload: $imageUpload
|
||||||
|
) {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
slug
|
slug
|
||||||
content
|
content
|
||||||
contentExcerpt
|
contentExcerpt
|
||||||
language
|
language
|
||||||
|
imageUpload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<transition name="fade" appear>
|
<transition name="fade" appear>
|
||||||
<ds-card
|
<ds-card
|
||||||
v-if="post && ready"
|
v-if="post && ready"
|
||||||
:image="post.image"
|
:image="post.image | proxyApiUrl"
|
||||||
:class="{ 'post-card': true, 'disabled-content': post.disabled }"
|
:class="{ 'post-card': true, 'disabled-content': post.disabled }"
|
||||||
>
|
>
|
||||||
<ds-space margin-bottom="small" />
|
<ds-space margin-bottom="small" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user