-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathCompactGradeList.tsx
More file actions
145 lines (139 loc) · 4.81 KB
/
Copy pathCompactGradeList.tsx
File metadata and controls
145 lines (139 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { PapillonAppearIn, PapillonAppearOut } from "@/ui/utils/Transition";
import Stack from "@/ui/components/Stack";
import Icon from "@/ui/components/Icon";
import { Papicons } from "@getpapillon/papicons";
import LegacyTypography from "@/ui/components/Typography";
import { t } from "i18next";
import { LegendList } from "@legendapp/list";
import { Dimensions, View } from "react-native";
import { ErrorBoundary } from "@/ui/components/ErrorBoundary";
import { CompactGrade } from "@/ui/components/CompactGrade";
import { getSubjectEmoji } from "@/utils/subjects/emoji";
import { getSubjectName } from "@/utils/subjects/name";
import { getSubjectColor } from "@/utils/subjects/colors";
import { Dynamic } from "@/ui/components/Dynamic";
import React, { JSX, useMemo } from "react";
import { Grade, Subject } from "@/services/shared/grade";
import MaskedView from "@react-native-masked-view/masked-view";
import { LinearGradient } from "expo-linear-gradient";
import { Link } from "expo-router";
export interface CompactGradeListProps {
grades: Grade[];
getSubjectById: (id: string) => Subject | undefined;
large?: boolean;
}
export function CompactGradeList({
grades,
getSubjectById,
large = false,
}: CompactGradeListProps): JSX.Element {
const list = useMemo(() => (
<LegendList
horizontal
data={grades.slice(0, 10)}
style={{
overflow: "visible",
height: 160,
marginVertical: -10,
}}
contentContainerStyle={{
gap: 12,
paddingStart: 16 + (large ? 20 : 0),
paddingEnd: 4 + (large ? 20 : 0),
overflow: "visible",
paddingVertical: 10
}}
estimatedItemSize={210 + 12}
showsHorizontalScrollIndicator={false}
recycleItems={true}
keyExtractor={item => item.id}
renderItem={({ item: grade }) => (
<ErrorBoundary fallback={<View style={{ width: 140, height: 140 }} />}>
<Link
href={{ pathname: "/(tabs)/grades/[id]", params: { id: grade.id } }}
asChild
>
<Link.AppleZoom>
<CompactGrade
key={grade.id + "_compactGrade_header"}
emoji={getSubjectEmoji(getSubjectById(grade.subjectId)?.name || "")}
title={getSubjectName(getSubjectById(grade.subjectId)?.name || "")}
description={grade.description}
skillLevel={grade.skills?.map(v => v.score) ?? []}
score={grade.studentScore?.value || 0}
outOf={grade.outOf?.value || 20}
disabled={grade.studentScore?.disabled}
status={grade.studentScore?.status}
color={getSubjectColor(getSubjectById(grade.subjectId)?.name || "")}
date={grade.givenAt}
hasMaxScore={
(grade?.studentScore?.value ?? 0) ===
(grade?.maxScore?.value ?? 1) && !grade?.studentScore?.disabled
}
/>
</Link.AppleZoom>
</Link>
</ErrorBoundary>
)}
/>
), [grades]);
return (
<Dynamic animated entering={PapillonAppearIn} exiting={PapillonAppearOut}>
<Stack gap={8} width={"100%"} style={{ marginBottom: large ? 0 : 16 }}>
{!large && (
<Stack
direction="horizontal"
gap={8}
vAlign="start"
hAlign="center"
style={{ opacity: 0.4 }}
padding={[0, 0]}
>
<Icon size={20}>
<Papicons name="star" />
</Icon>
<LegacyTypography variant="h6" color="text">
{t("Grades_Tab_Latest")}
</LegacyTypography>
</Stack>
)}
{large ? (
<MaskedView
style={{ width: "100%" }}
maskElement={
<View
style={{ width: "100%", height: 140, flexDirection: "row" }}
>
{large && (
<LinearGradient
colors={["#0000", "#000"]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={{ width: 40, height: 140 }}
/>
)}
<View style={{ flex: 1, backgroundColor: "#000" }} />
{large && (
<LinearGradient
colors={["#000", "#0000"]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={{ width: 40, height: 140 }}
/>
)}
</View>
}
>
{list}
</MaskedView>
) : (
<View style={{ width: Dimensions.get("window").width, marginHorizontal: -16 }}>{list}</View>
)}
</Stack>
</Dynamic>
);
}
/*
() => {
// @ts-expect-error navigation types
*/