You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.8 KiB
121 lines
2.8 KiB
|
4 years ago
|
<template>
|
||
|
|
<q-card bordered class="mb-4" flat>
|
||
|
|
<q-card-section>
|
||
|
|
<q-form
|
||
|
|
class="q-gutter-md"
|
||
|
|
>
|
||
|
|
<q-input
|
||
|
|
v-model="content"
|
||
|
|
:error="v$.content.$error"
|
||
|
4 years ago
|
:label="textPlaceholder"
|
||
|
4 years ago
|
autogrow
|
||
|
|
/>
|
||
|
|
|
||
|
|
<div class="row justify-between mt-0">
|
||
|
|
<q-file
|
||
|
|
v-model="attachment"
|
||
|
|
:label="$t('File upload')"
|
||
|
|
accept="image/*"
|
||
|
|
clearable
|
||
|
|
dense
|
||
|
|
@change="v$.attachment.$touch()"
|
||
|
|
>
|
||
|
|
<template v-slot:prepend>
|
||
|
|
<q-icon name="attach_file" />
|
||
|
|
</template>
|
||
|
|
</q-file>
|
||
|
|
|
||
|
|
<q-btn
|
||
|
|
:label="$t('Post')"
|
||
|
|
icon="send"
|
||
|
|
@click="sendPost"
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
</q-form>
|
||
|
|
</q-card-section>
|
||
|
|
</q-card>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script>
|
||
|
4 years ago
|
import {inject, onMounted, reactive, toRefs, watch} from "vue";
|
||
|
4 years ago
|
import {useStore} from "vuex";
|
||
|
4 years ago
|
import {MESSAGE_REL_USER_TYPE_TO, MESSAGE_TYPE_WALL} from "../message/constants";
|
||
|
4 years ago
|
import useVuelidate from "@vuelidate/core";
|
||
|
|
import {required} from "@vuelidate/validators";
|
||
|
4 years ago
|
import {useI18n} from "vue-i18n";
|
||
|
4 years ago
|
|
||
|
|
export default {
|
||
|
4 years ago
|
name: "WallPostForm",
|
||
|
4 years ago
|
setup() {
|
||
|
|
const user = inject('social-user');
|
||
|
|
|
||
|
4 years ago
|
const store = useStore();
|
||
|
4 years ago
|
const {t} = useI18n();
|
||
|
4 years ago
|
|
||
|
|
const currentUser = store.getters['security/getUser'];
|
||
|
|
|
||
|
|
const postState = reactive({
|
||
|
|
content: '',
|
||
|
|
attachment: null,
|
||
|
4 years ago
|
textPlaceholder: '',
|
||
|
4 years ago
|
});
|
||
|
|
|
||
|
4 years ago
|
function showTextPlaceholder() {
|
||
|
|
postState.textPlaceholder = currentUser['@id'] === user.value['@id']
|
||
|
4 years ago
|
? t('What are you thinking about?')
|
||
|
4 years ago
|
: t('Write something to {0}', [user.value.fullName]);
|
||
|
4 years ago
|
}
|
||
|
|
|
||
|
4 years ago
|
const v$ = useVuelidate({
|
||
|
|
content: {required},
|
||
|
|
}, postState);
|
||
|
|
|
||
|
|
async function sendPost() {
|
||
|
|
v$.value.$touch();
|
||
|
|
|
||
|
|
if (v$.value.$invalid) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const messagePayload = {
|
||
|
|
title: 'Post',
|
||
|
|
content: postState.content,
|
||
|
|
msgType: MESSAGE_TYPE_WALL,
|
||
|
4 years ago
|
sender: currentUser['@id'],
|
||
|
4 years ago
|
receivers: [
|
||
|
|
{
|
||
|
4 years ago
|
receiver: user.value['@id'],
|
||
|
4 years ago
|
receiverType: MESSAGE_REL_USER_TYPE_TO
|
||
|
4 years ago
|
}
|
||
|
|
]
|
||
|
|
};
|
||
|
|
|
||
|
|
await store.dispatch('message/create', messagePayload);
|
||
|
|
|
||
|
|
if (postState.attachment) {
|
||
|
|
const message = store.state.message.created;
|
||
|
|
const attachmentPayload = {
|
||
|
|
messageId: message.id,
|
||
|
|
file: postState.attachment
|
||
|
|
};
|
||
|
|
|
||
|
|
await store.dispatch('messageattachment/createWithFormData', attachmentPayload);
|
||
|
|
}
|
||
|
|
|
||
|
|
postState.content = '';
|
||
|
|
postState.attachment = null;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
watch(() => user.value, () => showTextPlaceholder())
|
||
|
4 years ago
|
|
||
|
4 years ago
|
onMounted(showTextPlaceholder);
|
||
|
4 years ago
|
|
||
|
4 years ago
|
return {
|
||
|
|
...toRefs(postState),
|
||
|
|
sendPost,
|
||
|
|
v$
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|