feat: target my collections importer ui

This commit is contained in:
liyasthomas
2022-01-12 07:41:36 +05:30
parent 6537a51854
commit ffb063ad94

View File

@@ -13,25 +13,10 @@
svg="arrow-left" svg="arrow-left"
@click.native="resetImport" @click.native="resetImport"
/> />
<ButtonSecondary
v-if="mode == 'import_from_my_collections'"
v-tippy="{ theme: 'tooltip' }"
:title="t('action.go_back')"
svg="arrow-left"
@click.native="
() => {
mode = 'import_export'
mySelectedCollectionID = undefined
}
"
/>
</template> </template>
<template #body> <template #body>
<div v-if="importerType !== null" class="flex flex-col"> <div v-if="importerType !== null" class="flex flex-col">
<div class="relative flex pb-6 flex-col px-2"> <div class="flex pb-6 flex-col px-2">
<div
class="absolute top-0 w-0.5 bg-primaryDark left-5 -z-1 bottom-1"
></div>
<div <div
v-for="(step, index) in importerSteps" v-for="(step, index) in importerSteps"
:key="`step-${index}`" :key="`step-${index}`"
@@ -40,9 +25,9 @@
<div v-if="step.name === 'FILE_IMPORT'" class="space-y-4"> <div v-if="step.name === 'FILE_IMPORT'" class="space-y-4">
<p class="flex items-center"> <p class="flex items-center">
<span <span
class="inline-flex items-center justify-center flex-shrink-0 mr-4 rounded-full border-5 border-primary text-secondaryLight" class="inline-flex border-4 border-primary items-center justify-center flex-shrink-0 mr-4 rounded-full text-dividerDark"
:class="{ :class="{
'text-green-500': hasFile, '!text-green-500': hasFile,
}" }"
> >
<i class="material-icons">check_circle</i> <i class="material-icons">check_circle</i>
@@ -51,7 +36,7 @@
{{ t("import.json_description") }} {{ t("import.json_description") }}
</span> </span>
</p> </p>
<p class="flex flex-col ml-11"> <p class="flex flex-col ml-10">
<input <input
id="inputChooseFileToImportFrom" id="inputChooseFileToImportFrom"
ref="inputChooseFileToImportFrom" ref="inputChooseFileToImportFrom"
@@ -66,9 +51,9 @@
<div v-else-if="step.name === 'URL_IMPORT'" class="space-y-4"> <div v-else-if="step.name === 'URL_IMPORT'" class="space-y-4">
<p class="flex items-center"> <p class="flex items-center">
<span <span
class="inline-flex items-center justify-center flex-shrink-0 mr-4 rounded-full border-5 border-primary text-secondaryLight" class="inline-flex border-4 border-primary items-center justify-center flex-shrink-0 mr-4 rounded-full text-dividerDark"
:class="{ :class="{
'text-green-500': hasGist, '!text-green-500': hasGist,
}" }"
> >
<i class="material-icons">check_circle</i> <i class="material-icons">check_circle</i>
@@ -86,11 +71,47 @@
/> />
</p> </p>
</div> </div>
<div
v-else-if="step.name === 'TARGET_MY_COLLECTION'"
class="flex flex-col px-2"
>
<div class="select-wrapper">
<select
type="text"
autocomplete="off"
class="select"
autofocus
@change="
($event) => {
mySelectedCollectionID = $event.target.value
}
"
>
<option
:key="undefined"
:value="undefined"
hidden
disabled
selected
>
{{ t("collection.select") }}
</option>
<option
v-for="(collection, collectionIndex) in myCollections"
:key="`collection-${collectionIndex}`"
:value="collectionIndex"
>
{{ collection.name }}
</option>
</select>
</div>
</div>
</div> </div>
</div> </div>
<ButtonPrimary <ButtonPrimary
:label="t('import.title')" :label="t('import.title')"
:disabled="enableImportButton" :disabled="enableImportButton"
class="mx-2"
@click.native="finishImport" @click.native="finishImport"
/> />
</div> </div>
@@ -104,15 +125,10 @@
:label="t(`${importer.name}`)" :label="t(`${importer.name}`)"
@click.native="importerType = index" @click.native="importerType = index"
/> />
<SmartItem </template>
v-if="collectionsType.type == 'team-collections'" </SmartExpand>
v-tippy="{ theme: 'tooltip' }"
:title="t('action.preserve_current')"
svg="user"
:label="t('import.from_my_collections')"
@click.native="mode = 'import_from_my_collections'"
/>
<hr /> <hr />
<div class="flex flex-col space-y-2">
<SmartItem <SmartItem
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
:title="t('action.download_file')" :title="t('action.download_file')"
@@ -148,55 +164,7 @@
" "
/> />
</span> </span>
</template>
</SmartExpand>
</div> </div>
<div
v-if="mode == 'import_from_my_collections'"
class="flex flex-col px-2"
>
<div class="select-wrapper">
<select
type="text"
autocomplete="off"
class="select"
autofocus
@change="
($event) => {
mySelectedCollectionID = $event.target.value
}
"
>
<option
:key="undefined"
:value="undefined"
hidden
disabled
selected
>
Select Collection
</option>
<option
v-for="(collection, index) in myCollections"
:key="`collection-${index}`"
:value="index"
>
{{ collection.name }}
</option>
</select>
</div>
</div>
</template>
<template #footer>
<div v-if="mode == 'import_from_my_collections'">
<span>
<ButtonPrimary
:disabled="mySelectedCollectionID == undefined"
svg="folder-plus"
:label="t('import.title')"
@click.native="importFromMyCollections"
/>
</span>
</div> </div>
</template> </template>
</SmartModal> </SmartModal>
@@ -312,28 +280,28 @@ const hideModal = () => {
const stepResults = ref<string[]>([]) const stepResults = ref<string[]>([])
const importFromMyCollections = () => { // const importFromMyCollections = () => {
if (props.collectionsType.type !== "team-collections") return // if (props.collectionsType.type !== "team-collections") return
teamUtils // teamUtils
.importFromMyCollections( // .importFromMyCollections(
apolloClient, // apolloClient,
mySelectedCollectionID.value, // mySelectedCollectionID.value,
props.collectionsType.selectedTeam.id // props.collectionsType.selectedTeam.id
) // )
.then((success) => { // .then((success) => {
if (success) { // if (success) {
fileImported() // fileImported()
emit("update-team-collections") // emit("update-team-collections")
} else { // } else {
failedImport() // failedImport()
} // }
}) // })
.catch((e) => { // .catch((e) => {
console.error(e) // console.error(e)
failedImport() // failedImport()
}) // })
} // }
const exportJSON = () => { const exportJSON = () => {
getJSONCollection() getJSONCollection()
@@ -402,13 +370,17 @@ watch(inputChooseGistToImportFrom, (v) => {
}) })
const onFileChange = () => { const onFileChange = () => {
if (!inputChooseFileToImportFrom.value[0]) return if (!inputChooseFileToImportFrom.value[0]) {
hasFile.value = false
return
}
if ( if (
!inputChooseFileToImportFrom.value[0].files || !inputChooseFileToImportFrom.value[0].files ||
inputChooseFileToImportFrom.value[0].files.length === 0 inputChooseFileToImportFrom.value[0].files.length === 0
) { ) {
inputChooseFileToImportFrom.value[0].value = "" inputChooseFileToImportFrom.value[0].value = ""
hasFile.value = false
toast.show(t("action.choose_file").toString()) toast.show(t("action.choose_file").toString())
return return
} }
@@ -419,6 +391,7 @@ const onFileChange = () => {
reader.onload = ({ target }) => { reader.onload = ({ target }) => {
const content = target!.result as string | null const content = target!.result as string | null
if (!content) { if (!content) {
hasFile.value = false
toast.show(t("action.choose_file").toString()) toast.show(t("action.choose_file").toString())
return return
} }
@@ -440,5 +413,6 @@ const resetImport = () => {
hasFile.value = false hasFile.value = false
inputChooseGistToImportFrom.value = "" inputChooseGistToImportFrom.value = ""
hasGist.value = false hasGist.value = false
mySelectedCollectionID.value = undefined
} }
</script> </script>