Skip to content

Commit daed7fd

Browse files
authored
Merge pull request wishonia#142 from mikepsinn/main
Petition Models and Relations, Civic API
2 parents def39ff + db97d70 commit daed7fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4869
-176
lines changed

.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,9 @@ SEARXNG_SAFESEARCH=0 # Safe search setting: 0 (off), 1 (moderate), 2 (strict)
145145
#NEXT_PUBLIC_BASE_URL=http://localhost:3000
146146

147147
DFDA_CLIENT_ID=
148-
DFDA_CLIENT_SECRET=
148+
DFDA_CLIENT_SECRET=
149+
150+
GOOGLE_CIVIC_API_KEY=your_api_key_here
151+
152+
# Default AI model to use for generation
153+
DEFAULT_AI_MODEL=gpt-4o-mini
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { NextResponse } from 'next/server'
2+
import { sendDailySummaries, sendWeeklySummaries } from '@/lib/notifications/petition-summary'
3+
4+
export const runtime = 'edge'
5+
6+
export async function GET(request: Request) {
7+
try {
8+
const { searchParams } = new URL(request.url)
9+
const type = searchParams.get('type')
10+
11+
if (type === 'daily') {
12+
await sendDailySummaries()
13+
} else if (type === 'weekly') {
14+
await sendWeeklySummaries()
15+
}
16+
17+
return NextResponse.json({ success: true })
18+
} catch (error) {
19+
console.error('Cron job failed:', error)
20+
return NextResponse.json({ error: 'Failed to process summaries' }, { status: 500 })
21+
}
22+
}

app/articles/articleActions.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { prisma } from "@/lib/prisma"
2+
3+
export async function getAuthorByUsername(username: string) {
4+
return await prisma.user.findUnique({
5+
where: { username },
6+
select: {
7+
id: true,
8+
name: true,
9+
username: true,
10+
image: true,
11+
bio: true,
12+
_count: {
13+
select: { authoredArticles: true }
14+
}
15+
}
16+
})
17+
}
18+
19+
export async function getAuthors() {
20+
return await prisma.user.findMany({
21+
where: {
22+
authoredArticles: {
23+
some: {}
24+
}
25+
},
26+
select: {
27+
id: true,
28+
name: true,
29+
username: true,
30+
image: true,
31+
bio: true,
32+
_count: {
33+
select: { authoredArticles: true }
34+
}
35+
},
36+
orderBy: {
37+
name: 'asc'
38+
}
39+
})
40+
}
41+
42+
export async function getAuthorForMetadata(username: string) {
43+
return await prisma.user.findUnique({
44+
where: { username },
45+
select: {
46+
name: true,
47+
username: true
48+
}
49+
})
50+
}

app/articles/author/[username]/page.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { prisma } from "@/lib/prisma"
21
import { notFound } from "next/navigation"
32
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
43
import ArticleSearchAndGrid from "@/components/article/ArticleSearchAndGrid"
4+
import { getAuthorByUsername, getAuthorForMetadata } from "../../articleActions"
55

