Skip to content

Commit 0d13456

Browse files
authored
feat: prospective points on user (#256)
1 parent ed1d5a1 commit 0d13456

File tree

10 files changed

+96
-22
lines changed

10 files changed

+96
-22
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div class="grid grid-cols-2 gap-2">
3+
<NuxtLink to="/points">
4+
<ActiveCard>
5+
<ProspectivePoints :points="userStore.prospectivePoints" />
6+
</ActiveCard>
7+
</NuxtLink>
8+
<ProspectiveDays :created-at="userStore.createdAt as string" />
9+
</div>
10+
</template>
11+
12+
<script setup lang="ts">
13+
const userStore = useUserStore()
14+
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<Section class="motion-preset-slide-down motion-delay-400">
3+
<div class="flex flex-col gap-2">
4+
<UIcon name="i-lucide-calendar-check-2" class="size-8 text-primary" />
5+
<p class="text-base/5">
6+
Вы с нами уже <span class="font-bold">{{ days }} {{ pluralizationRu(days, ['день', 'дня', 'дней']) }}</span>
7+
</p>
8+
</div>
9+
</Section>
10+
</template>
11+
12+
<script setup lang="ts">
13+
const { createdAt } = defineProps<{ createdAt: string }>()
14+
15+
const date = computed(() => new Date(createdAt))
16+
const days = computed(() => Math.floor((Date.now() - date.value.getTime()) / 86400000))
17+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<Section class="motion-preset-slide-down motion-delay-100">
3+
<div class="flex flex-col gap-2">
4+
<UIcon name="i-lucide-coins" class="size-8 text-primary" />
5+
<p class="text-base/5">
6+
На данный момент у вас <span class="font-bold">{{ points }} {{ pluralizationRu(points, ['Балл', 'Балла', 'Баллов']) }}</span>
7+
</p>
8+
</div>
9+
</Section>
10+
</template>
11+
12+
<script setup lang="ts">
13+
defineProps<{ points: number }>()
14+
</script>

apps/hub-telegram/app/composables/useNavigation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function _useNavigation() {
1313
// badge: flowStore.nowViewedItemsCount > 10 ? '10+' : flowStore.nowViewedItemsCount.toString(),
1414
},
1515
{
16-
path: '#',
17-
names: [],
18-
title: 'Позже',
19-
icon: 'i-lucide-lock',
16+
path: '/points',
17+
names: ['points'],
18+
title: 'Награды',
19+
icon: 'i-lucide-coins',
2020
},
2121
{
2222
path: '#',

apps/hub-telegram/app/pages/flow/[itemId]/index.vue

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
</div>
2828

2929
<div class="mt-6 flex justify-between items-center">
30-
<div class="flex flex-row gap-4" />
30+
<div class="flex flex-row gap-4">
31+
<div class="flex flex-row gap-1 items-center text-sm text-muted">
32+
<UIcon name="i-lucide-eye" class="size-4" />
33+
{{ item?.views.length }}
34+
</div>
35+
</div>
3136

3237
<time
3338
v-if="item?.createdAt"
@@ -38,21 +43,6 @@
3843
</div>
3944
</Section>
4045

41-
<Section class="flex flex-col">
42-
<h3 class="text-muted">
43-
Посмотрели
44-
</h3>
45-
46-
<div class="flex flex-row flex-wrap gap-1">
47-
<UAvatar
48-
v-for="view in item?.views"
49-
:key="view.id"
50-
:src="userStore.getAvatarUrl(view.userId)"
51-
size="lg"
52-
/>
53-
</div>
54-
</Section>
55-
5646
<div class="flex flex-col gap-2.5">
5747
<div class="flex flex-row gap-2.5 items-center">
5848
<SectionTitle title="Комментарии" />

apps/hub-telegram/app/pages/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<img
55
:src="userAvatar"
66
alt=""
7-
class="size-14 rounded-full"
7+
class="size-16 rounded-full border-3 border-primary"
88
>
99

1010
<SectionTitle :title="`Привет, ${userStore.name}!`" />
1111

12-
Ты 1 уровня
12+
<ProspectiveBlock />
1313
</div>
1414

1515
<div class="flex flex-col gap-2.5">
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<PageContainer>
3+
<Section class="motion-preset-slide-left">
4+
<div class="flex flex-row gap-2 items-center">
5+
<UIcon
6+
name="i-lucide-coins"
7+
class="size-10 text-primary"
8+
/>
9+
</div>
10+
11+
<SectionTitle title="Награды за Баллы" />
12+
13+
<p>Будет чуть позже</p>
14+
</Section>
15+
</PageContainer>
16+
</template>

apps/hub-telegram/app/stores/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const useUserStore = defineStore('user', () => {
1616
const phone = ref<string | null>(null)
1717
const avatarUrl = ref<string | null>(null)
1818
const focusedTaskId = ref<string | null>(null)
19+
const createdAt = ref<string | null>(null)
20+
const prospectivePoints = ref(0)
1921

2022
const initDataRaw = useSignal(initData.raw)
2123
const initDataState = useSignal(initData.state)
@@ -49,6 +51,8 @@ export const useUserStore = defineStore('user', () => {
4951
phone.value = data.phone
5052
avatarUrl.value = data.avatarUrl
5153
focusedTaskId.value = data.focusedTaskId
54+
createdAt.value = data.createdAt
55+
prospectivePoints.value = data.prospectivePoints
5256
} catch (error) {
5357
if (error instanceof Error) {
5458
if (error.message.includes('401')) {
@@ -99,6 +103,8 @@ export const useUserStore = defineStore('user', () => {
99103
email,
100104
avatarUrl,
101105
focusedTaskId,
106+
createdAt,
107+
prospectivePoints,
102108

103109
fullName,
104110

apps/hub-telegram/shared/utils/helpers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import type { FlowItemWithData } from '#shared/types'
22

3+
export function pluralizationRu(int: number, array: [string, string, string]): string {
4+
const n = Math.abs(int)
5+
6+
let idx: 1 | 2 | 0
7+
// @see http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html
8+
if (n % 10 === 1 && n % 100 !== 11) {
9+
idx = 0 // one
10+
} else if (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20)) {
11+
idx = 1 // few
12+
} else {
13+
idx = 2 // many
14+
}
15+
16+
return array[idx]
17+
}
18+
319
export function getIconNameForFlowItem(type: FlowItemWithData['type']): string {
420
switch (type) {
521
case 'user_post':

packages/database/src/tables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const users = pgTable('users', {
2626
phone: varchar('phone').unique(),
2727
avatarUrl: varchar('avatar_url'),
2828
focusedTaskId: cuid2('focused_task_id'),
29+
prospectivePoints: integer('prospective_points').notNull().default(0),
2930
permissions: jsonb('permissions').notNull().default([]).$type<entities.PermissionCode[]>(),
3031
notifications: jsonb('notifications').notNull().default([]).$type<entities.NotificationOption[]>(),
3132
partnerId: cuid2('partner_id').references(() => partners.id),

0 commit comments

Comments
 (0)