refactor code
This commit is contained in:
parent
de2944775f
commit
f52763c5ed
@ -1,6 +1,6 @@
|
||||
<script lang='ts'>
|
||||
import toast from 'svelte-french-toast';
|
||||
import {userRegion, commentAdded, commentUpdated, screenWidth, replyCommentClicked, editCommentClicked} from '$lib/store';
|
||||
import {commentAdded, commentUpdated, replyCommentClicked, editCommentClicked} from '$lib/store';
|
||||
|
||||
export let data;
|
||||
export let postId = '';
|
||||
@ -10,26 +10,14 @@
|
||||
|
||||
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
|
||||
let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let ref;
|
||||
let isLoaded = true;
|
||||
let imageId = 'image-input';
|
||||
//let imageId = 'image-input';
|
||||
let expandField = commentId?.length !== 0 ? true : false;
|
||||
let imageInput = '';
|
||||
|
||||
/*
|
||||
const showPreview = (event) => {
|
||||
const target = event.target;
|
||||
const files = target.files;
|
||||
@ -40,6 +28,7 @@ userRegion.subscribe(value => {
|
||||
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
async function handleComment(event) {
|
||||
if(isLoaded === true && inputValue?.length !== 0)
|
||||
@ -298,72 +287,6 @@ function handleImageInput(event) {
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!--
|
||||
{:else}
|
||||
|
||||
<section class="border-1 border-t border-slate-800 {imageInput?.length !== 0 ? 'min-h-44' : expandField ? 'min-h-40' : 'min-h-24'} rounded-none fixed z-20 w-full -translate-x-1/2 bg-[#09090B] bottom-0 left-1/2">
|
||||
<div class="w-full m-auto rounded-none mt-5">
|
||||
<textarea
|
||||
on:click={() => expandField = true}
|
||||
class="textarea h-8 max-w-h-20 rounded-lg w-11/12 flex justify-center items-center m-auto placeholder-gray-500 bg-[#333333] text-white"
|
||||
placeholder={placeholder}
|
||||
value={inputValue}
|
||||
on:input={handleInput}
|
||||
/>
|
||||
{#if expandField}
|
||||
<div class="flex flex-col">
|
||||
<div class="flex flex-row items-center mt-4">
|
||||
|
||||
|
||||
<div class="relative">
|
||||
<label for={imageId} class="{imageInput.length !== 0 ? 'hidden' : ''} py-2.5 px-4 text-xs font-medium text-center text-white rounded-lg">
|
||||
<svg class="w-6 h-6 inline-block" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path opacity="0.4" d="M22.0206 16.8198L18.8906 9.49978C18.3206 8.15978 17.4706 7.39978 16.5006 7.34978C15.5406 7.29978 14.6106 7.96978 13.9006 9.24978L12.0006 12.6598C11.6006 13.3798 11.0306 13.8098 10.4106 13.8598C9.78063 13.9198 9.15063 13.5898 8.64063 12.9398L8.42063 12.6598C7.71063 11.7698 6.83063 11.3398 5.93063 11.4298C5.03063 11.5198 4.26063 12.1398 3.75063 13.1498L2.02063 16.5998C1.40063 17.8498 1.46063 19.2998 2.19063 20.4798C2.92063 21.6598 4.19063 22.3698 5.58063 22.3698H18.3406C19.6806 22.3698 20.9306 21.6998 21.6706 20.5798C22.4306 19.4598 22.5506 18.0498 22.0206 16.8198Z" fill="#A6ADBB" ></path> <path d="M6.96984 8.38012C8.83657 8.38012 10.3498 6.86684 10.3498 5.00012C10.3498 3.13339 8.83657 1.62012 6.96984 1.62012C5.10312 1.62012 3.58984 3.13339 3.58984 5.00012C3.58984 6.86684 5.10312 8.38012 6.96984 8.38012Z" fill="#E5E7EB"></path> </g></svg>
|
||||
|
||||
<input class="hidden rounded text-gray-200"
|
||||
type="file"
|
||||
id={imageId}
|
||||
name={imageId}
|
||||
on:input={handleImageInput}
|
||||
on:change={showPreview}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
<label on:click={handleCancel} class="ml-auto py-2.5 px-4 text-xs font-medium text-center text-white rounded-lg mr-3">
|
||||
Cancel
|
||||
</label>
|
||||
{#if isLoaded}
|
||||
<label on:click={handleComment} class="mr-5 bg-purple-600 {inputValue.length !== 0 ? 'opacity-100' : 'opacity-60'} py-2.5 px-4 text-xs font-medium text-center text-white rounded-lg focus:ring-purple-300">
|
||||
Post
|
||||
</label>
|
||||
{:else}
|
||||
<label class="mr-5 bg-purple-600 opacity-60 py-2.5 px-4 text-xs font-medium text-center text-white rounded-lg focus:ring-purple-300">
|
||||
Post
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
|
||||
{#if imageInput.length !== 0}
|
||||
<div class="relative mr-auto -mt-8">
|
||||
<label on:click={() => imageInput = ''} class="text-black w-5 h-5 text-center m-auto flex justify-center items-center rounded-full bg-white absolute top-0 right-0 -mt-1 mr-1">✕</label>
|
||||
<img class="object-contain w-16 h-16 pl-4"
|
||||
alt="Image preview"
|
||||
id="image-preview" />
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
|
||||
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
-->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import {userRegion, cachedPosts, postVote, screenWidth, scrollToComment, postIdDeleted, setCache, getCache, tagList, numberOfUnreadNotification, commentAdded, commentUpdated, commentIdDeleted } from '$lib/store';
|
||||
import {cachedPosts, postVote, screenWidth, scrollToComment, postIdDeleted, setCache, getCache, tagList, numberOfUnreadNotification, commentAdded, commentUpdated, commentIdDeleted } from '$lib/store';
|
||||
import { goto, afterNavigate } from '$app/navigation';
|
||||
import { base } from '$app/paths'
|
||||
|
||||
@ -18,20 +18,7 @@
|
||||
export let data;
|
||||
export let form;
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let fastifyURL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
|
||||
if (usRegion.includes(value)) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
let post = data?.getOnePost;
|
||||
let isScrolled = false;
|
||||
let isLoaded = false;
|
||||
@ -71,7 +58,7 @@
|
||||
|
||||
$postVote = {'id': postId, 'upvote': upvoteCounter[postId], 'downvote': downvoteCounter[postId], 'upvoteClicked': upvoteButtonClicked[postId], 'downvoteClicked': downvoteButtonClicked[postId]};
|
||||
|
||||
const response = await fetch(fastifyURL+'/upvote', {
|
||||
const response = await fetch(data?.fastifyURL+'/upvote', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -107,7 +94,7 @@
|
||||
|
||||
$postVote = {'id': postId, 'upvote': upvoteCounter[postId], 'downvote': downvoteCounter[postId], 'upvoteClicked': upvoteButtonClicked[postId], 'downvoteClicked': downvoteButtonClicked[postId]};
|
||||
|
||||
const response = await fetch(fastifyURL+'/downvote', {
|
||||
const response = await fetch(data?.fastifyURL+'/downvote', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -169,7 +156,7 @@
|
||||
userId: data?.user?.id
|
||||
};
|
||||
|
||||
const response = await fetch(fastifyURL+'/delete-post', {
|
||||
const response = await fetch(data?.fastifyURL+'/delete-post', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -220,7 +207,7 @@
|
||||
const postData = {'postId': data?.getPostId};
|
||||
|
||||
// make the GET request to the endpoint
|
||||
const response = await fetch(fastifyURL+'/get-all-comments', {
|
||||
const response = await fetch(data?.fastifyURL+'/get-all-comments', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -245,7 +232,7 @@
|
||||
} else {
|
||||
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(fastifyURL + '/get-moderators', {
|
||||
const response = await fetch(data?.fastifyURL + '/get-moderators', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -1,19 +1,8 @@
|
||||
import { userRegion, cachedPosts } from '$lib/store';
|
||||
import { cachedPosts } from '$lib/store';
|
||||
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export const load = async ({ params }) => {
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
});
|
||||
export const load = async ({ parent, params }) => {
|
||||
|
||||
|
||||
|
||||
@ -28,7 +17,8 @@ export const load = async ({ params }) => {
|
||||
if (Object.keys(output).length !== 0) {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
const { fastifyURL } = await parent();
|
||||
// If the post is not found in the cache, fetch it from the endpoint
|
||||
const postData = { postId: params.postId };
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user