Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/repo-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:
tests/integration/ballotQuestions.test.ts
tests/integration/backfillTestimonyScope.test.ts
tests/integration/conferences.test.ts
tests/integration/conferenceFollowing.test.ts
components/auth/hooks.test.ts
components/db/useUpcoming.test.ts
components/db/testimony
83 changes: 74 additions & 9 deletions components/EditProfilePage/FollowingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { flags } from "components/featureFlags"
import { dbService } from "components/db/api"
import { useBill } from "components/db"
import { formatBillId } from "components/formatting"
import { Internal } from "components/links"
import { Internal, maple } from "components/links"
import { conferenceName, isShown } from "components/conference/types"
import { getConference } from "components/db/conferences"
import {
FollowBallotQuestionButton,
FollowBillButton
FollowBillButton,
FollowConferenceTopicButton
} from "components/shared/FollowButton"
import { collection, onSnapshot, query, where } from "firebase/firestore"
import { useTranslation } from "next-i18next"
Expand All @@ -23,6 +26,7 @@ import {
export function FollowingTab({ className }: { className?: string }) {
const { t } = useTranslation("editProfile")
const followedBallotQuestions = useFollowedBallotQuestions()
const followedConferences = useFollowedConferences()
return (
<>
<PaginatedItemsCard
Expand All @@ -39,6 +43,14 @@ export function FollowingTab({ className }: { className?: string }) {
{...followedBallotQuestions}
/>
)}
{flags().conferences && (
<PaginatedItemsCard
className={className}
title={t("follow.conferences")}
ItemCard={FollowedConferenceCard}
{...followedConferences}
/>
)}
<PaginatedItemsCard
className={className}
title={t("follow.orgs")}
Expand All @@ -57,12 +69,24 @@ const useFollowedBallotQuestions = (): LoadableItemsState<
ComponentProps<typeof FollowedBallotQuestionCard>
> => useTopicSubscription("ballotQuestion")

const useFollowedConferences = (): LoadableItemsState<
ComponentProps<typeof FollowedConferenceCard>
> => useTopicSubscription("conference")

const useFollowedUsers = (): LoadableItemsState<
ComponentProps<typeof FollowUserCard>
> => useTopicSubscription("testimony")

/** The field of a subscription doc that says what is followed, by type. */
const TOPIC_KEYS = {
bill: "billLookup",
ballotQuestion: "ballotQuestionLookup",
conference: "conferenceLookup",
testimony: "userLookup"
} as const

function useTopicSubscription<T extends object>(
type: "bill" | "ballotQuestion" | "testimony"
type: keyof typeof TOPIC_KEYS
): LoadableItemsState<T> {
const [state, setState] = useState<LoadableItemsState<T>>({
items: [],
Expand All @@ -78,12 +102,7 @@ function useTopicSubscription<T extends object>(
: null,
[uid]
)
const topicKey =
type === "bill"
? "billLookup"
: type === "ballotQuestion"
? "ballotQuestionLookup"
: "userLookup"
const topicKey = TOPIC_KEYS[type]

useEffect(() => {
if (!subscriptionRef || !uid) return
Expand Down Expand Up @@ -190,3 +209,49 @@ function FollowedBallotQuestionCard({
</div>
)
}

/** A followed conference. One that is hidden, no longer taking input while
* closed conferences are off, keeps its row without a link, so the reader can
* still unfollow it. */
function FollowedConferenceCard({
conferenceId,
court
}: {
conferenceId: string
court: number
}) {
const { t } = useTranslation("editProfile")
const uid = useAuth().user?.uid
const {
loading,
error,
result: conference
} = useAsync(() => getConference(court, conferenceId), [court, conferenceId])
if (loading) return <Spinner animation="border" className="mx-auto" />
if (error) return <Alert variant="danger">{t("content.error")}</Alert>

const shown = conference && isShown(conference)

return (
<div className={`fs-3 lh-lg`}>
<Row className={`align-items-center flex-column flex-md-row`}>
<Col xs={12} md={8} className={`d-flex`}>
{shown ? (
<Internal href={maple.conference({ court, id: conferenceId })}>
{conferenceName(conference)}
</Internal>
) : (
<h6>{conference ? conferenceName(conference) : conferenceId}</h6>
)}
</Col>
<Col xs="auto" className="d-flex justify-content-end ms-auto p-0">
<FollowConferenceTopicButton
conference={{ id: conferenceId, court }}
confirmUnfollow
/>
</Col>
</Row>
<hr className={`mt-3`} />
</div>
)
}
3 changes: 3 additions & 0 deletions components/Newsfeed/Newsfeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ export default function Newsfeed() {
billId={element.billId}
bodyText={element.bodyText}
conferenceId={element.conferenceId}
conferenceName={element.conferenceName}
cosignOf={element.cosignOf}
court={element.court}
header={element.header}
isBillMatch={element.isBillMatch}
isConferenceMatch={element.isConferenceMatch}
isUserMatch={element.isUserMatch}
isBallotQuestionMatch={
element.isBallotQuestionMatch
Expand Down
6 changes: 6 additions & 0 deletions components/Newsfeed/NotificationProps.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Timestamp } from "firebase/firestore"
import type { CosignOf } from "functions/src/notifications/types"

export type { CosignOf }

export type NotificationProps = {
authorUid: string // Testimony author
Expand All @@ -25,6 +28,9 @@ export type NotificationProps = {
ballotStatus?: string
// Set on testimony to a committee of conference
conferenceId?: string | null
conferenceName?: string | null
isConferenceMatch?: boolean // is subscribed to the conference
cosignOf?: CosignOf | null // set when the testimony cosigns another
}

export type Notifications = NotificationProps[]
96 changes: 96 additions & 0 deletions components/NewsfeedCard/NewsfeedCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,102 @@ describe("NewsfeedCard", () => {
expect(document.querySelector("a[href^='/testimony/']")).toBeNull()
})

it("says a reader follows the conference, by name, when that is the match", () => {
render(
<NewsfeedCard
{...testimony}
isUserMatch={false}
isConferenceMatch={true}
conferenceId="phones"
conferenceName="Phone-Free Schools"
position="passSomething"
/>
)

const reason = screen.getByText("newsfeed.follow").closest(".card-title")!
expect(reason).toHaveTextContent("newsfeed.followPhone-Free Schools")
expect(reason).not.toHaveTextContent("Alice")
})

it("names the conference and the author when the reader follows both", () => {
render(
<NewsfeedCard
{...testimony}
isConferenceMatch={true}
conferenceId="phones"
conferenceName={null}
position="passSomething"
/>
)

// With no name stored, the conference goes by its bill's title.
const titles = Array.from(document.querySelectorAll(".card-title"))
expect(titles.map(t => t.textContent)).toContain(
"newsfeed.followAn Act relative to student learningnewsfeed.andAlice"
)
})

describe("a cosign", () => {
const cosignOf = {
authorName: "Grace",
content: "Pass a strong final bill this session."
}
const quoted = () => document.querySelector("blockquote")

it("is tagged, with its own line first and the cosigned input under it", () => {
render(
<NewsfeedCard
{...testimony}
bodyText="As a parent, this matters to me."
conferenceId="phones"
cosignOf={cosignOf}
position="passSomething"
/>
)

expect(screen.getByText("newsfeed.cosigned")).toBeInTheDocument()
expect(screen.getByText("newsfeed.conferenceCosign")).toBeInTheDocument()
expect(screen.queryByText("newsfeed.conferenceInput")).toBeNull()
const line = screen.getByText('"As a parent, this matters to me."')
const credit = screen.getByText("newsfeed.cosignedInput")
expect(
line.compareDocumentPosition(credit) & Node.DOCUMENT_POSITION_FOLLOWING
).toBeTruthy()
expect(quoted()).toHaveTextContent(cosignOf.content)
})

it("shows the cosigned input without an empty quote when it has no line", () => {
render(
<NewsfeedCard
{...testimony}
bodyText=""
conferenceId="phones"
cosignOf={cosignOf}
position="passSomething"
/>
)

expect(screen.getByText("newsfeed.cosigned")).toBeInTheDocument()
expect(screen.queryByText('""')).toBeNull()
expect(screen.getByText("newsfeed.cosignedInput")).toBeInTheDocument()
expect(quoted()).toHaveTextContent(cosignOf.content)
})

it("isn't tagged on input that cosigns nothing", () => {
render(
<NewsfeedCard
{...testimony}
conferenceId="phones"
position="passSomething"
/>
)

expect(screen.queryByText("newsfeed.cosigned")).toBeNull()
expect(screen.getByText("newsfeed.conferenceInput")).toBeInTheDocument()
expect(quoted()).toBeNull()
})
})

it("keeps bill testimony on its bill, testimony page and thumbs", () => {
render(<NewsfeedCard {...testimony} position="endorse" />)

Expand Down
8 changes: 8 additions & 0 deletions components/NewsfeedCard/NewsfeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "./NewsfeedCardBody"
import NewsfeedCardTitle from "./NewsfeedCardTitle"
import { maple } from "components/links"
import { CosignOf } from "../Newsfeed/NotificationProps"

const Container = styled.div`
max-width: 700px;
Expand All @@ -22,10 +23,13 @@ export const NewsfeedCard = (props: {
billId?: string
bodyText: string
conferenceId?: string | null
conferenceName?: string | null
cosignOf?: CosignOf | null
court?: string
header: string
isBallotQuestionMatch?: boolean
isBillMatch?: boolean
isConferenceMatch?: boolean
isUserMatch?: boolean
position?: string
subheader?: string
Expand All @@ -45,10 +49,13 @@ export const NewsfeedCard = (props: {
authorUid={props.authorUid}
billId={props.billId}
conferenceHref={conferenceHref}
conferenceName={props.conferenceName}
cosigned={!!props.cosignOf}
court={props.court}
header={props.header}
isBallotQuestionMatch={props.isBallotQuestionMatch}
isBillMatch={props.isBillMatch}
isConferenceMatch={props.isConferenceMatch}
isUserMatch={props.isUserMatch}
subheader={props.subheader}
timestamp={formattedTimestamp}
Expand All @@ -71,6 +78,7 @@ export const NewsfeedCard = (props: {
<NewsfeedConferenceTestimonyCardBody
billText={props.header}
conferenceHref={conferenceHref}
cosignOf={props.cosignOf}
position={props.position}
text={props.bodyText}
timestamp={formattedTimestamp}
Expand Down
42 changes: 32 additions & 10 deletions components/NewsfeedCard/NewsfeedCardBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Col, Row } from "../bootstrap"
import { Internal } from "components/links"
import { truncateText } from "components/formatting"
import { ConferencePosition } from "components/db"
import { PositionChip } from "components/conference/input/Entry"
import { Cosigned, PositionChip } from "components/conference/input/Entry"
import { CosignOf } from "../Newsfeed/NotificationProps"

export const NewsfeedBallotQuestionCardBody = ({
ballotQuestionId,
Expand Down Expand Up @@ -196,16 +197,22 @@ export const NewsfeedTestimonyCardBody = (props: NewsfeedCardBodyProps) => {
)
}

/** Testimony on a committee of conference: the stance is the conference
* page's chip, and the card leads to the conference, not the bill. */
/**
* Testimony on a committee of conference: the stance is the conference page's
* chip, and the card leads to the conference, not the bill. A cosign is
* tagged, with the cosigner's own line first when they wrote one and the
* input they cosigned quoted under it, as the email to their legislators sets
* it out. That quote arrives already trimmed.
*/
export const NewsfeedConferenceTestimonyCardBody = (props: {
billText?: string
conferenceHref: string
cosignOf?: CosignOf | null
position?: string
text?: string
timestamp?: string
}) => {
const { billText, conferenceHref, text, timestamp } = props
const { billText, conferenceHref, cosignOf, text, timestamp } = props
const { t } = useTranslation("common")

return (
Expand All @@ -215,13 +222,28 @@ export const NewsfeedConferenceTestimonyCardBody = (props: {
<strong>{billText}</strong>
</CardBootstrap.Text>
<div className={`bg-body mx-0 mt-1 p-3 rounded`}>
{ConferencePosition.guard(props.position) && (
<PositionChip position={props.position} long />
<div className={`d-flex flex-wrap align-items-center gap-2`}>
{ConferencePosition.guard(props.position) && (
<PositionChip position={props.position} long />
)}
{cosignOf && <Cosigned>{t("newsfeed.cosigned")}</Cosigned>}
</div>
{(text || !cosignOf) && (
<strong className={`d-block mt-2`}>{`"${truncateText(
text,
600
)}"`}</strong>
)}
{cosignOf && (
<>
<div className={`mt-2`}>
{t("newsfeed.cosignedInput", { name: cosignOf.authorName })}
</div>
<blockquote className={`border-start border-3 ps-3 mt-1 mb-0`}>
{cosignOf.content}
</blockquote>
</>
)}
<strong className={`d-block mt-2`}>{`"${truncateText(
text,
600
)}"`}</strong>
</div>
<div className={`d-flex flex-wrap justify-content-between mt-2 mb-2`}>
<div>
Expand Down
Loading
Loading