-
Notifications
You must be signed in to change notification settings - Fork 0
feat: flow item view #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: flow item view #153
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ import { initDataRaw as _initDataRaw, useSignal } from '@telegram-apps/sdk-vue' | |||||||||||||||||||||||||
| export const useFlowStore = defineStore('flow', () => { | ||||||||||||||||||||||||||
| const items = ref<FlowItemWithData[]>([]) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const nowViewedItemsCount = computed(() => items.value.filter((item) => !item.views.some((view) => view.userId === useUserStore().id)).length) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: comparing a string to a Ref — count will be wrong for all users.
Fix by hoisting the store and unwrapping - const nowViewedItemsCount = computed(() => items.value.filter((item) => !item.views.some((view) => view.userId === useUserStore().id)).length)
+ const userStore = useUserStore()
+ const { id: userId } = storeToRefs(userStore)
+ const notViewedItemsCount = computed(() =>
+ items.value.filter((item) => !item.views.some((view) => view.userId === userId.value)).length
+ )Also export the renamed symbol below. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix Ref-vs-string comparison in computed (using user id).
Apply: - const nowViewedItemsCount = computed(() => items.value.filter((item) => !item.views.some((view) => view.userId === useUserStore().id)).length)
+ const userStore = useUserStore()
+ const { id: userId } = storeToRefs(userStore)
+ const nowViewedItemsCount = computed(() =>
+ items.value.filter((item) => !item.views?.some((view) => view.userId === userId.value)).length
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| const initDataRaw = useSignal(_initDataRaw) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| async function update() { | ||||||||||||||||||||||||||
|
|
@@ -29,9 +31,34 @@ export const useFlowStore = defineStore('flow', () => { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| async function addView(itemId: string) { | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| await $fetch(`/api/flow/id/${itemId}/view`, { | ||||||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||
| Authorization: `tma ${initDataRaw.value}`, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| await update() | ||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||
| if (error instanceof Error) { | ||||||||||||||||||||||||||
| if (error.message.includes('401')) { | ||||||||||||||||||||||||||
| // No | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (error.message.includes('404')) { | ||||||||||||||||||||||||||
| // Not found | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||
| items, | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| nowViewedItemsCount, | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| update, | ||||||||||||||||||||||||||
| addView, | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+59
to
63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainExport the renamed counter. If you adopt - nowViewedItemsCount,
+ notViewedItemsCount,Grepping for usages to update call sites: 🏁 Script executed: #!/bin/bash
rg -n "nowViewedItemsCount|notViewedItemsCount" apps/atrium-telegramLength of output: 366 Export renamed counter and update usages If you rename nowViewedItemsCount → notViewedItemsCount, update the export in apps/atrium-telegram/app/stores/flow.ts (def: line 6, export: line 59) and replace all references — e.g. apps/atrium-telegram/app/composables/useNavigation.ts:16 (flowStore.nowViewedItemsCount → flowStore.notViewedItemsCount). 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { repository } from '@roll-stack/database' | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export default defineEventHandler(async (event) => { | ||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||
| const itemId = getRouterParam(event, 'itemId') | ||||||||||||||||||||||||||||||||||||||||||
| if (!itemId) { | ||||||||||||||||||||||||||||||||||||||||||
| throw createError({ | ||||||||||||||||||||||||||||||||||||||||||
| statusCode: 400, | ||||||||||||||||||||||||||||||||||||||||||
| message: 'Id is required', | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add auth guard to avoid NPE and return 401 when unauthenticated.
const itemId = getRouterParam(event, 'itemId')
if (!itemId) {
throw createError({
statusCode: 400,
message: 'Id is required',
})
}
+ if (!event.context.user?.id) {
+ throw createError({
+ statusCode: 401,
+ message: 'Unauthorized',
+ })
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| // Guards: | ||||||||||||||||||||||||||||||||||||||||||
| // If not exist | ||||||||||||||||||||||||||||||||||||||||||
| // If already viewed | ||||||||||||||||||||||||||||||||||||||||||
| const item = await repository.flow.findItem(itemId) | ||||||||||||||||||||||||||||||||||||||||||
| if (!item) { | ||||||||||||||||||||||||||||||||||||||||||
| throw createError({ | ||||||||||||||||||||||||||||||||||||||||||
| statusCode: 404, | ||||||||||||||||||||||||||||||||||||||||||
| message: 'Item not found', | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (item.views.some((view) => view.userId === event.context.user.id)) { | ||||||||||||||||||||||||||||||||||||||||||
| throw createError({ | ||||||||||||||||||||||||||||||||||||||||||
| statusCode: 400, | ||||||||||||||||||||||||||||||||||||||||||
| message: 'Already viewed', | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| await repository.flow.createItemView({ | ||||||||||||||||||||||||||||||||||||||||||
| itemId, | ||||||||||||||||||||||||||||||||||||||||||
| userId: event.context.user.id, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return { ok: true } | ||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||
| throw errorResolver(error) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Ref-vs-string comparison in
isViewed.userStore.idis a Ref; compare against its value.📝 Committable suggestion
🤖 Prompt for AI Agents