Skip to content

Commit

Permalink
Added refund policy some adjustment added slider upload logic updated (
Browse files Browse the repository at this point in the history
…#14)

* landing page done

some assets added

some design fix added

Signed-off-by: RajrupDasid <[email protected]>

* contact form is working
some enhacement added

Signed-off-by: RajrupDasid <[email protected]>

* made contactform dynamic

Signed-off-by: RajrupDasid <[email protected]>

* Signup authentication validation added

Signed-off-by: RajrupDasid <[email protected]>

* User authentication hasbeen implemented

user authentication hasbeen applied

some logic hasbeen rectified

Signed-off-by: RajrupDasid <[email protected]>

* Some modifications hasbeen applied

Signed-off-by: RajrupDasid <[email protected]>

* user authentication implemnted and verification added

Signed-off-by: RajrupDasid <[email protected]>

* Group based layout added

default layout changed

some auth logic improvement added

admin navbar added

Signed-off-by: RajrupDasid <[email protected]>

* Added null safety

auth improvement added

some logic changes added

some improvements added

Signed-off-by: RajrupDasid <[email protected]>

* Adapter hasbeen chnged

some other modifications added

Signed-off-by: RajrupDasid <[email protected]>

* addition

Signed-off-by: RajrupDasid <[email protected]>

* Some modifications added

Signed-off-by: RajrupDasid <[email protected]>

* some mitigation added

Signed-off-by: RajrupDasid <[email protected]>

* some adjustment added

Signed-off-by: RajrupDasid <[email protected]>

* more adjustment added

Signed-off-by: RajrupDasid <[email protected]>

* some changes added

Signed-off-by: RajrupDasid <[email protected]>

* adapter modified

Signed-off-by: RajrupDasid <[email protected]>

* worked edited

Signed-off-by: RajrupDasid <[email protected]>

* SEO added

some general improvements added

Signed-off-by: RajrupDasid <[email protected]>

* Static image fetched via cdn

Signed-off-by: RajrupDasid <[email protected]>

* SEO added

sitemap generator added

Signed-off-by: RajrupDasid <[email protected]>

* Added firebase sdk

some modifications added

client side multiple file upload added

Signed-off-by: RajrupDasid <[email protected]>

* batch processing is working

tested with firebase storage

two files hasbeen added simultaniously

Signed-off-by: RajrupDasid <[email protected]>

* added terms and conditions

added privacy policy page

Signed-off-by: RajrupDasid <[email protected]>

* Improved File uploding logic

added proper batch processing and file upload methods

both frontend and backend logics hasbeen refactored

Signed-off-by: RajrupDasid <[email protected]>

* Return and refund policy page added

Signed-off-by: RajrupDasid <[email protected]>

---------

Signed-off-by: RajrupDasid <[email protected]>
  • Loading branch information
rajrupdasofficial authored Jul 5, 2024
1 parent 3af706e commit 8fa441a
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 183 deletions.
4 changes: 3 additions & 1 deletion src/lib/components/ui/footer/+footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@
<a href="/privacy-policy" class="text-gray-500 transition hover:opacity-75"> Privacy Policy </a>
</li>


<li>
<a href="/return-and-refund-policy" class="text-gray-500 transition hover:opacity-75"> Return and Refund Policy</a>
</li>
<li>
<a href="/sitemap.xml" class="text-gray-500 transition hover:opacity-75"> Sitemap </a>
</li>
Expand Down
260 changes: 120 additions & 140 deletions src/routes/(admin)/admin/details/createslider/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
<script lang="ts">
import { files } from '$service-worker';
import { onMount } from 'svelte';
interface CustomRequestInit extends RequestInit {
onprogress?: (event: ProgressEvent<XMLHttpRequestEventTarget>) => void;
}
onMount(async () => {
const response = await fetch('/api/auth/verifyauth', {
credentials: 'include'
});
if (
response.status === 401 ||
response.status === 500 ||
response.status === 404 ||
response.status == 403
) {
if ([401, 500, 404, 403].includes(response.status)) {
window.location.href = '/auth/login';
} else {
const user = response.headers.get('user-status') ?? '';
const parsedata = JSON.parse(user);
const isadmin = parsedata.isadmin;
if (isadmin === false) {
window.location.href = '/';
} else if (isadmin === null) {
if (isadmin === false || isadmin === null) {
window.location.href = '/';
} else {
console.log('Authenticated');
Expand All @@ -33,74 +19,73 @@
});
let sliderFiles: File[] = [];
let uploadProgress: number[] = [];
let uploadedFiles: number = 0;
let uploadProgress: { [key: string]: number } = {};
let isProcessing = false;
let showAlert = false;
let showerroralert=false
let showErrorAlert = false;
const handleFileUpload = async (event: Event) => {
event.preventDefault();
isProcessing=true
showAlert=false
showerroralert=false
const uploadFile = async (file: File, index: number) => {
const formData = new FormData();
sliderFiles.forEach((file, index) => {
formData.append('files', file);
uploadProgress[index] = 0; // Initialize progress for each file
});
formData.append('file', file);
try {
const fetchOptions: CustomRequestInit = {
method: 'POST',
body: formData,
onprogress: (event: ProgressEvent<XMLHttpRequestEventTarget>) => {
if (event.lengthComputable) {
const xhr = event.target as XMLHttpRequest;
const fileIndex = parseInt(xhr.responseURL.split('/').pop() || '0');
uploadProgress[fileIndex] = Math.round((event.loaded / event.total) * 100);
uploadedFiles++;
// Update the progress bar for the corresponding file
sliderFiles = [...sliderFiles];
}
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/admin/details/slider_handel/');
xhr.upload.onprogress = (event) => {
if (event.lengthComputable) {
uploadProgress[index] = Math.round((event.loaded / event.total) * 100);
uploadProgress = { ...uploadProgress };
}
};
return new Promise((resolve, reject) => {
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr.response);
} else {
reject(xhr.statusText);
}
};
xhr.onerror = () => reject(xhr.statusText);
xhr.send(formData);
});
};
const response = await fetch('/api/admin/details/slider_handel/', fetchOptions);
const handleFileUpload = async () => {
isProcessing = true;
showAlert = false;
showErrorAlert = false;
if (response.ok) {
console.log('Files uploaded successfully');
isProcessing=false
showAlert=true
} else {
isProcessing=false
showAlert=false
showerroralert=true
console.error('Error uploading files');
const batchSize = 3; // Adjust this value based on your needs
const batches = [];
for (let i = 0; i < sliderFiles.length; i += batchSize) {
batches.push(sliderFiles.slice(i, i + batchSize));
}
try {
for (const batch of batches) {
await Promise.all(batch.map((file, index) => uploadFile(file, index)));
}
} catch (error) {
isProcessing=false
showAlert=false
showerroralert=true
console.log('Files uploaded successfully');
showAlert = true;
} catch (error) {
console.error('Error uploading files:', error);
}finally{
isProcessing=false
showAlert=false
showerroralert=false
showErrorAlert = true;
} finally {
isProcessing = false;
}
console.log('Uploaded files:', sliderFiles);
};
const handleChange = (event: Event) => {
const input = event.target as HTMLInputElement;
if (input.files) {
sliderFiles = Array.from(input.files);
uploadProgress = new Array(sliderFiles.length).fill(0); // Initialize progress for each file
uploadedFiles = 0;
console.log(sliderFiles);
uploadProgress = {};
sliderFiles.forEach((_, index) => {
uploadProgress[index] = 0;
});
}
};
</script>
Expand All @@ -112,37 +97,61 @@
<p class="mt-4 text-gray-500">Upload Images for Slider</p>
</div>
{#if showAlert}
<div role="alert" class="rounded-xl border border-gray-100 bg-white p-4">
<div class="flex items-start gap-4">
<span class="text-green-600">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</span>
<div role="alert" class="rounded-xl border border-gray-100 bg-white p-4">
<div class="flex items-start gap-4">
<span class="text-green-600">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</span>

<div class="flex-1">
<strong class="block font-medium text-gray-900"> File upload success </strong>
<div class="flex-1">
<strong class="block font-medium text-gray-900">File upload success</strong>
<p class="mt-1 text-sm text-gray-700">Files have been uploaded successfully to firebase</p>
</div>

<p class="mt-1 text-sm text-gray-700">File hasbeen uploaded successfully to firebase</p>
<button
class="text-gray-500 transition hover:text-gray-600"
on:click={() => (showAlert = false)}
>
<span class="sr-only">Dismiss popup</span>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</div>
{/if}

{#if showErrorAlert}
<div role="alert" class="rounded border-s-4 border-red-500 bg-red-50 p-4">
<strong class="block font-medium text-red-800">Error: Something went wrong</strong>
<p class="mt-2 text-sm text-red-700">
There was an error uploading the files. Please try again.
</p>
<button
class="text-gray-500 transition hover:text-gray-600"
on:click={() => (showAlert = false)}
on:click={() => (showErrorAlert = false)}
>
<span class="sr-only">Dismiss popup</span>

<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand All @@ -155,38 +164,7 @@
</svg>
</button>
</div>
</div>
{/if}

<!-- user not found banner -->

{#if showerroralert}
<div role="alert" class="rounded border-s-4 border-red-500 bg-red-50 p-4">
<strong class="block font-medium text-red-800"> Error something not right</strong>

<p class="mt-2 text-sm text-red-700">
Something is not right
</p>
<button
class="text-gray-500 transition hover:text-gray-600"
on:click={() => (showerroralert = false)}
>
<span class="sr-only">Dismiss popup</span>

<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>

{/if}
{/if}

<form class="mx-auto mb-0 mt-8 max-w-md space-y-4">
<div>
Expand Down Expand Up @@ -225,14 +203,14 @@
class="inline-block rounded-lg bg-blue-500 px-5 py-3 text-sm font-medium text-white"
on:click|preventDefault={handleFileUpload}
>
{#if isProcessing}
<div class="flex items-center justify-center">
<div class="mr-2 animate-spin rounded-full border-4 border-t-4 border-gray-200 h-6 w-6"></div>
Processing...
</div>
{:else}
Upload files
{/if}
{#if isProcessing}
<div class="flex items-center justify-center">
<div class="mr-2 animate-spin rounded-full border-4 border-t-4 border-gray-200 h-6 w-6"></div>
Processing...
</div>
{:else}
Upload files
{/if}
</button>
</div>
</form>
Expand All @@ -241,19 +219,21 @@
<!-- Image preview -->
<div class="relative h-64 w-full sm:h-96 lg:h-full lg:w-1/2">
{#each sliderFiles as file, index}
<img
alt=""
src={URL.createObjectURL(file)}
class="absolute inset-0 h-full w-full object-cover"
/>
<div class="absolute bottom-0 left-0 w-full px-4 py-2">
<div class="bg-white rounded-full overflow-hidden">
<div
class="bg-blue-500 h-2 rounded-full w-[{uploadProgress[index]}%]"

></div>
<div class="relative mb-4">
<img
alt=""
src={URL.createObjectURL(file)}
class="h-32 w-full object-cover"
/>
<div class="absolute bottom-0 left-0 w-full px-4 py-2">
<div class="bg-white rounded-full overflow-hidden">
<div
class="bg-blue-500 h-2 rounded-full"
style="width: {uploadProgress[index]}%"
></div>
</div>
</div>
</div>
{/each}
</div>
</section>
</section>
Loading

0 comments on commit 8fa441a

Please sign in to comment.