Skip to content

Commit

Permalink
✨ Add ISCN card print page
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Nov 2, 2023
1 parent 064dea3 commit 90b5c28
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 28 deletions.
12 changes: 12 additions & 0 deletions components/IscnCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
/>
</foreignObject>
</g>
<rect
key="border_radius_hack_for_printing"
class="hidden print:block"
x="-9"
y="-9"
:width="svgSizeProps.width + 18"
:height="svgSizeProps.height + 18"
rx="30"
fill="none"
stroke="#fff"
stroke-width="18"
/>
</svg>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
"iscn.meta.usage.info": "Usage Info",
"iscn.meta.version.placeholder": "Version",
"iscn.meta.version": "Version",
"IscnCardPage.button.back": "Back",
"IscnCardPage.button.landscape": "Landscape",
"IscnCardPage.button.portrait": "Portrait",
"IscnCardPage.button.print": "Print",
"IscnRegisterForm.arweave.link": "ar://{arweaveId}",
"IscnRegisterForm.button.back": "Back",
"IscnRegisterForm.button.confirm": "Confirm",
Expand Down
128 changes: 128 additions & 0 deletions pages/view/_iscnId/card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<template>
<div class="fixed inset-0 flex justify-center items-center">
<header
v-if="shouldShowControls"
class="print:hidden absolute inset-x-0 top-0 flex justify-between p-4 bg-white shadow-sm z-10"
>
<Button
preset="tertiary"
:text="$t('IscnCardPage.button.back')"
:to="localeLocation({
name: 'view-iscnId',
params: { iscnId },
})"
>
<template #prepend>
<IconArrowLeft />
</template>
</Button>

<div class="flex gap-2">
<Button
preset="tertiary"
:text="$t(isLandscape ? 'IscnCardPage.button.portrait' : 'IscnCardPage.button.landscape')"
:to="localeLocation({
name: 'view-iscnId-card',
params: { iscnId },
query: { orientation: isLandscape ? 'portrait' : 'landscape' },
})"
@click.native="handleClickOrientationChange"
/>
<Button
preset="secondary"
:text="$t('IscnCardPage.button.print')"
@click="handleClickPrint"
/>
</div>
</header>

<IscnCard
:key="orientation"
:record="record"
:is-animated="true"
:orientation="orientation"
:style="`width: ${width}px`"
/>

</div>
</template>

<script lang="ts">
import { Vue, Component, Watch } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import { ISCN_PREFIX } from '~/constant'
import { ISCNRecordWithID } from '~/utils/cosmos/iscn/iscn.type'
import { logTrackerEvent } from '~/utils/logger'
const iscnModule = namespace('iscn')
@Component({
layout: 'blank',
components: { IscnCard: () => import('~/components/IscnCard.vue') },
async asyncData({ params, store, error }) {
try {
const { iscnId } = params
if (iscnId && iscnId.startsWith(ISCN_PREFIX)) {
const res = await store.dispatch('iscn/fetchISCNById', iscnId)
if (res) {
return {
iscnId: res.records[0].id,
};
}
}
} catch (err) {
error(err as Error)
}
return {}
},
})
export default class ISCNCardPrintPage extends Vue {
iscnId = ''
width = 0
@iscnModule.Getter getISCNById!: (arg0: string) => ISCNRecordWithID
get isLandscape() {
return this.$route.query.orientation === 'landscape'
}
get shouldShowControls() {
return this.$route.query.control !== '0'
}
get orientation() {
return this.isLandscape ? 'landscape' : 'portrait'
}
get record() {
return this.getISCNById(this.iscnId)
}
mounted() {
this.handleResize()
window.addEventListener('resize', this.handleResize)
}
beforeDestroy() {
window.removeEventListener('resize', this.handleResize)
}
@Watch('isLandscape')
handleResize() {
window.requestAnimationFrame(() => {
this.width = this.isLandscape ? Math.min(window.innerHeight * 2, 560) : Math.min(window.innerHeight / 2, 280);
})
}
handleClickOrientationChange() {
logTrackerEvent(this, 'ISCNView', `ISCNCardPageSet${this.isLandscape ? 'Landscape' : 'Portrait' }`, this.iscnId, 1)
}
handleClickPrint() {
logTrackerEvent(this, 'ISCNView', 'ISCNCardPagePrint', this.iscnId, 1)
window.print()
}
}
</script>
55 changes: 31 additions & 24 deletions pages/view/_iscnId.vue → pages/view/_iscnId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,37 @@
'lg:max-w-[280px]',
]"
>
<IscnCard
:key="`${record.id}-portrait`"
:class="[
'hidden',
'lg:block',
'flex-shrink-0',
'w-[280px]',
]"
:record="record"
orientation="portrait"
:is-animated="true"
/>
<IscnCard
:key="`${record.id}-landscape`"
:class="[
'w-full',
'lg:absolute',
'lg:opacity-0',
'lg:pointer-events-none',
]"
:record="record"
:is-animated="true"
orientation="landscape"
/>
<NuxtLink
:to="localeLocation({
name: 'view-iscnId-card',
params: { iscnId: record.id },
})"
>
<IscnCard
:key="`${record.id}-portrait`"
:class="[
'hidden',
'lg:block',
'flex-shrink-0',
'w-[280px]',
]"
:record="record"
orientation="portrait"
:is-animated="true"
/>
<IscnCard
:key="`${record.id}-landscape`"
:class="[
'w-full',
'lg:absolute',
'lg:opacity-0',
'lg:pointer-events-none',
]"
:record="record"
:is-animated="true"
orientation="landscape"
/>
</NuxtLink>
<Button
v-if="viewContentURL"
class="mx-auto mt-[16px]"
Expand Down
12 changes: 8 additions & 4 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ module.exports = {
'airdrop-gold':'#D1AB79',
'twitter-blue':'#4696F1',
},
boxShadow: {
popup: '2px 4px 8px rgba(0, 0, 0, 0.25)',
},
fontFamily: {
'mono': [
'PT Mono',
Expand All @@ -38,6 +35,13 @@ module.exports = {
'48px': '48px',
'64px': '64px',
},
screens: {
// Should remove this once we upgrade TailwindCSS to v3
print: { raw: 'print' },
},
boxShadow: {
popup: '2px 4px 8px rgba(0, 0, 0, 0.25)',
},
},
screens: {
'sm': '640px',
Expand All @@ -59,7 +63,7 @@ module.exports = {
'.scrollbar-hidden': {
'-ms-overflow-style': 'none', /* IE and Edge */
'scrollbar-width': 'none', /* Firefox */
'&::-webkit-scrollbar': {
'&::-webkit-scrollbar': {
display: 'none', /* Chrome */
},
},
Expand Down

0 comments on commit 90b5c28

Please sign in to comment.