267 lines
10 KiB
JavaScript
267 lines
10 KiB
JavaScript
import "./PoliticsSidebar.js"
|
|
import "./PoliticsRepresentatives.js"
|
|
import "./PoliticsElections.js"
|
|
|
|
css(`
|
|
politics- {
|
|
font-family: 'Arial';
|
|
scrollbar-width: none;
|
|
-ms-overflow-style: none;
|
|
}
|
|
`)
|
|
|
|
class Politics extends Shadow {
|
|
constructor() {
|
|
super()
|
|
this.view = "representatives"
|
|
this.levelFilter = "all"
|
|
|
|
this.jurisdiction = {
|
|
federal: "TX-21",
|
|
stateSenate: "SD-25",
|
|
stateHouse: "HD-20",
|
|
county: "Comal County",
|
|
}
|
|
|
|
this.representatives = [
|
|
// ── Federal ───────────────────────────────────────────────
|
|
{
|
|
id: 1, level: "federal",
|
|
name: "John Cornyn", initials: "JC",
|
|
title: "U.S. Senator", party: "R",
|
|
district: "Texas (Class 2)", since: 2002,
|
|
phone: "(202) 224-2934", website: "cornyn.senate.gov",
|
|
},
|
|
{
|
|
id: 2, level: "federal",
|
|
name: "Ted Cruz", initials: "TC",
|
|
title: "U.S. Senator", party: "R",
|
|
district: "Texas (Class 1)", since: 2013,
|
|
phone: "(202) 224-5922", website: "cruz.senate.gov",
|
|
},
|
|
{
|
|
id: 3, level: "federal",
|
|
name: "Chip Roy", initials: "CR",
|
|
title: "U.S. Representative", party: "R",
|
|
district: "TX-21", since: 2019,
|
|
phone: "(202) 225-4236", website: "roy.house.gov",
|
|
},
|
|
|
|
// ── State ─────────────────────────────────────────────────
|
|
{
|
|
id: 4, level: "state",
|
|
name: "Donna Campbell", initials: "DC",
|
|
title: "Texas State Senator", party: "R",
|
|
district: "Senate District 25", since: 2013,
|
|
phone: "(512) 463-0125", website: "senate.texas.gov/member.php?d=25",
|
|
},
|
|
{
|
|
id: 5, level: "state",
|
|
name: "Terry Wilson", initials: "TW",
|
|
title: "Texas State Representative", party: "R",
|
|
district: "House District 20", since: 2017,
|
|
phone: "(512) 463-0309", website: "house.texas.gov/members/member-page/?district=20",
|
|
},
|
|
{
|
|
id: 6, level: "state",
|
|
name: "Ken Paxton", initials: "KP",
|
|
title: "Texas Attorney General", party: "R",
|
|
district: "Statewide", since: 2015,
|
|
phone: "(512) 463-2100", website: "texasattorneygeneral.gov",
|
|
},
|
|
|
|
// ── Local ─────────────────────────────────────────────────
|
|
{
|
|
id: 7, level: "local",
|
|
name: "Sherman Krause", initials: "SK",
|
|
title: "Comal County Judge", party: "R",
|
|
district: "Comal County", since: 2019,
|
|
phone: "(830) 221-1100", website: "co.comal.tx.us",
|
|
},
|
|
{
|
|
id: 8, level: "local",
|
|
name: "Mark Reynolds", initials: "MR",
|
|
title: "County Sheriff", party: "R",
|
|
district: "Comal County", since: 2017,
|
|
phone: "(830) 620-3400", website: null,
|
|
},
|
|
{
|
|
id: 9, level: "local",
|
|
name: "Jane Guerrero", initials: "JG",
|
|
title: "New Braunfels Mayor", party: "I",
|
|
district: "City of New Braunfels", since: 2021,
|
|
phone: "(830) 221-4000", website: "newbraunfels.gov",
|
|
},
|
|
]
|
|
|
|
const future = (d) => new Date(Date.now() + d * 86400000)
|
|
const past = (d) => new Date(Date.now() - d * 86400000)
|
|
|
|
this.elections = [
|
|
// Upcoming
|
|
{
|
|
id: 1,
|
|
level: "federal",
|
|
title: "U.S. Senate — Texas",
|
|
type: "general",
|
|
date: future(209),
|
|
description: "Class 2 seat — John Cornyn defending",
|
|
userVoteId: null,
|
|
userThumbsUp: false,
|
|
thumbsUp: 14,
|
|
candidates: [
|
|
{ id: 101, name: "John Cornyn", initials: "JC", party: "R", incumbent: true, votes: 312 },
|
|
{ id: 102, name: "Colin Allred", initials: "CA", party: "D", incumbent: false, votes: 187 },
|
|
]
|
|
},
|
|
{
|
|
id: 2,
|
|
level: "federal",
|
|
title: "U.S. House — TX-21",
|
|
type: "general",
|
|
date: future(209),
|
|
description: "Chip Roy vs. challenger",
|
|
userVoteId: null,
|
|
userThumbsUp: true,
|
|
thumbsUp: 31,
|
|
candidates: [
|
|
{ id: 201, name: "Chip Roy", initials: "CR", party: "R", incumbent: true, votes: 278 },
|
|
{ id: 202, name: "Marc Segers", initials: "MS", party: "D", incumbent: false, votes: 91 },
|
|
]
|
|
},
|
|
{
|
|
id: 3,
|
|
level: "state",
|
|
title: "Texas House District 20",
|
|
type: "primary",
|
|
date: future(42),
|
|
description: "Republican primary — open seat",
|
|
userVoteId: null,
|
|
userThumbsUp: false,
|
|
thumbsUp: 8,
|
|
candidates: [
|
|
{ id: 301, name: "Terry Wilson", initials: "TW", party: "R", incumbent: true, votes: 203 },
|
|
{ id: 302, name: "Brad Fischer", initials: "BF", party: "R", incumbent: false, votes: 144 },
|
|
]
|
|
},
|
|
{
|
|
id: 4,
|
|
level: "local",
|
|
title: "Comal County Commissioner Pct. 2",
|
|
type: "general",
|
|
date: future(12),
|
|
description: "Precinct 2 seat",
|
|
userVoteId: null,
|
|
userThumbsUp: false,
|
|
thumbsUp: 5,
|
|
candidates: [
|
|
{ id: 401, name: "Lisa Hartmann", initials: "LH", party: "R", incumbent: false, votes: 89 },
|
|
{ id: 402, name: "David Moreno", initials: "DM", party: "D", incumbent: false, votes: 53 },
|
|
]
|
|
},
|
|
{
|
|
id: 5,
|
|
level: "local",
|
|
title: "New Braunfels City Council At-Large",
|
|
type: "special",
|
|
date: future(6),
|
|
description: "Filling vacant at-large seat",
|
|
userVoteId: null,
|
|
userThumbsUp: false,
|
|
thumbsUp: 22,
|
|
candidates: [
|
|
{ id: 501, name: "Karen Ellis", initials: "KE", party: "I", incumbent: false, votes: 112 },
|
|
{ id: 502, name: "Tom Riggs", initials: "TR", party: "I", incumbent: false, votes: 74 },
|
|
{ id: 503, name: "Anita Solis", initials: "AS", party: "I", incumbent: false, votes: 41 },
|
|
]
|
|
},
|
|
|
|
// Recent/past
|
|
{
|
|
id: 6,
|
|
level: "state",
|
|
title: "Texas Senate District 25",
|
|
type: "primary",
|
|
date: past(48),
|
|
description: "Donna Campbell won unopposed",
|
|
userVoteId: 601,
|
|
userThumbsUp: true,
|
|
thumbsUp: 41,
|
|
candidates: [
|
|
{ id: 601, name: "Donna Campbell", initials: "DC", party: "R", incumbent: true, votes: 487 },
|
|
]
|
|
},
|
|
{
|
|
id: 7,
|
|
level: "local",
|
|
title: "Comal County Sheriff",
|
|
type: "general",
|
|
date: past(180),
|
|
description: "Mark Reynolds re-elected",
|
|
userVoteId: 701,
|
|
userThumbsUp: false,
|
|
thumbsUp: 19,
|
|
candidates: [
|
|
{ id: 701, name: "Mark Reynolds", initials: "MR", party: "R", incumbent: true, votes: 623 },
|
|
{ id: 702, name: "Phil Sanderson", initials: "PS", party: "D", incumbent: false, votes: 214 },
|
|
]
|
|
},
|
|
]
|
|
}
|
|
|
|
handleVote(electionId, candidateId) {
|
|
const election = this.elections.find(e => e.id === electionId)
|
|
if (!election || election.userVoteId) return
|
|
election.userVoteId = candidateId
|
|
const candidate = election.candidates.find(c => c.id === candidateId)
|
|
if (candidate) candidate.votes++
|
|
this.rerender()
|
|
}
|
|
|
|
handleThumbsUp(electionId) {
|
|
const election = this.elections.find(e => e.id === electionId)
|
|
if (!election) return
|
|
election.userThumbsUp = !election.userThumbsUp
|
|
election.thumbsUp += election.userThumbsUp ? 1 : -1
|
|
this.rerender()
|
|
}
|
|
|
|
render() {
|
|
HStack(() => {
|
|
// Sidebar
|
|
VStack(() => {
|
|
PoliticsSidebar(
|
|
this.view,
|
|
this.levelFilter,
|
|
(v) => { this.view = v; this.rerender(); },
|
|
(l) => { this.levelFilter = l; this.rerender(); },
|
|
this.jurisdiction,
|
|
this.elections
|
|
)
|
|
})
|
|
.width(230, px).minWidth(210, px)
|
|
.height(100, pct)
|
|
.borderRight("1px solid var(--divider)")
|
|
.flexShrink(0).overflow("hidden")
|
|
|
|
// Main
|
|
VStack(() => {
|
|
if (this.view === "representatives") {
|
|
PoliticsRepresentatives(this.representatives, this.levelFilter)
|
|
} else {
|
|
PoliticsElections(
|
|
this.elections,
|
|
this.levelFilter,
|
|
(electionId, candidateId) => this.handleVote(electionId, candidateId),
|
|
(electionId) => this.handleThumbsUp(electionId)
|
|
)
|
|
}
|
|
})
|
|
.flex(1).height(100, pct).overflow("hidden")
|
|
})
|
|
.height(100, pct).width(100, pct).overflow("hidden")
|
|
}
|
|
}
|
|
|
|
register(Politics)
|