66
export async function generateMetadata({ params }: { params: { username: string } }) {
7-
const author = await prisma.user.findUnique({
8-
where: { username: params.username }
9-
})
7+
const author = await getAuthorForMetadata(params.username)
108

119
if (!author) {
1210
return {
@@ -21,14 +19,7 @@ export async function generateMetadata({ params }: { params: { username: string
2119
}
2220

2321
export default async function AuthorPage({ params }: { params: { username: string } }) {
24-
const author = await prisma.user.findUnique({
25-
where: { username: params.username },
26-
include: {
27-
_count: {
28-
select: { authoredArticles: true }
29-
}
30-
}
31-
})
22+
const author = await getAuthorByUsername(params.username)
3223

3324
if (!author) {
3425
notFound()

app/articles/authors/page.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
1-
import { prisma } from "@/lib/prisma"
21
import AuthorsList from "@/components/authors/AuthorsList"
2+
import { getAuthors } from "../articleActions"
33

44
export const metadata = {
55
title: 'Article Authors',
66
description: 'Browse all article authors'
77
}
88

9-
async function getAuthors() {
10-
const authors = await prisma.user.findMany({
11-
where: {
12-
authoredArticles: {
13-
some: {}
14-
}
15-
},
16-
include: {
17-
_count: {
18-
select: { authoredArticles: true }
19-
}
20-
},
21-
orderBy: {
22-
name: 'asc'
23-
}
24-
})
25-
return authors
26-
}
27-
289
export default async function AuthorsPage() {
2910
const authors = await getAuthors()
3011

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use client'
2+
3+
import { SignPetitionButton } from '@/app/petitions/components/SignPetitionButton'
4+
import { useEffect, useState } from 'react'
5+
import { useSession } from 'next-auth/react'
6+
import { checkPetitionSignature } from '@/app/petitions/petitionActions'
7+
8+
const neoBrutalistStyles = {
9+
button: "border-4 border-black p-4 text-lg font-bold transition-all hover:translate-x-1 hover:translate-y-1 hover:shadow-none bg-white shadow-[8px_8px_0px_0px_rgba(0,0,0,1)] text-black min-w-[200px] min-h-[60px] rounded-none",
10+
signed: "border-4 border-black p-4 text-lg font-bold bg-pink-400 shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:bg-pink-500 text-white min-w-[200px] min-h-[60px] rounded-none"
11+
}
12+
13+
export function DFDASignPetitionButton() {
14+
const { data: session } = useSession()
15+
const [hasSigned, setHasSigned] = useState(false)
16+
17+
useEffect(() => {
18+
let mounted = true
19+
20+
async function checkSignature() {
21+
if (!session?.user?.id) {
22+
if (mounted) setHasSigned(false)
23+
return
24+
}
25+
26+
try {
27+
const hasSignature = await checkPetitionSignature('right-to-trial-act')
28+
if (mounted) setHasSigned(hasSignature)
29+
} catch (error) {
30+
console.error('Failed to check signature status:', error)
31+
if (mounted) setHasSigned(false)
32+
}
33+
}
34+
35+
checkSignature()
36+
37+
return () => {
38+
mounted = false
39+
}
40+
}, [session?.user?.id])
41+
42+
return (
43+
<SignPetitionButton
44+
petitionId="right-to-trial-act"
45+
hasSigned={hasSigned}
46+
status="ACTIVE"
47+
className={neoBrutalistStyles.button}
48+
signedClassName={neoBrutalistStyles.signed}
49+
onSignatureChange={() => {
50+
// Toggle the hasSigned state immediately for better UX
51+
setHasSigned(prev => !prev)
52+
}}
53+
/>
54+
)
55+
}

app/dfda/right-to-trial-act/components/PetitionSection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client'
22

33
import { GitHubEditButton } from './GitHubEditButton'
4-
import { SignPetitionButton } from './SignPetitionButton'
4+
import { DFDASignPetitionButton } from './DFDASignPetitionButton'
55

66
export function PetitionSection() {
77
return (
@@ -10,8 +10,8 @@ export function PetitionSection() {
1010
<p className="text-xl mb-8 text-black">
1111
Sign the petition to support the Right to Trial Act and help end the suffering of billions of people.
1212
</p>
13-
<div className="flex flex-col sm:flex-row gap-4 justify-center">
14-
<SignPetitionButton />
13+
<div className="inline-flex gap-4 justify-center">
14+
<DFDASignPetitionButton />
1515
<GitHubEditButton />
1616
</div>
1717
</div>

app/dfda/right-to-trial-act/components/SignPetitionButton.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/dfda/right-to-trial-act/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Metadata } from 'next'
22
import { getMarkdownContent } from '@/lib/content/getMarkdownContent'
33
import { PetitionSection } from './components/PetitionSection'
44
import { FloatingPetitionButton } from './components/FloatingPetitionButton'
5-
import { SignPetitionButton } from './components/SignPetitionButton'
5+
import { DFDASignPetitionButton } from './components/DFDASignPetitionButton'
66
import CureAccelerationAct from './components/right-to-trial-act'
77
import { GitHubEditButton } from './components/GitHubEditButton'
88

@@ -50,7 +50,7 @@ export default async function RightToTrialPage() {
5050
{/* Bottom Petition Section */}
5151
<div className="mt-16 text-center border-t-4 pt-12">
5252
<h3 className="text-2xl font-serif mb-6">Add Your Name to Support This Act</h3>
53-
<SignPetitionButton /> <GitHubEditButton />
53+
<DFDASignPetitionButton /> <GitHubEditButton />
5454
</div>
5555
</div>
5656
</div>

app/globals.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,35 @@
5959
@apply bg-background text-foreground;
6060
}
6161
}
62+
63+
@import '@mdxeditor/editor/style.css';
64+
65+
/* Add dark mode styles for the editor */
66+
.dark .mdxeditor {
67+
--mdxeditor-bg: hsl(var(--background));
68+
--mdxeditor-text: hsl(var(--foreground));
69+
--mdxeditor-border: hsl(var(--border));
70+
--mdxeditor-toolbar-bg: hsl(var(--card));
71+
--mdxeditor-toolbar-border: hsl(var(--border));
72+
--mdxeditor-button-bg: transparent;
73+
--mdxeditor-button-border: hsl(var(--border));
74+
--mdxeditor-button-hover-bg: hsl(var(--accent));
75+
--mdxeditor-button-hover-text: hsl(var(--accent-foreground));
76+
--mdxeditor-button-active-bg: hsl(var(--accent));
77+
--mdxeditor-button-active-text: hsl(var(--accent-foreground));
78+
--mdxeditor-button-active-border: hsl(var(--border));
79+
}
80+
81+
.dark .mdxeditor-toolbar {
82+
background-color: hsl(var(--card));
83+
border-color: hsl(var(--border));
84+
}
85+
86+
.dark .mdxeditor-button {
87+
color: hsl(var(--foreground));
88+
}
89+
90+
.dark .mdxeditor-button:hover {
91+
background-color: hsl(var(--accent));
92+
color: hsl(var(--accent-foreground));
93+
}

0 commit comments

Comments
 (0)