Skip to content

Commit

Permalink
Merge branch 'main' into switch-to-dyndata
Browse files Browse the repository at this point in the history
  • Loading branch information
preschian authored Aug 8, 2024
2 parents 69fe015 + e6075e2 commit 7d3a989
Show file tree
Hide file tree
Showing 19 changed files with 993 additions and 342 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
50 changes: 19 additions & 31 deletions components/codeChecker/CodeChecker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@
v-if="selectedFile && !errorMessage"
class="border-t border-k-shade pt-5 flex flex-col gap-5"
>
<CodeCheckerTestItem
:passed="fileValidity.resizerUsed"
:description="$t('codeChecker.automaticResize')"
>
<template #modalContent>
<CodeCheckerIssueHintAutomaticResize />
</template>
</CodeCheckerTestItem>
<CodeCheckerTestItem
:passed="fileValidity.validTitle"
:description="$t('codeChecker.correctHTMLName')"
Expand Down Expand Up @@ -147,40 +139,41 @@
<CodeCheckerIssueHintUsingParamHash />
</template>
</CodeCheckerTestItem>

<CodeCheckerTestItem
:passed="!fileValidity.webGlUsed"
:description="$t('codeChecker.notUsingWebGl')"
:passed="fileValidity.validKodaRenderPayload"
:description="$t('codeChecker.validImage')"
>
<template #modalContent>
<CodeCheckerIssueHintNoWebGl />
<CodeCheckerIssueHintValidImage />
</template>
</CodeCheckerTestItem>
<CodeCheckerTestItem
:passed="fileValidity.renderDurationValid"
:description="
$t('codeChecker.variationLoadingTime', [
(config.maxAllowedLoadTime / 1000).toFixed(0),
])
"
:passed="fileValidity.consistent"
:description="$t('codeChecker.consistentArt')"
>
<template #modalContent>
<CodeCheckerIssueHintVariationLoadingTime />
<CodeCheckerIssueHintConsistentArt />
</template>
</CodeCheckerTestItem>
<CodeCheckerTestItem
:passed="fileValidity.validKodaRenderPayload"
:description="$t('codeChecker.validImage')"
:passed="fileValidity.resizerUsed"
:description="$t('codeChecker.automaticResize')"
optional
>
<template #modalContent>
<CodeCheckerIssueHintValidImage />
<CodeCheckerIssueHintAutomaticResize />
</template>
</CodeCheckerTestItem>
<CodeCheckerTestItem
:passed="fileValidity.consistent"
:description="$t('codeChecker.consistentArt')"
:passed="fileValidity.renderDurationValid"
:description="
$t('codeChecker.variationLoadingTime')
"
optional
>
<template #modalContent>
<CodeCheckerIssueHintConsistentArt />
<CodeCheckerIssueHintVariationLoadingTime />
</template>
</CodeCheckerTestItem>
</div>
Expand Down Expand Up @@ -233,7 +226,7 @@

