Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading indicator #18

Merged
merged 3 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SecureSend/ClientApp/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script setup lang="ts">
import { provide, ref } from "vue";
import { RouterView } from "vue-router";
provide("isLoading", ref<boolean>(false));
</script>

<template>
Expand Down
13 changes: 13 additions & 0 deletions SecureSend/ClientApp/src/assets/icons/CheckIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<svg
class="w-6 h-6 text-gray-800 dark:text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"
/>
</svg>
</template>
4 changes: 3 additions & 1 deletion SecureSend/ClientApp/src/components/FileCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<FileIcon></FileIcon>
</div>
<div class="flex-1 min-w-0">
<div class="flex justify-between gap-2">
<div class="flex justify-between gap-2 items-center">
<div class="flex-1 min-w-0">
<p class="truncate">{{ fileName }}</p>
</div>
<p v-if="size">{{ fileSize(size) }}</p>
<slot name="cardMiddle"></slot>
</div>

<slot name="cardBottom"> </slot>
Expand All @@ -23,6 +24,7 @@
<script setup lang="ts">
import { fileSize } from "@/utils/utils";
import FileIcon from "@/assets/icons/FileIcon.vue";

defineProps<{
fileName: string;
size?: number;
Expand Down
29 changes: 25 additions & 4 deletions SecureSend/ClientApp/src/components/FileUploadForm/FileInput.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script setup lang="ts">
import UploadIcon from "@/assets/icons/UploadIcon.vue";
import FileCard from "../FileCard.vue";
import LoadingIndicator from "@/components/LoadingIndicator.vue";
import CheckIcon from "@/assets/icons/CheckIcon.vue";

defineEmits(["onFielsChange"]);

defineProps<{
files: Map<File, number | string>;
files: Map<File, number | string | boolean>;
}>();
</script>

Expand Down Expand Up @@ -40,13 +42,32 @@ defineProps<{
:file-name="key.name"
:size="key.size"
>
<template #cardMiddle>
<LoadingIndicator
v-if="value === 100"
class="w-8 h-5 mr-2"
></LoadingIndicator>
<CheckIcon v-if="value === true"></CheckIcon>
</template>
<template #cardBottom>
<div class="w-full bg-gray-200 rounded-full dark:bg-gray-700">
<div class="w-full bg-gray-200 rounded-full dark:bg-gray-700 mt-2">
<div
class="bg-blue-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
:style="{ width: `${value}%` }"
:style="{
width: `${
value === true ? 100 : typeof value === 'number' ? value : 100
}%`,
}"
>
{{ value }}%
{{
typeof value === "string"
? value
: typeof value === "number"
? value === 100
? "Finishing upload..."
: `${value}%`
: "Upload completed"
}}
</div>
</div>
</template>
Expand Down
22 changes: 22 additions & 0 deletions SecureSend/ClientApp/src/components/LoadingIndicator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<div role="status">
<svg
aria-hidden="true"
v-bind="$attrs"
class="text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span class="sr-only">Loading...</span>
</div>
</template>
31 changes: 25 additions & 6 deletions SecureSend/ClientApp/src/views/FileUploadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
>
<StyledButton
:type="ButtonType.primary"
:disabled="step === 0"
:disabled="step === 0 || isLoading"
@click="step -= 1"
>Back</StyledButton
>
<StyledButton
:type="ButtonType.primary"
:disabled="!meta.valid"
:disabled="!meta.valid || isLoading"
@click="onSubmit()"
>
{{ step < 2 ? "Next" : "Upload" }}
<span class="flex items-center justify-center">
{{ step < 2 ? "Next" : "Upload" }}
<LoadingIndicator
v-if="isLoading && step !== 2"
class="w-5 h-5 ml-2"
></LoadingIndicator>
</span>
</StyledButton>
</div>
</div>
Expand All @@ -59,7 +65,7 @@ import SchemaInput from "@/components/FileUploadForm/SchemaInput.vue";
import { SecureSendService } from "@/services/SecureSendService";
import AuthenticatedSecretKeyCryptography from "@/utils/AuthenticatedSecretKeyCryptography";
import splitFile from "@/utils/splitFile";
import { ref } from "vue";
import { ref, type Ref } from "vue";
import { useForm } from "vee-validate";
import { computed } from "vue";
import FileInput from "@/components/FileUploadForm/FileInput.vue";
Expand All @@ -69,6 +75,8 @@ import { ButtonType } from "@/models/enums/ButtonType";
import ConfirmModalVue from "@/components/ConfirmModal.vue";
import { useConfirmDialog } from "@/utils/composables/useConfirmDialog";
import SimpleInput from "@/components/SimpleInput.vue";
import { inject } from "vue";
import LoadingIndicator from "@/components/LoadingIndicator.vue";

interface IMappedFormValues {
expiryDate: string;
Expand All @@ -84,6 +92,8 @@ const step = ref<number>(0);

let downloadUrl: string;

const isLoading = inject<Ref<boolean>>("isLoading");

const stepZeroschema = {
password(value: string) {
if (value) return true;
Expand Down Expand Up @@ -119,11 +129,15 @@ const { handleSubmit, meta, resetForm } = useForm({

const onSubmit = handleSubmit(async (values: IMappedFormValues) => {
if (step.value === 1) {
isLoading!.value = true;
await SecureSendService.createSecureUpload(uuid);
isLoading!.value = false;
} else if (step.value === 2) {
isLoading!.value = true;
keychain = new AuthenticatedSecretKeyCryptography(values.password, salt);
await keychain.start();
await encryptFile();
isLoading!.value = false;
const { data } = await reveal();
console.log(data);
if (data) {
Expand All @@ -141,7 +155,7 @@ const copyToClipboard = () => navigator.clipboard.writeText(downloadUrl);
const uuid = self.crypto.randomUUID();
const uploadStatus = ref<number>();

const files = ref(new Map<File, number | string>());
const files = ref(new Map<File, number | string | boolean>());

const onFilesChange = (event: any) => {
files.value.clear();
Expand Down Expand Up @@ -177,7 +191,12 @@ const encryptFile = async () => {
chunk,
file.type
);
files.value.set(file, Math.ceil(((num + 1) / totalChunks) * 100));
files.value.set(
file,
num + 1 === totalChunks
? true
: Math.ceil(((num + 1) / totalChunks) * 100)
);
} catch (error) {
files.value.set(file, "Error with uploading file");
throw error;
Expand Down
Loading