Skip to content

Commit b8b698f

Browse files
committed
refactor(astro): ♻️ Move shared React components to common directory
Move reusable components and utilities (`useDataLoader`, `QueryProvider`, `PrivacyToggleCompact`) into the `common` directory to improve organization and reduce duplication. Also includes: * Add boilerplate `index.ts` files with copyright headers to component folders. * Improve typing clarity in dashboard components. * Add CSS fallback animation for progressive enhancement reveal state.
1 parent f146171 commit b8b698f

File tree

17 files changed

+237
-24
lines changed

17 files changed

+237
-24
lines changed

apps/api/src/services/agencies/agency-search.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
* @compliance NIST 800-53 SI-10 (Information Input Validation)
3030
*/
3131

32-
import { db, schema } from '@/db';
33-
import type { Agency } from '@/types';
3432
import {
3533
createAgencyHierarchy,
3634
createAgencyTrie,
@@ -41,6 +39,9 @@ import {
4139
} from '@foia-stream/shared';
4240
import { Schema as S } from 'effect';
4341

42+
import { db, schema } from '@/db';
43+
import type { Agency } from '@/types';
44+
4445
// ============================================
4546
// Types
4647
// ============================================
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1+
/**
2+
* Copyright (c) 2025 Foia Stream
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
123
export { default as AgenciesPage } from './agencies-page';
224
export { default as AgencySearch } from './agency-search';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* Copyright (c) 2025 Foia Stream
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
123
export { default as LoginForm } from './login-form';
224
export { default as Onboarding } from './onboarding';
325
export { default as RegisterForm } from './register-form';

apps/astro/src/components/react/auth/onboarding.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import { ArrowRight, Check, ChevronLeft, FileText, Search, Send, Sparkles } from 'lucide-react';
2929
import { useEffect, useState } from 'react';
30-
import { $user, useAuthStore } from '@/stores/auth';
30+
import { useAuthStore } from '@/stores/auth';
3131

3232
/**
3333
* Onboarding step configuration

apps/astro/src/components/react/common/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* Copyright (c) 2025 Foia Stream
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
123
export { default as EffectDataLoader } from './effect-data-loader';
224
export { EmptyState, ErrorBoundary, ErrorDisplay } from './error-boundary';
325
export { default as PrivacyToggle } from './privacy-toggle';

apps/astro/src/components/react/dashboard/dashboard-content.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
* @author FOIA Stream Team
2727
*/
2828

29-
import type { FoiaRequest } from '@/lib/api';
30-
import { API_BASE } from '@/lib/config';
31-
import { formatDate, getStatusColor } from '@/lib/utils';
32-
import { initAuth, logout, useAuthStore } from '@/stores/auth';
3329
import {
3430
Building2,
3531
ChevronDown,
@@ -43,7 +39,12 @@ import {
4339
User,
4440
} from 'lucide-react';
4541
import { Suspense, useEffect, useRef, useState } from 'react';
46-
import { useDataLoader } from './effect-data-loader';
42+
43+
import type { FoiaRequest } from '@/lib/api';
44+
import { API_BASE } from '@/lib/config';
45+
import { formatDate, getStatusColor } from '@/lib/utils';
46+
import { initAuth, logout, useAuthStore } from '@/stores/auth';
47+
import { useDataLoader } from '../common/effect-data-loader';
4748

4849
interface RequestsResponse {
4950
data: FoiaRequest[];
@@ -64,7 +65,7 @@ function RequestsList({ onRefetch }: { onRefetch?: (refetch: () => Promise<void>
6465
refetchOnWindowFocus: false,
6566
});
6667

67-
const requests = data?.data || [];
68+
const requests: FoiaRequest[] = data?.data || [];
6869

6970
useEffect(() => {
7071
if (onRefetch) {
@@ -129,12 +130,13 @@ function DashboardStats() {
129130
refetchOnWindowFocus: false,
130131
});
131132

132-
const requests = data?.data || [];
133+
const requests: FoiaRequest[] = data?.data || [];
133134

134135
const pendingCount = requests.filter(
135-
(r) => r.status === 'submitted' || r.status === 'processing' || r.status === 'acknowledged',
136+
(r: FoiaRequest) =>
137+
r.status === 'submitted' || r.status === 'processing' || r.status === 'acknowledged',
136138
).length;
137-
const completedCount = requests.filter((r) =>
139+
const completedCount = requests.filter((r: FoiaRequest) =>
138140
[
139141
'fulfilled',
140142
'partially_fulfilled',
@@ -144,7 +146,7 @@ function DashboardStats() {
144146
'withdrawn',
145147
].includes(r.status),
146148
).length;
147-
const uniqueAgencies = new Set(requests.map((r) => r.agencyId)).size;
149+
const uniqueAgencies = new Set(requests.map((r: FoiaRequest) => r.agencyId)).size;
148150

149151
return (
150152
<div className="mb-8 grid grid-cols-1 gap-4 md:grid-cols-4">

apps/astro/src/components/react/dashboard/dashboard-with-query.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* @author FOIA Stream Team
2727
*/
2828

29+
import { QueryProvider } from '../common/query-provider';
2930
import DashboardContent from './dashboard-content';
30-
import { QueryProvider } from './query-provider';
3131

3232
/**
3333
* Dashboard component wrapped with QueryProvider for TanStack Query support.

apps/astro/src/components/react/dashboard/dashboard.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
* @module components/react/Dashboard
2626
*/
2727

28-
import { api, type FoiaRequest } from '@/lib/api';
29-
import { formatDate, getStatusColor } from '@/lib/utils';
30-
import { initAuth, logout, useAuthStore } from '@/stores/auth';
31-
import { maybeRedact, redactName, usePrivacyStore } from '@/stores/privacy';
3228
import {
3329
Building2,
3430
Check,
@@ -48,7 +44,12 @@ import {
4844
X,
4945
} from 'lucide-react';
5046
import { useCallback, useEffect, useRef, useState } from 'react';
51-
import { PrivacyToggleCompact } from './privacy-toggle';
47+
48+
import { api, type FoiaRequest } from '@/lib/api';
49+
import { formatDate, getStatusColor } from '@/lib/utils';
50+
import { initAuth, logout, useAuthStore } from '@/stores/auth';
51+
import { maybeRedact, redactName, usePrivacyStore } from '@/stores/privacy';
52+
import { PrivacyToggleCompact } from '../common/privacy-toggle';
5253

5354
/**
5455
* Main dashboard component showing request statistics and list
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* Copyright (c) 2025 Foia Stream
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
123
export { default as Dashboard } from './dashboard';
224
export { default as DashboardContent } from './dashboard-content';
325
export { default as DashboardWithQuery } from './dashboard-with-query';

apps/astro/src/components/react/documents/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* Copyright (c) 2025 Foia Stream
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
123
export { default as DocumentViewer } from './document-viewer';
224
export { default as DocumentsPage } from './documents-page';
325
export { default as PDFRedactionViewer } from './pdf-redaction-viewer';

0 commit comments

Comments
 (0)