This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/the-grid' of github.com:lukso-network/universalpro…
…file.cloud into fix/wallet-connect-improvements
- Loading branch information
Showing
8 changed files
with
221 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<script setup lang="ts"> | ||
type Props = { | ||
type: GridWidgetType | ||
id?: string | ||
properties?: ElfsightWidgetProperties | ||
width?: number | ||
height?: number | ||
} | ||
const props = defineProps<Props>() | ||
const { formatMessage } = useIntl() | ||
const { closeModal, showModal } = useModal() | ||
const { addGridWidget, updateGridWidget, getGridById } = useGrid() | ||
const { tempGrid, selectedGridId } = storeToRefs(useGridStore()) | ||
const isEdit = computed(() => !!props.id) | ||
const widgetType = computed(() => props.type) | ||
const schemaMap = WIDGET_SCHEMA_MAP[widgetType.value] | ||
const { | ||
inputValues, | ||
canSubmit, | ||
getFieldErrorMessage, | ||
handleFieldChange, | ||
handleFormErrors, | ||
} = useForm(schemaMap?.input, { | ||
input: props.properties?.id, | ||
}) | ||
const isInstructionsVisible = ref(false) | ||
const handleSave = async () => { | ||
if (!canSubmit.value) { | ||
return | ||
} | ||
try { | ||
const inputParse = await schemaMap?.input?.safeParseAsync(inputValues.value) | ||
const properties = await schemaMap?.output?.parseAsync(inputParse?.data) | ||
if (isEdit.value) { | ||
updateGridWidget(props.id, { | ||
properties, | ||
w: props.width, | ||
h: props.height, | ||
}) | ||
} else { | ||
const newWidget: GridWidgetWithoutCords = createWidgetObject({ | ||
type: inputParse?.data?.widgetType, // widget type is not based on selection but on the parsing result | ||
properties, | ||
w: props.width, | ||
h: props.height, | ||
}) | ||
addGridWidget( | ||
newWidget, | ||
getGridById(tempGrid.value, selectedGridId.value) | ||
) | ||
} | ||
handleCancel() | ||
} catch (error: unknown) { | ||
handleFormErrors(error) | ||
} | ||
} | ||
const handleCancel = () => { | ||
closeModal() | ||
} | ||
const handleBackToSelection = () => { | ||
showModal<Partial<GridWidget>>({ | ||
template: 'AddGridWidget', | ||
forceOpen: true, | ||
}) | ||
} | ||
const widgetInstructions = computed(() => { | ||
return formatMessage( | ||
`add_widget_${widgetType.value.toLowerCase()}_instructions` | ||
) | ||
}) | ||
const hasInstructions = computed(() => widgetInstructions.value !== '-') | ||
</script> | ||
|
||
<template> | ||
<div class="p-6"> | ||
<div class="flex items-center gap-3 pb-4"> | ||
<lukso-icon | ||
v-if="!isEdit" | ||
name="arrow-left-sm" | ||
class="relative z-[1] cursor-pointer rounded-full bg-neutral-100 shadow-neutral-above-shadow transition hover:scale-105 hover:shadow-neutral-above-shadow-1xl active:scale-100 active:shadow-neutral-above-shadow" | ||
@click="handleBackToSelection" | ||
></lukso-icon> | ||
<div class="heading-inter-21-semi-bold"> | ||
{{ | ||
formatMessage( | ||
`${isEdit ? 'edit' : 'add'}_widget_${widgetType.toLowerCase()}_title` | ||
) | ||
}} | ||
</div> | ||
</div> | ||
<div class="paragraph-inter-14-regular pb-6"> | ||
{{ | ||
formatMessage( | ||
`${isEdit ? 'edit' : 'add'}_widget_${widgetType.toLowerCase()}_description` | ||
) | ||
}} | ||
|
||
<!-- Instructions --> | ||
<div v-if="hasInstructions" class="mt-2"> | ||
<div class="flex items-center"> | ||
<span | ||
v-if="isInstructionsVisible" | ||
class="cursor-pointer text-purple-51 underline hover:text-purple-41" | ||
@click="isInstructionsVisible = !isInstructionsVisible" | ||
>Hide instructions</span | ||
> | ||
<span | ||
v-else | ||
class="cursor-pointer text-purple-51 underline hover:text-purple-41" | ||
@click="isInstructionsVisible = !isInstructionsVisible" | ||
>Show instructions</span | ||
> | ||
<lukso-icon | ||
name="arrow-down-sm" | ||
color="purple-51" | ||
:class="{ | ||
'rotate-180 transition': isInstructionsVisible, | ||
}" | ||
></lukso-icon> | ||
</div> | ||
<div | ||
v-if="isInstructionsVisible" | ||
class="mt-4 animate-fade-in whitespace-pre-line font-600 break-word" | ||
> | ||
{{ widgetInstructions }} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Content --> | ||
<lukso-textarea | ||
is-full-width | ||
autofocus | ||
:placeholder=" | ||
formatMessage( | ||
`add_widget_${widgetType.toLowerCase()}_input_placeholder` | ||
) | ||
" | ||
:value="inputValues.input" | ||
:error="getFieldErrorMessage('input')" | ||
@on-input=" | ||
(customEvent: CustomEvent) => handleFieldChange(customEvent, 'input') | ||
" | ||
></lukso-textarea> | ||
|
||
<!-- Buttons --> | ||
<div class="grid grid-cols-[max-content,auto] pt-6"> | ||
<lukso-button variant="text" @click="handleCancel"> | ||
{{ formatMessage('add_widget_cancel') }} | ||
</lukso-button> | ||
<lukso-button | ||
:disabled="!canSubmit ? true : undefined" | ||
variant="landing" | ||
is-full-width | ||
@click="handleSave" | ||
> | ||
{{ formatMessage('add_widget_confirm') }} | ||
</lukso-button> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
<script setup lang="ts"> | ||
import { useScriptTag } from '@vueuse/core' | ||
type Props = { | ||
id: string | ||
} | ||
defineProps<Props>() | ||
useScriptTag('https://static.elfsight.com/platform/platform.js', () => {}, { | ||
async: true, | ||
defer: true, | ||
}) | ||
const props = defineProps<Props>() | ||
const embedId = ref('') | ||
watch( | ||
() => props.id, | ||
async () => { | ||
embedId.value = '' | ||
await nextTick() | ||
const script = document.createElement('script') | ||
script.src = 'https://static.elfsight.com/platform/platform.js' | ||
script.async = true | ||
script.defer = true | ||
const existingScript = document.querySelector(`script[src="${script.src}"]`) | ||
if (existingScript) { | ||
existingScript.remove() | ||
} | ||
embedId.value = props.id | ||
document.body.appendChild(script) | ||
}, | ||
{ immediate: true, deep: true } | ||
) | ||
</script> | ||
|
||
<template> | ||
<div class="relative m-3 overflow-auto"> | ||
<div :class="`elfsight-app-${id}`" data-elfsight-app-lazy></div> | ||
<div v-if="embedId" class="relative m-3 overflow-auto"> | ||
<div :class="`elfsight-app-${embedId}`" data-elfsight-app-lazy></div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters