From 5c26e0458cc249e22b482130e599e47bb75b0564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20F=C3=B6rtsch?= Date: Mon, 2 Mar 2026 21:38:14 +0100 Subject: [PATCH] fix polls API call, move themen back to tabbar, configure only for MdB/MdL Co-Authored-By: Claude Opus 4.6 --- .../components/bundestag-configure.tsx | 31 ++++------- .../bundestag/lib/assemble-bundestag-feed.ts | 5 +- src/features/bundestag/store.ts | 4 -- .../landtag/components/landtag-configure.tsx | 53 ++++++++----------- .../landtag/components/landtag-page.tsx | 53 ++----------------- src/features/landtag/store.ts | 4 -- src/features/topics/components/topic-list.tsx | 9 ++++ src/features/topics/index.ts | 1 + src/features/topics/store.ts | 11 ++++ src/routeTree.gen.ts | 21 ++++++++ src/routes/app/route.tsx | 7 ++- src/routes/app/topics.tsx | 6 +++ src/shared/lib/aw-api.ts | 13 ----- 13 files changed, 90 insertions(+), 128 deletions(-) create mode 100644 src/features/topics/components/topic-list.tsx create mode 100644 src/features/topics/index.ts create mode 100644 src/features/topics/store.ts create mode 100644 src/routes/app/topics.tsx diff --git a/src/features/bundestag/components/bundestag-configure.tsx b/src/features/bundestag/components/bundestag-configure.tsx index 95b5805..f135b74 100644 --- a/src/features/bundestag/components/bundestag-configure.tsx +++ b/src/features/bundestag/components/bundestag-configure.tsx @@ -1,5 +1,4 @@ import { RepresentativeList } from "@/shared/components/representative-list" -import { TopicToggleList } from "@/shared/components/topic-toggle-list" import { useDb } from "@/shared/db/provider" import type { MandateWithPolitician } from "@/shared/lib/aw-api" import { useEffect, useState } from "react" @@ -8,8 +7,6 @@ import { useBundestagUI } from "../store" export function BundestagConfigure() { const db = useDb() - const topicSearch = useBundestagUI((s) => s.topicSearch) - const setTopicSearch = useBundestagUI((s) => s.setTopicSearch) const politicianSearch = useBundestagUI((s) => s.politicianSearch) const setPoliticianSearch = useBundestagUI((s) => s.setPoliticianSearch) @@ -25,25 +22,15 @@ export function BundestagConfigure() { return (
-
-

Themen

- -
- -
-

- Abgeordnete -

- {loadingMandates ? ( -
-
-
- ) : mandates.length > 0 ? ( - - ) : ( -

Keine Abgeordneten verfügbar.

- )} -
+ {loadingMandates ? ( +
+
+
+ ) : mandates.length > 0 ? ( + + ) : ( +

Keine Abgeordneten verfügbar.

+ )}
) } diff --git a/src/features/bundestag/lib/assemble-bundestag-feed.ts b/src/features/bundestag/lib/assemble-bundestag-feed.ts index e929cab..4940a2a 100644 --- a/src/features/bundestag/lib/assemble-bundestag-feed.ts +++ b/src/features/bundestag/lib/assemble-bundestag-feed.ts @@ -2,12 +2,11 @@ import type { FeedItem } from "@/features/feed/lib/assemble-feed" import { type Poll, fetchCandidacyMandates, + fetchPolls, fetchPollsByIds, - fetchPollsByLegislature, fetchTopics, fetchVotes, } from "@/shared/lib/aw-api" -import { BUNDESTAG_LEGISLATURE_ID } from "@/shared/lib/constants" import { fetchUpcomingVorgaenge } from "@/shared/lib/dip-api" export async function assembleBundestagFeed( @@ -16,7 +15,7 @@ export async function assembleBundestagFeed( ): Promise { const [topics, polls, vorgaenge] = await Promise.all([ fetchTopics(), - fetchPollsByLegislature(BUNDESTAG_LEGISLATURE_ID, 150), + fetchPolls(150), fetchUpcomingVorgaenge().catch(() => []), ]) diff --git a/src/features/bundestag/store.ts b/src/features/bundestag/store.ts index 7f2d38b..af85d38 100644 --- a/src/features/bundestag/store.ts +++ b/src/features/bundestag/store.ts @@ -1,15 +1,11 @@ import { create } from "zustand" interface BundestagUIState { - topicSearch: string - setTopicSearch: (query: string) => void politicianSearch: string setPoliticianSearch: (query: string) => void } export const useBundestagUI = create((set) => ({ - topicSearch: "", - setTopicSearch: (query) => set({ topicSearch: query }), politicianSearch: "", setPoliticianSearch: (query) => set({ politicianSearch: query }), })) diff --git a/src/features/landtag/components/landtag-configure.tsx b/src/features/landtag/components/landtag-configure.tsx index 2324416..2e78885 100644 --- a/src/features/landtag/components/landtag-configure.tsx +++ b/src/features/landtag/components/landtag-configure.tsx @@ -1,5 +1,4 @@ import { RepresentativeList } from "@/shared/components/representative-list" -import { TopicToggleList } from "@/shared/components/topic-toggle-list" import { useDb } from "@/shared/db/provider" import type { MandateWithPolitician } from "@/shared/lib/aw-api" import { Link } from "@tanstack/react-router" @@ -9,10 +8,8 @@ import { useLandtagUI } from "../store" export function LandtagConfigure() { const db = useDb() - const topicSearch = useLandtagUI((s) => s.topicSearch) - const setTopicSearch = useLandtagUI((s) => s.setTopicSearch) - const politicianSearch = useLandtagUI((s) => s.politicianSearch) - const setPoliticianSearch = useLandtagUI((s) => s.setPoliticianSearch) + const search = useLandtagUI((s) => s.politicianSearch) + const setSearch = useLandtagUI((s) => s.setPoliticianSearch) const [mandates, setMandates] = useState([]) const [loaded, setLoaded] = useState(false) @@ -23,34 +20,28 @@ export function LandtagConfigure() { }) }, [db]) + if (loaded && mandates.length === 0) { + return ( +
+

+ Noch keine Abgeordneten geladen. Erkenne zuerst deinen Standort in den Einstellungen. +

+ + Zu den Einstellungen + +
+ ) + } + return (
-
-

Themen

- -
- -
-

- Abgeordnete -

- {!loaded ? ( -
-
-
- ) : mandates.length > 0 ? ( - - ) : ( -
-

- Noch keine Abgeordneten geladen. Erkenne zuerst deinen Standort in den Einstellungen. -

- - Zu den Einstellungen - -
- )} -
+ {!loaded ? ( +
+
+
+ ) : ( + + )}
) } diff --git a/src/features/landtag/components/landtag-page.tsx b/src/features/landtag/components/landtag-page.tsx index c5b4e1f..3cb622e 100644 --- a/src/features/landtag/components/landtag-page.tsx +++ b/src/features/landtag/components/landtag-page.tsx @@ -1,55 +1,8 @@ -import { RepresentativeList } from "@/shared/components/representative-list" -import { useDb } from "@/shared/db/provider" -import type { MandateWithPolitician } from "@/shared/lib/aw-api" -import { Link } from "@tanstack/react-router" -import { useEffect, useState } from "react" -import { type GeoResult, loadCachedResult } from "../../location/lib/geo" -import { useLandtagUI } from "../store" - export function LandtagPage() { - const db = useDb() - const [result, setResult] = useState(null) - const [mandates, setMandates] = useState([]) - const search = useLandtagUI((s) => s.politicianSearch) - const setSearch = useLandtagUI((s) => s.setPoliticianSearch) - - useEffect(() => { - loadCachedResult(db).then((cached) => { - if (cached) { - setResult(cached) - setMandates(cached.mandates) - } - }) - }, [db]) - - if (!result || mandates.length === 0) { - return ( -
-

Landtag

-

- Erkenne zuerst deinen Standort in den Einstellungen, um deine Landtagsabgeordneten zu sehen. -

- - Zu den Einstellungen - -
- ) - } - return ( -
- {result.landtag_label && ( -
-

{result.landtag_label}

- {result.bundesland &&

{result.bundesland}

} -
- )} - - - -
-

Abstimmungsdaten folgen in Kürze

-
+
+

Landtag

+

Abstimmungsdaten folgen in Kürze.

) } diff --git a/src/features/landtag/store.ts b/src/features/landtag/store.ts index 061ba66..c12ee64 100644 --- a/src/features/landtag/store.ts +++ b/src/features/landtag/store.ts @@ -1,15 +1,11 @@ import { create } from "zustand" interface LandtagUIState { - topicSearch: string - setTopicSearch: (query: string) => void politicianSearch: string setPoliticianSearch: (query: string) => void } export const useLandtagUI = create((set) => ({ - topicSearch: "", - setTopicSearch: (query) => set({ topicSearch: query }), politicianSearch: "", setPoliticianSearch: (query) => set({ politicianSearch: query }), })) diff --git a/src/features/topics/components/topic-list.tsx b/src/features/topics/components/topic-list.tsx new file mode 100644 index 0000000..65d24e2 --- /dev/null +++ b/src/features/topics/components/topic-list.tsx @@ -0,0 +1,9 @@ +import { TopicToggleList } from "@/shared/components/topic-toggle-list" +import { useTopicsUI } from "../store" + +export function TopicList() { + const search = useTopicsUI((s) => s.searchQuery) + const setSearch = useTopicsUI((s) => s.setSearchQuery) + + return +} diff --git a/src/features/topics/index.ts b/src/features/topics/index.ts new file mode 100644 index 0000000..0a4ebce --- /dev/null +++ b/src/features/topics/index.ts @@ -0,0 +1 @@ +export { TopicList } from "./components/topic-list" diff --git a/src/features/topics/store.ts b/src/features/topics/store.ts new file mode 100644 index 0000000..7807093 --- /dev/null +++ b/src/features/topics/store.ts @@ -0,0 +1,11 @@ +import { create } from "zustand" + +interface TopicsUIState { + searchQuery: string + setSearchQuery: (query: string) => void +} + +export const useTopicsUI = create((set) => ({ + searchQuery: "", + setSearchQuery: (query) => set({ searchQuery: query }), +})) diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 0ca7240..99cf653 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -11,6 +11,7 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as AppRouteRouteImport } from './routes/app/route' import { Route as IndexRouteImport } from './routes/index' +import { Route as AppTopicsRouteImport } from './routes/app/topics' import { Route as AppSettingsRouteImport } from './routes/app/settings' import { Route as AppHomeRouteImport } from './routes/app/home' import { Route as AppLandtagRouteRouteImport } from './routes/app/landtag/route' @@ -30,6 +31,11 @@ const IndexRoute = IndexRouteImport.update({ path: '/', getParentRoute: () => rootRouteImport, } as any) +const AppTopicsRoute = AppTopicsRouteImport.update({ + id: '/topics', + path: '/topics', + getParentRoute: () => AppRouteRoute, +} as any) const AppSettingsRoute = AppSettingsRouteImport.update({ id: '/settings', path: '/settings', @@ -78,6 +84,7 @@ export interface FileRoutesByFullPath { '/app/landtag': typeof AppLandtagRouteRouteWithChildren '/app/home': typeof AppHomeRoute '/app/settings': typeof AppSettingsRoute + '/app/topics': typeof AppTopicsRoute '/app/bundestag/configure': typeof AppBundestagConfigureRoute '/app/landtag/configure': typeof AppLandtagConfigureRoute '/app/bundestag/': typeof AppBundestagIndexRoute @@ -88,6 +95,7 @@ export interface FileRoutesByTo { '/app': typeof AppRouteRouteWithChildren '/app/home': typeof AppHomeRoute '/app/settings': typeof AppSettingsRoute + '/app/topics': typeof AppTopicsRoute '/app/bundestag/configure': typeof AppBundestagConfigureRoute '/app/landtag/configure': typeof AppLandtagConfigureRoute '/app/bundestag': typeof AppBundestagIndexRoute @@ -101,6 +109,7 @@ export interface FileRoutesById { '/app/landtag': typeof AppLandtagRouteRouteWithChildren '/app/home': typeof AppHomeRoute '/app/settings': typeof AppSettingsRoute + '/app/topics': typeof AppTopicsRoute '/app/bundestag/configure': typeof AppBundestagConfigureRoute '/app/landtag/configure': typeof AppLandtagConfigureRoute '/app/bundestag/': typeof AppBundestagIndexRoute @@ -115,6 +124,7 @@ export interface FileRouteTypes { | '/app/landtag' | '/app/home' | '/app/settings' + | '/app/topics' | '/app/bundestag/configure' | '/app/landtag/configure' | '/app/bundestag/' @@ -125,6 +135,7 @@ export interface FileRouteTypes { | '/app' | '/app/home' | '/app/settings' + | '/app/topics' | '/app/bundestag/configure' | '/app/landtag/configure' | '/app/bundestag' @@ -137,6 +148,7 @@ export interface FileRouteTypes { | '/app/landtag' | '/app/home' | '/app/settings' + | '/app/topics' | '/app/bundestag/configure' | '/app/landtag/configure' | '/app/bundestag/' @@ -164,6 +176,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/app/topics': { + id: '/app/topics' + path: '/topics' + fullPath: '/app/topics' + preLoaderRoute: typeof AppTopicsRouteImport + parentRoute: typeof AppRouteRoute + } '/app/settings': { id: '/app/settings' path: '/settings' @@ -255,6 +274,7 @@ interface AppRouteRouteChildren { AppLandtagRouteRoute: typeof AppLandtagRouteRouteWithChildren AppHomeRoute: typeof AppHomeRoute AppSettingsRoute: typeof AppSettingsRoute + AppTopicsRoute: typeof AppTopicsRoute } const AppRouteRouteChildren: AppRouteRouteChildren = { @@ -262,6 +282,7 @@ const AppRouteRouteChildren: AppRouteRouteChildren = { AppLandtagRouteRoute: AppLandtagRouteRouteWithChildren, AppHomeRoute: AppHomeRoute, AppSettingsRoute: AppSettingsRoute, + AppTopicsRoute: AppTopicsRoute, } const AppRouteRouteWithChildren = AppRouteRoute._addFileChildren( diff --git a/src/routes/app/route.tsx b/src/routes/app/route.tsx index 6c6295a..9f79776 100644 --- a/src/routes/app/route.tsx +++ b/src/routes/app/route.tsx @@ -24,6 +24,11 @@ const TABS: TabDef[] = [ label: "Landtag", icon: "M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z", }, + { + to: "/app/topics", + label: "Themen", + icon: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2", + }, { to: "/app/settings", label: "Einstellungen", @@ -87,7 +92,7 @@ function AppLayout() { ) : null}

- {isConfigureRoute ? `${currentTab.label} konfigurieren` : currentTab.label} + {isConfigureRoute ? "Abgeordnete" : currentTab.label}

{!isConfigureRoute && configureTarget && ( { return request("votes", { mandate: String(mandateID), range_end: "200" }, voteSchema) } -export function fetchPollsByLegislature(legislatureId: number, rangeEnd = 150): Promise { - return request( - "polls", - { - parliament_period: String(legislatureId), - range_end: String(rangeEnd), - sort_by: "field_poll_date", - sort_direction: "desc", - }, - pollSchema, - ) -} - export function fetchMandatesByParliamentPeriod(periodID: number): Promise { return request( "candidacies-mandates",