<script lang="ts" setup>
import { NeoIcon } from '@kodadot1/brick'
import { validate, webGlUsed } from './validate'
import { validate } from './validate'
import { createSandboxAssets, extractAssetsFromZip } from './utils'
import config from './codechecker.config'
import type { AssetMessage, Validity } from './types'
Expand All @@ -255,7 +248,6 @@ const RESOURCES_LIST = [
const validtyDefault: Validity = {
canvasSize: '',
webGlUsed: false,
localP5jsUsed: false,
kodaRendererUsed: 'unknown',
kodaRendererCalledOnce: 'unknown',
Expand Down Expand Up @@ -287,7 +279,7 @@ const onFileSelected = async (file: File) => {
clear()
startClock()
selectedFile.value = file
const { indexFile, sketchFile, entries, jsFiles }
const { indexFile, sketchFile, entries }
= await extractAssetsFromZip(file)
if (!sketchFile) {
Expand All @@ -301,9 +293,6 @@ const onFileSelected = async (file: File) => {
else {
Object.assign(fileValidity, valid.value)
}
fileValidity.webGlUsed = jsFiles.some(file =>
webGlUsed(file.content, file.path),
)
if (!fileValidity.kodaRendererUsed) {
fileValidity.renderDurationValid = 'unknown'
Expand Down Expand Up @@ -354,7 +343,6 @@ useEventListener(window, 'message', async (res) => {
renderEndTime.value = performance.now()
const duration = renderEndTime.value - renderStartTime.value
fileValidity.renderDurationValid = duration < config.maxAllowedLoadTime
fileValidity.validKodaRenderPayload
= Boolean(payload?.image) && hasImage(payload.image)
if (fileValidity.validKodaRenderPayload) {
Expand Down
3 changes: 2 additions & 1 deletion components/codeChecker/TestItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type { Passed } from './types'
const props = defineProps<{
passed: Passed
description: string
optional?: boolean
}>()
const showResolveIssuesModal = ref(false)
Expand All @@ -54,7 +55,7 @@ const icon = computed(() => {
spin: true,
}
}
if (props.passed === 'unknown') {
if (props.passed === 'unknown' || (props.optional && !props.passed)) {
return {
name: 'question',
class: 'text-k-grey',
Expand Down
21 changes: 0 additions & 21 deletions components/codeChecker/issueHint/NoWebGl.vue

This file was deleted.

13 changes: 0 additions & 13 deletions components/codeChecker/issueHint/VariationLoadingTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,4 @@
<li>{{ $t('codeChecker.variationLoadingTimeMeans2') }}</li>
<li>{{ $t('codeChecker.variationLoadingTimeMeans3') }}</li>
</ul>

<CodeCheckerIssueHintCodeBlock
class="mt-5"
:code="code"
lang="javascript"
/>
</template>

<script setup lang="ts">
const code = `
function windowResized() { canvasSize = min(windowWidth, windowHeight)
resizeCanvas(canvasSize, canvasSize)
}`
</script>
1 change: 0 additions & 1 deletion components/codeChecker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type Result<T> = Success<T> | Failure
export type Validity = {
canvasSize: string
title: string
webGlUsed: boolean
localP5jsUsed: boolean
kodaRendererUsed: Passed
kodaRendererCalledOnce: Passed
Expand Down
19 changes: 0 additions & 19 deletions components/codeChecker/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type InnerValidity = Pick<

const constants = {
canvasRegex: /createCanvas\(([^,]+?),\s*([^\s,]+?)(,\s*WEBGL)?\)/g,
graphicsRegex: /createGraphics\(([^,]+?),\s*([^\s,]+?)(,\s*WEBGL)?\)/g,
getUrlParamsRegex: /\b(const|let|var)\s+(\w+)\s*=\s*getURLParams\(\)\s*/,
urlSearchParamsRegex:
/\b(const|let|var)\s+(\w+)\s*=\s*new URLSearchParams\(window.location.search\)\s*/,
Expand All @@ -45,24 +44,6 @@ const validateCanvasCreation = (
return { isSuccess: true, value: canvasMatch }
}

export const webGlUsed = (content, path) => {
const canvasMatches = content.match(constants.canvasRegex)
const graphicsMatches = content.match(constants.graphicsRegex)

const canvasWebGLUsed = canvasMatches
? canvasMatches.some(match => match.includes('WEBGL'))
: false
const graphicsWebGLUsed = graphicsMatches
? graphicsMatches.some(match => match.includes('WEBGL'))
: false

if (canvasWebGLUsed || graphicsWebGLUsed) {
console.warn(`WebGL usage found in file: ${path}`)
}

return canvasWebGLUsed || graphicsWebGLUsed
}

const validateGetURLParamsUsage = (
sketchFileContent: string,
): Result<RegExpExecArray> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/>
</div>
<h1
class="collection-banner-name font-bold text-2xl md:text-[31px]"
class="collection-banner-name font-bold text-2xl md:text-[31px] w-max max-w-sm"
data-testid="collection-banner-name"
>
{{ collectionName }}
Expand Down
8 changes: 5 additions & 3 deletions components/drops/Drops.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
:drops="currentDrops"
:loaded="loaded"
:default-skeleton-count="DEFAULT_SKELETON_COUNT"
:async-skeleton-count="Math.round((count/2) - currentDrops.length)"
skeleton-key="current-drops-skeleton"
/>

Expand All @@ -55,6 +56,7 @@
:drops="pastDrops"
:loaded="loaded"
:default-skeleton-count="DEFAULT_SKELETON_COUNT"
:async-skeleton-count="Math.round((count/2) - pastDrops.length)"
skeleton-key="skeleton"
/>

Expand All @@ -78,11 +80,11 @@ const CURRENT_DROP_STATUS = Object.values(DropStatus).filter(
const { $i18n } = useNuxtApp()
const { urlPrefix } = usePrefix()
const { drops, loaded } = useDrops({
const { drops, loaded, count } = useDrops({
active: [true],
chain: !isProduction ? [urlPrefix.value] : [],
limit: 100, // set limit to enable sort from backend
})
limit: 100,
}, { async: true })
const isCreateEventModalActive = ref(false)
Expand Down
34 changes: 19 additions & 15 deletions components/drops/DropsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
:default-width="GRID_DEFAULT_WIDTH"
persist
>
<template
v-if="asyncSkeletonCount ? true : loaded"
>
<div
v-for="(drop, index) in drops"
:key="`${isDrop(drop) ? drop.collection?.id : drop.id}=${index}`"
class="w-full h-full"
:data-testid="index"
>
<slot
name="card"
:item="drop as InternalDropCalendar"
>
<DropCard :drop="drop as Drop" />
</slot>
</div>
</template>
<template v-if="!loaded">
<DropsDropCardSkeleton
v-for="x in defaultSkeletonCount"
v-for="x in asyncSkeletonCount || defaultSkeletonCount"
:key="`${skeletonKey}-${x}`"
/>
</template>
<div
v-for="(drop, index) in drops"
v-else
:key="`${isDrop(drop) ? drop.collection?.id : drop.id}=${index}`"
class="w-full h-full"
:data-testid="index"
>
<slot
name="card"
:item="drop as InternalDropCalendar"
>
<DropCard :drop="drop as Drop" />
</slot>
</div>
</DynamicGrid>
</template>
Expand All @@ -42,6 +45,7 @@ defineProps<{
drops: Drop[] | InternalDropCalendar[]
loaded: boolean
defaultSkeletonCount: number
asyncSkeletonCount?: number
skeletonKey: string
clickable?: boolean
}>()
Expand Down
32 changes: 25 additions & 7 deletions components/drops/useDrops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,40 @@ const DROP_LIST_ORDER = [

const ONE_DAYH_IN_MS = 24 * 60 * 60 * 1000

export function useDrops(query?: GetDropsQuery) {
export function useDrops(query?: GetDropsQuery, { async = false }: { async?: boolean } = { }) {
const drops = ref<Drop[]>([])
const dropsList = ref<DropItem[]>([])
const count = computed(() => dropsList.value.length)
const loaded = ref(false)

const getDropsAsync = () => {
dropsList.value.forEach((drop) => {
getFormattedDropItem(drop, drop).then((drop: Drop) => {
drops.value = orderBy(
[...drops.value, drop],
[drop => dropsList.value.map(d => d.alias).indexOf(drop.alias)],
)
})
})

watch(() => drops.value.length === dropsList.value.length, () => {
loaded.value = true
}, { once: true })
}

onBeforeMount(async () => {
dropsList.value = await getDrops(query)

const formattedDrops = await Promise.all(
dropsList.value.map(async drop => getFormattedDropItem(drop, drop)),
)

drops.value = formattedDrops
if (async) {
getDropsAsync()
}
else {
drops.value = await Promise.all(
dropsList.value.map(async drop => getFormattedDropItem(drop, drop)),
)

loaded.value = true
loaded.value = true
}
})

const sortDrops = computed(() =>
Expand Down
Loading

0 comments on commit 7d3a989

Please sign in to comment.