Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thooyork committed Jun 13, 2024
1 parent a43f944 commit ba328d3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 42 deletions.
99 changes: 68 additions & 31 deletions client/src/views/PostFormView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,48 @@
</div>

<div class="form-floating mb-3">
<textarea v-model="form.description" style="overflow-y: scroll; height: 6rem" class="form-control"
id="description"></textarea>
<textarea
v-model="form.description"
style="overflow-y: scroll; height: 6rem"
class="form-control"
id="description"
></textarea>
<label for="description">{{ t("posts.form.description") }}</label>
</div>

<div class="form-floating mb-3">
<label for="stringTags">{{ t("posts.form.tags.tags") }}</label>
<vue-tags-input v-model="tag" :tags="tags" :autocomplete-items="tagList"
:placeholder="t('posts.form.tags.enter')" @tags-changed="handleTagsChanged"
@input="handleAutocompletion" @before-adding-tag="checkTag" />
<vue-tags-input
v-model="tag"
:tags="tags"
:autocomplete-items="tagList"
:placeholder="t('posts.form.tags.enter')"
@tags-changed="handleTagsChanged"
@input="handleAutocompletion"
@before-adding-tag="checkTag"
/>
</div>

<div class="mb-3">
<ai-summaries :full-text="form.markdown" :onSetDescription="setDescription" :onAddTag="addTag"
:onSetKeyvisual="setKeyvisual"></ai-summaries>
<ai-summaries
:full-text="form.markdown"
:onSetDescription="setDescription"
:onAddTag="addTag"
:onSetKeyvisual="setKeyvisual"
></ai-summaries>
</div>

