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

feat: Collection Edit: Support Name Update and Description Update #11199

Merged
merged 5 commits into from
Dec 4, 2024
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
42 changes: 36 additions & 6 deletions components/collection/EditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@
class="flex flex-col gap-6"
@submit.prevent
>
<NeoField
:label="$t('mint.collection.name.label')"
required
:error="!name"
>
<NeoInput
v-model="name"
required
:placeholder="$t('mint.collection.name.placeholder')"
/>
</NeoField>

<!-- collection description -->
<NeoField :label="$t('mint.collection.description.label')">
<NeoInput
v-model="description"
type="textarea"
has-counter
maxlength="1000"
height="10rem"
:placeholder="$t('mint.collection.description.placeholder')"
/>
</NeoField>
<CollectionEditSection :title="$t('edit.collection.image.label')">
<FormLogoField
v-model:file="image"
Expand Down Expand Up @@ -131,6 +154,8 @@ const props = defineProps<{

const isModalActive = useVModel(props, 'modelValue')

const name = ref<string>()
const description = ref<string>()
const image = ref<File>()
const banner = ref<File>()
const imageUrl = ref<string>()
Expand All @@ -142,18 +167,21 @@ const max = ref<number | null>(null)

const disabled = computed(() => {
const hasImage = imageUrl.value
const isNameFilled = Boolean(name.value)

const hasImagechanged = (!imageUrl.value && Boolean(props.collection?.image)) || Boolean(image.value)
const hasBannerChanged = (!bannerUrl.value && Boolean(props.collection?.banner)) || Boolean(banner.value)
const hasMaxChanged = max.value !== props.collection?.max
const nameChanged = props.collection.name !== name.value
const descriptionChanged = props.collection.description !== description.value
const hasImageChanged = (!imageUrl.value && Boolean(props.collection.image)) || Boolean(image.value)
const hasBannerChanged = (!bannerUrl.value && Boolean(props.collection.banner)) || Boolean(banner.value)
const hasMaxChanged = max.value !== props.collection.max

return !hasImage || (!hasImagechanged && !hasBannerChanged && !hasMaxChanged)
return !hasImage || !isNameFilled || (!nameChanged && !descriptionChanged && !hasImageChanged && !hasBannerChanged && !hasMaxChanged)
})

const editCollection = async () => {
emit('submit', {
name: props.collection.name,
description: props.collection.description,
name: name.value,
description: description.value,
image: image.value || props.collection.image,
imageType: props.collection.imageType,
banner: bannerUrl.value ? banner.value || props.collection.banner : undefined,
Expand All @@ -163,6 +191,8 @@ const editCollection = async () => {

watch(isModalActive, (value) => {
if (value && props.collection) {
name.value = props.collection.name
description.value = props.collection.description
imageUrl.value = sanitizeIpfsUrl(props.collection.image)
bannerUrl.value = props.collection.banner && sanitizeIpfsUrl(props.collection.banner)
image.value = undefined
Expand Down
12 changes: 6 additions & 6 deletions components/collection/HeroButtonEditCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
/>

<CollectionEditModal
v-if="collectinoMetadata"
v-if="collectionMetadata"
v-model="isModalActive"
:collection="collectinoMetadata"
:collection="collectionMetadata"
:min="collection.nftCount"
@submit="editCollection"
/>
Expand All @@ -37,7 +37,7 @@ const route = useRoute()

const isModalActive = ref(false)

const collectinoMetadata = computed(() =>
const collectionMetadata = computed(() =>
props.collection
? {
name: props.collection.meta.name,
Expand All @@ -61,7 +61,7 @@ const updateMetadata = (a: UpdateCollection, b: UpdateCollection) => {
const editCollection = async (collection: UpdateCollection) => {
isModalActive.value = false

if (!collectinoMetadata.value) {
if (!collectionMetadata.value) {
return
}

Expand All @@ -70,8 +70,8 @@ const editCollection = async (collection: UpdateCollection) => {
collectionId: route.params.id.toString(),
collection,
update: {
metadata: updateMetadata(collection, collectinoMetadata.value),
max: collection.max !== collectinoMetadata.value.max,
metadata: updateMetadata(collection, collectionMetadata.value),
max: collection.max !== collectionMetadata.value.max,
},
urlPrefix: urlPrefix.value,
successMessage: $i18n.t('edit.collection.success'),
Expand Down
Loading