bugfixing
This commit is contained in:
parent
226d21c6e7
commit
a4526a7caa
@ -31,7 +31,6 @@
|
||||
if (['.mp4', '.webm'].some(format => files[0]?.name?.includes(format)) )
|
||||
{
|
||||
videoInput = URL.createObjectURL(files[0]);
|
||||
console.log(videoInput)
|
||||
}
|
||||
else {
|
||||
|
||||
@ -127,10 +126,11 @@ function handleDrop(e) {
|
||||
|
||||
|
||||
const handleCancel= () => {
|
||||
inputValue = '';
|
||||
showVideo = false;
|
||||
inputValue = '';
|
||||
showVideo = false;
|
||||
}
|
||||
let isHovering = false;
|
||||
|
||||
let isHovering = false;
|
||||
|
||||
|
||||
$: {
|
||||
@ -175,10 +175,10 @@ $: {
|
||||
<span class="mt-2 mb-4 text-gray-200">Drop here to upload</span>
|
||||
{/if}
|
||||
<span class="text-xs sm:text-sm text-gray-400 m-auto mb-5 ">
|
||||
We support jpg/jpeg, png, webp, mp4 and gif.
|
||||
We support jpg/jpeg, png, webp and mp4.
|
||||
</span>
|
||||
<span class="text-xs sm:text-sm text-gray-400 m-auto mb-5 ">
|
||||
File must be smaller than 10MB.
|
||||
File must be smaller than 5MB.
|
||||
</span>
|
||||
<label for={id} class="cursor-pointer rounded-full bg-blue-700 text-sm text-white font-bold w-auto p-3">
|
||||
Choose File
|
||||
@ -193,7 +193,7 @@ $: {
|
||||
{id}
|
||||
name={id}
|
||||
value={inputValue}
|
||||
accept="image/gif"
|
||||
accept="image"
|
||||
on:change={showPreview}
|
||||
on:input={handleInput}
|
||||
autocomplete="off"
|
||||
|
||||
@ -84,18 +84,15 @@ export const createPostImageSchema = z.object({
|
||||
.trim(),
|
||||
tagTopic: z.string(),
|
||||
tagline: z.string(),
|
||||
atLeastOneTag: z
|
||||
.string({ required_error: 'At least 1 tag is required' })
|
||||
.min(1, { message: 'At least 1 tag is required' }),
|
||||
|
||||
atLeastOneTag: z.string({ required_error: 'At least 1 tag is required' }).min(1, { message: 'At least 1 tag is required' }),
|
||||
thumbnail: z
|
||||
.instanceof(File)
|
||||
.superRefine((val, ctx) => {
|
||||
if (val) {
|
||||
if (val.size > 10242880) {
|
||||
if (val.size > 5121440) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: 'File must be less than 10MB',
|
||||
message: 'File must be less than 5MB',
|
||||
});
|
||||
}
|
||||
|
||||
@ -107,12 +104,11 @@ export const createPostImageSchema = z.object({
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
'Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg, gif',
|
||||
'Unsupported file type. Supported formats: jpeg, jpg, png, webp, svg',
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
postType: z.string({ required_error: 'PostType is required.' }),
|
||||
user: z.string({ required_error: 'User is required.' }),
|
||||
});
|
||||
|
||||
@ -83,15 +83,16 @@ export const load = async ({ locals}) => {
|
||||
export const actions = {
|
||||
|
||||
createPostText: async ({ request, locals }) => {
|
||||
|
||||
let newPost = '';
|
||||
const body = await request.formData();
|
||||
const thumb = body.get('thumbnail');
|
||||
body.delete('thumbnail');
|
||||
body.append('user', locals?.user?.id);
|
||||
|
||||
let {formData, errors} = await validateData( body, createPostTextSchema);
|
||||
|
||||
formData.description = addClassesToHtml(marked(formData?.description))
|
||||
console.log(formData)
|
||||
|
||||
|
||||
formData.tagTopic = JSON.parse(formData.tagTopic)[0]
|
||||
formData.upvote = 1
|
||||
@ -114,7 +115,7 @@ export const actions = {
|
||||
|
||||
try {
|
||||
|
||||
let newPost = await locals.pb.collection('posts').create(serialize(formData));
|
||||
newPost = await locals.pb.collection('posts').create(serialize(formData));
|
||||
|
||||
|
||||
// add the tagTopic manually because serialize does not work on arrays
|
||||
@ -126,23 +127,31 @@ export const actions = {
|
||||
//FormData for alreadyVoted
|
||||
|
||||
let formDataAlreadyVoted = new FormData();
|
||||
formDataAlreadyVoted.append('post', newPost.id);
|
||||
formDataAlreadyVoted.append('user', newPost.user);
|
||||
formDataAlreadyVoted.append('post', newPost?.id);
|
||||
formDataAlreadyVoted.append('user', newPost?.user);
|
||||
formDataAlreadyVoted.append('type', 'upvote');
|
||||
//console.log(formDataAlreadyVoted)
|
||||
await locals.pb.collection('alreadyVoted').create(formDataAlreadyVoted);
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log('Error: ', err);
|
||||
error(err.status, err.message);
|
||||
}
|
||||
|
||||
redirect(303, '/community');
|
||||
if(newPost?.id?.length !== 0) {
|
||||
redirect(303, '/community/post/'+newPost?.id);
|
||||
} else {
|
||||
redirect(303, '/community');
|
||||
}
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
createPostImage: async ({ request, locals }) => {
|
||||
let newPost = '';
|
||||
const body = await request.formData();
|
||||
const thumb = body.get('thumbnail');
|
||||
|
||||
@ -150,8 +159,7 @@ export const actions = {
|
||||
body.delete('thumbnail');
|
||||
}
|
||||
|
||||
body.append('user', locals?.user?.id);
|
||||
|
||||
body.append('user', locals?.user?.id);
|
||||
|
||||
let {formData, errors} = await validateData( body, createPostImageSchema);
|
||||
|
||||
@ -204,7 +212,6 @@ export const actions = {
|
||||
type: image.type,
|
||||
lastModified: image.lastModified,
|
||||
});
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
@ -218,7 +225,7 @@ export const actions = {
|
||||
|
||||
try {
|
||||
|
||||
let newPost = await locals.pb.collection('posts').create(serialize(formData));
|
||||
newPost = await locals.pb.collection('posts').create(serialize(formData));
|
||||
|
||||
|
||||
// add the tagTopic manually because serialize does not work on arrays
|
||||
@ -242,12 +249,19 @@ export const actions = {
|
||||
error(err.status, err.message);
|
||||
}
|
||||
|
||||
redirect(303, '/community');
|
||||
|
||||
if(newPost?.id?.length !== 0) {
|
||||
redirect(303, '/community/post/'+newPost?.id);
|
||||
} else {
|
||||
redirect(303, '/community');
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
createPostLink: async ({ request, locals }) => {
|
||||
let newPost = '';
|
||||
const body = await request.formData();
|
||||
const url = body.get('link')
|
||||
let image;
|
||||
@ -295,7 +309,7 @@ export const actions = {
|
||||
|
||||
catch(e)
|
||||
{
|
||||
//console.log(e)
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
|
||||
@ -344,7 +358,7 @@ export const actions = {
|
||||
})
|
||||
|
||||
try {
|
||||
let newPost = await locals.pb.collection('posts').create(serialize(formData));
|
||||
newPost = await locals.pb.collection('posts').create(serialize(formData));
|
||||
|
||||
|
||||
// add the tagTopic manually because serialize does not work on arrays
|
||||
@ -367,7 +381,11 @@ export const actions = {
|
||||
error(err.status, err.message);
|
||||
}
|
||||
|
||||
redirect(303, '/community');
|
||||
if(newPost?.id?.length !== 0) {
|
||||
redirect(303, '/community/post/'+newPost?.id);
|
||||
} else {
|
||||
redirect(303, '/community');
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
@ -336,7 +336,7 @@
|
||||
|
||||
let previousPage : string = base || '/community/';
|
||||
afterNavigate(({from}) => {
|
||||
previousPage = from?.url.pathname || '/community/'
|
||||
previousPage = from?.url.pathname?.startsWith('/community/create-post') ? '/community' : ( from?.url.pathname || '/community')
|
||||
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user