Skip to content

Commit a12ee4e

Browse files
authored
feat: gyroscope test (#127)
1 parent 6ddf549 commit a12ee4e

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

apps/storefront-telegram/app/assets/css/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
.tg-text {
6868
color: var(--tg-theme-text-color);
6969
}
70+
.tg-text-inverted {
71+
color: var(--tg-theme-bg-color);
72+
}
7073
.tg-text-accent {
7174
color: var(--tg-theme-accent-text-color);
7275
}

apps/storefront-telegram/app/components/UserPointsCard.vue

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<template>
2+
{{ x }} / {{ y }} / {{ z }}
3+
24
<div ref="target" class="relative w-full h-auto aspect-3/2 perspective-normal motion-preset-slide-down">
35
<div
46
class="absolute inset-0 bg-primary rounded-lg"
57
:style="{
6-
transform: `rotateX(${parallax.roll * 3}deg) rotateY(${parallax.tilt * 3}deg)`,
8+
transform: `rotateX(${x * 6}deg) rotateY(${y * 6}deg)`,
79
}"
810
/>
911

1012
<div
1113
class="z-10 w-full h-full p-4 flex flex-col justify-between tg-text-button"
1214
:style="{
13-
transform: `rotateX(${parallax.roll * 2}deg) rotateY(${parallax.tilt * 2}deg)`,
15+
transform: `rotateX(${x * 4}deg) rotateY(${y * 4}deg)`,
1416
}"
1517
>
1618
<div class="flex flex-row justify-between items-center">
@@ -29,17 +31,17 @@
2931
<img
3032
src="/sushi-heart.svg"
3133
alt=""
32-
class="w-12 opacity-20 invert-100"
34+
class="w-12 opacity-35 invert-100"
3335
>
3436
</div>
3537

3638
<div class="flex flex-row justify-between items-center">
3739
<div class="flex flex-row gap-2 items-center">
38-
<div class="px-3.5 py-1.5 text-2xl/5 text-primary font-bold ring ring-default bg-default rounded-2xl">
40+
<div class="px-3.5 py-1.5 text-2xl/5 text-primary font-bold rounded-full tg-bg-section">
3941
5%
4042
</div>
4143

42-
<div>
44+
<div class="tg-text-inverted">
4345
Кешбэк
4446
</div>
4547
</div>
@@ -51,8 +53,27 @@
5153
</template>
5254

5355
<script setup lang="ts">
54-
import { useParallax } from '@vueuse/core'
56+
import type { EventListener } from '@telegram-apps/sdk-vue'
57+
import { off, on } from '@telegram-apps/sdk-vue'
5558
5659
const target = useTemplateRef<HTMLElement>('target')
57-
const parallax = reactive(useParallax(target))
60+
// const parallax = reactive(useParallax(target))
61+
62+
const x = ref(0)
63+
const y = ref(0)
64+
const z = ref(0)
65+
66+
const listener: EventListener<'gyroscope_changed'> = (payload) => {
67+
x.value = payload.x
68+
y.value = payload.y
69+
z.value = payload.z
70+
}
71+
72+
onMounted(() => {
73+
on('gyroscope_changed', listener)
74+
})
75+
76+
onUnmounted(() => {
77+
off('gyroscope_changed', listener)
78+
})
5879
</script>

apps/storefront-telegram/app/components/catalog/CategoriesSliderMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
v-for="category in menuStore.menu?.categories"
77
:id="`to-${category.slug}`"
88
:key="category.id"
9-
class="scroll-ml-24 snap-start text-muted rounded-md"
9+
class="scroll-ml-24 snap-start text-sm text-muted rounded-full"
1010
:class="{ 'tg-text-button bg-primary': visibleCategory === category.slug }"
1111
>
12-
<button class="px-3 py-1" @click="scrollToCategory(category.slug)">
12+
<button class="px-2.5 py-1" @click="scrollToCategory(category.slug)">
1313
{{ category.name }}
1414
</button>
1515
</div>

apps/storefront-telegram/app/pages/user.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<UButtonGroup orientation="vertical" size="xl">
1616
<UButton
1717
color="neutral"
18-
variant="subtle"
18+
variant="ghost"
1919
label="Мои заказы"
2020
icon="i-lucide-shopping-basket"
2121
/>
2222
<UButton
2323
color="neutral"
24-
variant="outline"
24+
variant="ghost"
2525
label="Мои адреса"
2626
icon="i-lucide-map-pin-house"
2727
/>

apps/storefront-telegram/app/utils/init.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export async function init(options: {
9090
locked: true,
9191
})
9292

93+
// Gyroscope
94+
postEvent('web_app_start_gyroscope', {
95+
refresh_rate: 50,
96+
})
97+
9398
if (mountViewport.isAvailable()) {
9499
mountViewport().then(() => {
95100
bindViewportCssVars()

0 commit comments

Comments
 (0)