|
@@ -1,9 +1,34 @@
|
1
|
1
|
import { IonContent, IonItem, IonLabel, IonListHeader } from "@ionic/react";
|
2
|
2
|
import "../components/ListComponent.css";
|
|
3
|
+import SkeletonText from "./SkeletonText";
|
3
|
4
|
|
4
|
|
-const ListComponent: React.FC<{ title?: string; laws: string[] }> = (props) => {
|
|
5
|
+/**
|
|
6
|
+ * This component creates a shimmering "skeleton" version of the list component.
|
|
7
|
+ * It shows only when content isn't available yet (loading).
|
|
8
|
+ */
|
|
9
|
+function ListComponentSkeleton({ items = 5 }: { items?: number }) {
|
|
10
|
+ return (
|
|
11
|
+ <>
|
|
12
|
+ {Array(items)
|
|
13
|
+ .fill(0)
|
|
14
|
+ .map((_, i) => (
|
|
15
|
+ <IonItem key={i}>
|
|
16
|
+ <SkeletonText />
|
|
17
|
+ </IonItem>
|
|
18
|
+ ))}
|
|
19
|
+ </>
|
|
20
|
+ );
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+const ListComponent: React.FC<{
|
|
24
|
+ title?: string;
|
|
25
|
+ laws: string[];
|
|
26
|
+ loading?: boolean;
|
|
27
|
+}> = (props) => {
|
5
|
28
|
const title = props.title;
|
6
|
29
|
const laws = props.laws;
|
|
30
|
+ const loading = props.loading ?? false;
|
|
31
|
+
|
7
|
32
|
return (
|
8
|
33
|
<IonContent>
|
9
|
34
|
{title ? (
|
|
@@ -12,16 +37,19 @@ const ListComponent: React.FC<{ title?: string; laws: string[] }> = (props) => {
|
12
|
37
|
</IonListHeader>
|
13
|
38
|
) : null}
|
14
|
39
|
|
15
|
|
- {laws.map((lawName: string) => {
|
16
|
|
- return (
|
17
|
|
- <IonItem
|
18
|
|
- key={lawName}
|
19
|
|
- routerLink={`/article/${encodeURIComponent(lawName)}`}
|
20
|
|
- >
|
21
|
|
- <p className="ListItemText">{lawName}</p>
|
22
|
|
- </IonItem>
|
23
|
|
- );
|
24
|
|
- })}
|
|
40
|
+ {loading && <ListComponentSkeleton />}
|
|
41
|
+
|
|
42
|
+ {!loading &&
|
|
43
|
+ laws.map((lawName: string) => {
|
|
44
|
+ return (
|
|
45
|
+ <IonItem
|
|
46
|
+ key={lawName}
|
|
47
|
+ routerLink={`/article/${encodeURIComponent(lawName)}`}
|
|
48
|
+ >
|
|
49
|
+ <p className="ListItemText">{lawName}</p>
|
|
50
|
+ </IonItem>
|
|
51
|
+ );
|
|
52
|
+ })}
|
25
|
53
|
</IonContent>
|
26
|
54
|
);
|
27
|
55
|
};
|