<div class="form-floating mb-3">
<textarea v-model="form.markdown" class="form-control" placeholder="Blogpost" ref="markdownArea"
style="height: 40vh; min-height: 200px" aria-describedby="markdownHelp"
v-on:drop="dropMarkdown($event)" required></textarea>
<textarea
v-model="form.markdown"
class="form-control"
placeholder="Blogpost"
ref="markdownArea"
style="height: 40vh; min-height: 200px"
aria-describedby="markdownHelp"
v-on:drop="dropMarkdown($event)"
required
></textarea>
<label for="markdown">{{ t("posts.form.message.label") }}</label>
<div id="markdownHelp" class="form-text">{{ t("posts.form.message.hint") }}</div>
</div>
Expand All @@ -54,12 +75,15 @@
<h2 class="display-6">{{ (form?.title?.length ?? 0) > 0 ? form?.title : t("posts.form.preview.title") }}</h2>
<div class="card flex-md-row mb-4 box-shadow h-md-250">
<div class="card-body" style="max-width: 100%">
<div v-if="loading" style="position: absolute; width: 100%; margin-top: 10vh; text-align: center"
class="text-primary">
<div v-if="loading" style="position: absolute; width: 100%; margin-top: 10vh; text-align: center" class="text-primary">
<loading-spinner />
</div>
<mark-down :markdown="md" v-bind:custom-image-urls="files" @loading="loading = $event"
:style="loading ? 'opacity:0.2' : 'opacity:1'"></mark-down>
<mark-down
:markdown="md"
v-bind:custom-image-urls="files"
@loading="loading = $event"
:style="loading ? 'opacity:0.2' : 'opacity:1'"
></mark-down>
</div>
</div>
</div>
Expand All @@ -68,22 +92,41 @@
<div class="card-body">
<h3>
{{ tc("posts.form.imageupload", Object.keys(files).length) }}
<small class="text-body-secondary f-4" v-if="Object.keys(files).length > 0">({{
convertToHumanReadableFileSize(totalBytesInFiles) }})</small>
<small class="text-body-secondary f-4" v-if="Object.keys(files).length > 0"
>({{ convertToHumanReadableFileSize(totalBytesInFiles) }})</small
>
</h3>
<!-- Hidden file input, used to open the file dialog, when the dropzone is clicked -->
<input style="display: none" type="file" id="file" multiple v-on:change="handleFileChange($event)"
accept=".png, .gif, .jpg, .jpeg, image/png, image/jpeg, image/gif" />
<div id="dropzone" v-on:click="openFileDialog()" v-on:drop="handleFileChange($event)"
v-on:dragover="highlightDropzone($event, true)" v-on:dragleave="highlightDropzone($event, false)"
:class="{ active: dropzoneHighlight }">
<input
style="display: none"
type="file"
id="file"
multiple
v-on:change="handleFileChange($event)"
accept=".png, .gif, .jpg, .jpeg, image/png, image/jpeg, image/gif"
/>
<div
id="dropzone"
v-on:click="openFileDialog()"
v-on:drop="handleFileChange($event)"
v-on:dragover="highlightDropzone($event, true)"
v-on:dragleave="highlightDropzone($event, false)"
:class="{ active: dropzoneHighlight }"
>
<div class="plus"><fa-icon :icon="faUpload"></fa-icon></div>
<span class="label" v-if="dropzoneHighlight">Dateien fallen lassen</span>
<span class="label" v-else>Neue Dateien hierher ziehen oder hier klicken um Dateien auszuwählen</span>
</div>
<Suspense v-for="hash in Object.keys(files)" v-bind:key="hash">
<ImagePreview :value="files[hash]" :hash="hash" @paste="pasteImageFileToMarkdown($event, 'afterCursor')"
@delete="removeImageFileFromMarkdown(files[hash]); delete files[hash]">
<ImagePreview
:value="files[hash]"
:hash="hash"
@paste="pasteImageFileToMarkdown($event, 'afterCursor')"
@delete="
removeImageFileFromMarkdown(files[hash]);
delete files[hash];
"
>
</ImagePreview>
</Suspense>
</div>
Expand Down Expand Up @@ -204,7 +247,6 @@
}
@keyframes shake {
10%,
90% {
transform: scale(0.9) translate3d(-1px, 0, 0);
Expand Down Expand Up @@ -251,8 +293,6 @@ import { computed, onMounted, reactive, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import VueTagsInput from "@sipec/vue3-tags-input";
const tag = ref<string>("");
const tags = ref<{ text: string; tiClasses?: string[] }[]>([]); // vue-tags-input internal format
const md = ref<string | null>(null);
Expand All @@ -279,7 +319,6 @@ const props = defineProps({
},
});
const totalBytesInFiles = computed(() =>
Object.values(files)
.map((it) => it.size)
Expand Down Expand Up @@ -309,7 +348,6 @@ onMounted(async () => {
// ADD already existing attachments to files
processAttachments(resJson.attachments);
}
} catch (e) {
postHasError.value = true;
}
Expand All @@ -321,15 +359,14 @@ onMounted(async () => {
}, 1000);
});
// Function to process attachments and populate the files object
const processAttachments = (attachments: Attachment[]) => {
attachments.forEach((attachment) => {
const blob = new Uint8Array((attachment.file.binaryData as any).data);
const file = new File([blob], attachment.filename, { type: attachment.file.mimeType });
files[attachment.file.sha256] = file;
});
}
};
// Create a computed property to generate URLs for the files
const filesWithUrls = computed(() => {
Expand All @@ -350,7 +387,7 @@ const removeImageFileFromMarkdown = (file: File) => {
setTimeout(() => {
form.markdown = markDownBeforeRemove.replace(strToRemove, "");
}, 0);
}
};
const dropMarkdown = (evt: DragEvent) => {
const items = evt.dataTransfer?.items;
Expand Down
16 changes: 5 additions & 11 deletions server/src/routes/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ router.post(
} else {
return { postId: post.id, attachments: [] };
}


})
.catch((err) => {
throw new InternalServerError(true, "Could not create post " + err);
Expand All @@ -186,7 +184,6 @@ router.post(
},
);


// EDIT EXISTING POST
router.post("/:id(\\d+$)", authMiddleware, multipleFilesUpload, async (req: Request, res: Response, next) => {
const postId = +req.params.id;
Expand Down Expand Up @@ -227,7 +224,6 @@ router.post("/:id(\\d+$)", authMiddleware, multipleFilesUpload, async (req: Requ
// tags: tagsToUseInPost,
})
.then(async (updateResult) => {

manager.getRepository(AttachmentEntity).delete({ post: { id: post.id } });

const attachmentEntities: AttachmentEntity[] = await Promise.all(
Expand Down Expand Up @@ -277,11 +273,11 @@ async function getPersistedTagsForPost(post: PostEntity, bodyJson: PostRequestDt
const alreadySavedTags =
bodyJson.stringTags?.length > 0
? await AppDataSource.manager
.getRepository(TagEntity)
.createQueryBuilder("tagEntity")
.select()
.where("tagEntity.name IN(:...names)", { names: bodyJson.stringTags })
.getMany()
.getRepository(TagEntity)
.createQueryBuilder("tagEntity")
.select()
.where("tagEntity.name IN(:...names)", { names: bodyJson.stringTags })
.getMany()
: await Promise.all([]);
tagsToUseInPost.push(...alreadySavedTags);

Expand Down Expand Up @@ -318,8 +314,6 @@ router.get("/tags/:search", async (req: Request, res: Response, next) => {
.catch(next);
});



// DELETE POST
router.get("/delete/:id(\\d+$)", async (req: Request, res: Response, next) => {
await AppDataSource.manager.transaction(async (manager) => {
Expand Down

0 comments on commit ba328d3

Please sign in to comment.