Skip to content

Commit

Permalink
feat(api): extend announcement popup with platform and userKind filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 committed Dec 5, 2024
1 parent 5f143fd commit 918026c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/__generated__/gql/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/__generated__/gql/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/api/gql-documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const APP_ANNOUNCEMENT_FRAGMENT = graphql(/* GraphQL */ `
endDateTime
priority
url
platform
userKind
}
`)

Expand Down
18 changes: 14 additions & 4 deletions src/components/Cards/PopUpCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// BaseCard Component to show the card on the dashboard to navigate to the corresponding page
import { type AnnouncementFieldsFragment } from '@/__generated__/gql/graphql'
import {
type AnnouncementFieldsFragment,
type Platform as AppPlatform,
type UserKind,
} from '@/__generated__/gql/graphql'
import i18n from '@/localization/i18n'
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { Linking, Pressable, Text, View } from 'react-native'
import { Linking, Platform, Pressable, Text, View } from 'react-native'
import { createStyleSheet, useStyles } from 'react-native-unistyles'

import PlatformIcon from '../Universal/Icon'
import { DashboardContext } from '../contexts'
import { DashboardContext, UserKindContext } from '../contexts'

interface PopUpCardProps {
data: AnnouncementFieldsFragment[]
Expand All @@ -17,6 +20,7 @@ const PopUpCard: React.FC<PopUpCardProps> = ({ data }) => {
const { hiddenAnnouncements, hideAnnouncement } =
useContext(DashboardContext)
const { t } = useTranslation('navigation')
const { userKind = 'guest' } = useContext(UserKindContext)
const { styles } = useStyles(stylesheet)

if (data === undefined) {
Expand All @@ -28,6 +32,12 @@ const PopUpCard: React.FC<PopUpCardProps> = ({ data }) => {
const now = Date.now()
const activeAnnouncements = data.filter(
(announcement) =>
announcement?.platform?.includes(
Platform.OS.toUpperCase() as AppPlatform
) &&
announcement?.userKind?.includes(
userKind?.toUpperCase() as UserKind
) &&
new Date(announcement.startDateTime).getTime() < now &&
new Date(announcement.endDateTime).getTime() > now &&
!hiddenAnnouncements.includes(announcement.id)
Expand Down

0 comments on commit 918026c

Please sign in to comment.