Skip to content

Commit

Permalink
dips, push notif backend progress, speaker links
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejaco committed Sep 30, 2024
1 parent baa699d commit bea5317
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 35 deletions.
2 changes: 2 additions & 0 deletions devcon-api/src/clients/dips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ export async function GetDIPs(): Promise<Array<DIP>> {
const nextDip = currentIndex < dipNumbers.length ? `/dips/dip-${dipNumbers[currentIndex + 1]}` : `/dips/`

const doc = matter(formattedMarkdown)

return {
number: doc.data.DIP,
title: doc.data.Title,
summary: doc.data.Summary ? toHtml(doc.data.Summary) : '',
status: doc.data.Status,
github: doc.data['Github URL'],
themes: doc.data.Themes ? doc.data.Themes.split(',') : [],
instances: Array.isArray(doc.data.Instances) ? doc.data.Instances : doc.data.Instances ? [doc.data.Instances] : [],
tags: doc.data.Tags ? doc.data.Tags.split(',') : [],
authors: doc.data.Authors ? doc.data.Authors.split(',') : [],
resources: doc.data['Resources Required'] ?? '',
Expand Down
51 changes: 51 additions & 0 deletions devcon-api/src/controllers/push-notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Request, Response, Router } from 'express'
import { PrismaClient } from '@/db/clients/account'

const prisma = new PrismaClient()

export const pushNotificationRouter = Router()

pushNotificationRouter.post('/subscriptions', subscribeToPushNotifications)
pushNotificationRouter.delete('/subscriptions', unsubscribeFromPushNotifications)

async function subscribeToPushNotifications(req: Request, res: Response) {
// #swagger.tags = ['Push Notifications']
const { endpoint, keys } = req.body

if (!endpoint || !keys || !keys.auth || !keys.p256dh) {
return res.status(400).send({ status: 400, message: 'Endpoint and keys (auth and p256dh) are required', data: null })
}

try {
await prisma.pushSubscription.create({
data: {
endpoint,
auth: keys.auth,
p256dh: keys.p256dh,
},
})
res.status(201).send({ status: 201, message: 'Subscription successful', data: null })
} catch (error) {
console.error('Error subscribing to push notifications:', error)
res.status(500).send({ status: 500, message: 'Internal server error', data: null })
}
}

async function unsubscribeFromPushNotifications(req: Request, res: Response) {
// #swagger.tags = ['Push Notifications']
const { endpoint } = req.body

if (!endpoint) {
return res.status(400).send({ status: 400, message: 'Endpoint is required', data: null })
}

try {
await prisma.pushSubscription.delete({
where: { endpoint },
})
res.status(200).send({ status: 200, message: 'Unsubscription successful', data: null })
} catch (error) {
console.error('Error unsubscribing from push notifications:', error)
res.status(500).send({ status: 500, message: 'Internal server error', data: null })
}
}
9 changes: 9 additions & 0 deletions devcon-api/src/db/account.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ model rate_limit {
points Int @default(0)
expire BigInt?
}

model PushSubscription {
id String @id @default(uuid())
endpoint String @unique
auth String
p256dh String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Binary file modified devcon-api/src/db/devcon.db
Binary file not shown.
2 changes: 2 additions & 0 deletions devcon-api/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { sessionsRouter } from '@/controllers/sessions'
import { speakersRouter } from '@/controllers/speakers'
import { aiRouter } from '@/controllers/ai'
import { hooksRouter } from '@/controllers/hooks'
// import { pushNotificationRouter } from '@/controllers/push-notifications'
import { Router } from 'express'
import { API_INFO } from '@/utils/config'

Expand All @@ -25,3 +26,4 @@ router.use(sessionsRouter)
router.use(speakersRouter)
router.use(aiRouter)
router.use(hooksRouter)
// router.use(pushNotificationRouter)
1 change: 1 addition & 0 deletions devcon-api/src/types/dips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface DIP {
github: string
themes: Array<Theme>
tags: Array<Tag>
instances: Array<string>
authors: Array<string>
resources: string
discussion: string
Expand Down
20 changes: 19 additions & 1 deletion devcon-app/src/components/domain/app/pwa-prompt/pwa-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,32 @@ export const pwaUtilities = {

if (existingSubscription) {
await existingSubscription.unsubscribe()
// Call backend to remove subscription
await fetch('/api/push-notifications/subscriptions', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ endpoint: existingSubscription.endpoint }),
})
return { success: true, message: 'Push notifications unsubscribed successfully' }
} else {
const newSubscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: process.env.VAPID_PUBLIC,
})
console.log('Push notification subscribed:', newSubscription)
// Here you would typically send the subscription to your server
// Call backend to save subscription
await fetch('/api/push-notifications/subscriptions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
endpoint: newSubscription.endpoint,
keys: newSubscription.keys,
}),
})
return { success: true, message: 'Push notifications enabled successfully' }
}
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions devcon/src/components/common/sort/Sort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum SortVariation {
number = 'number',
date = 'date',
basic = 'basic',
basicReverse = 'basicReverse',
}

type SortState = {
Expand Down Expand Up @@ -66,6 +67,8 @@ export const presetSortingMethods: any = {
return dateA === dateB ? 0 : dateA > dateB ? 1 : -1
},
basic: (fieldKey: string) => (a: any, b: any) => a[fieldKey] === b[fieldKey] ? 0 : a[fieldKey] > b[fieldKey] ? 1 : -1,
basicReverse: (fieldKey: string) => (a: any, b: any) =>
a[fieldKey] === b[fieldKey] ? 0 : a[fieldKey] < b[fieldKey] ? 1 : -1,
}

// useSort contains reusable sorting logic to provide rendering flexiblity (e.g. archive sorting is very different from table sorting)
Expand Down
2 changes: 1 addition & 1 deletion devcon/src/components/common/sort/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Sort, SortButton, useSort, SortVariation } from './Sort'
export { Sort, SortButton, useSort, SortVariation, presetSortingMethods } from './Sort'
17 changes: 15 additions & 2 deletions devcon/src/components/domain/dips/overview/proposals/Proposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Label } from 'components/common/label'
import { Link } from 'components/common/link'
import { leftPad } from 'utils/left-pad'
import { Table, TableColumn } from 'components/common/table/Table'
import { SortVariation } from 'components/common/sort'
import { SortVariation, presetSortingMethods } from 'components/common/sort'
import { DIP } from 'types/DIP'
import GithubIcon from 'assets/icons/github.svg'
import TooltipIcon from 'assets/icons/tooltip.svg'
Expand Down Expand Up @@ -90,7 +90,7 @@ export const Proposals = (props: ProposalsProps) => {
title: '#',
key: 'number',
className: css['index-column'],
sort: SortVariation.basic,
sort: SortVariation.basicReverse,
render: (item: DIP) => {
return (
<p className={`${css['index']} h3`}>
Expand Down Expand Up @@ -120,6 +120,19 @@ export const Proposals = (props: ProposalsProps) => {
}
},
},
{
intl: 'dips_instances',
key: 'Edition',
className: '!basis-[115px] !grow-0 !hidden lg:!flex', // css['name-column'],
// sort: SortVariation.basic,
render: (item: DIP) => {
if (item.instances) {
return <div>{item.instances.join(', ')}</div>
}

return null
},
},
{
intl: 'dips_status',
key: 'status',
Expand Down
Loading

0 comments on commit bea5317

Please sign in to comment.