-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSessions.tsx
115 lines (103 loc) · 3.65 KB
/
Sessions.tsx
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
import { useState, useEffect } from "react";
import {
View,
Text,
StyleSheet,
FlatList,
TouchableOpacity,
} from "react-native";
import { generateClient } from "aws-amplify/data";
import type { Schema } from "./amplify/data/resource";
import { SessionItem } from "./components/SessionItemComponent";
const client = generateClient<Schema>();
const SessionList = () => {
const [sessions, setSessions] = useState<Schema["Session"]["type"][]>([]);
const createSession = async () => {
try {
await client.models.Session.create(
new Date().getMilliseconds() % 2 == 0 ? sampleSession : sampleSession2
);
} catch (error: unknown) {
alert("fail to create");
}
};
useEffect(() => {
const sub = client.models.Session.observeQuery().subscribe({
next: (thing) => {
var myItems = thing.items;
setSessions([...myItems]);
},
error: (e) => {
console.log(e);
},
});
return () => sub.unsubscribe();
}, []);
const renderItem = ({ item }: { item: Schema["Session"]["type"] }) => {
return <SessionItem {...item} />;
};
return (
<View style={styles.container}>
<FlatList
data={sessions}
renderItem={renderItem}
keyExtractor={(item) => item.id}
ItemSeparatorComponent={() => <View style={styles.listItemSeparator} />}
ListEmptyComponent={() => (
<Text style={styles.emptyText}>No sessions available.</Text>
)}
style={styles.listContainer}
/>
<TouchableOpacity style={styles.createButton} onPress={createSession}>
<Text style={styles.createButtonText}>+ Create New Session</Text>
</TouchableOpacity>
</View>
);
};
const sampleSession = {
ratings: [],
image:
"https://media.licdn.com/dms/image/v2/C4E03AQHHcqvlwtquAg/profile-displayphoto-shrink_800_800/profile-displayphoto-shrink_800_800/0/1532482695425?e=1732147200&v=beta&t=9hr3TFUPuiSyKqEIcPsf4NgZjg57PVOQwDr1iceh4LA",
content: `In this session we will cover how you can create mobile apps with Amplify Gen 2`,
title: "Accelerate Web And Mobile App Dev with Amplify Gen 2",
};
const sampleSession2 = {
ratings: [],
image:
"https://media.licdn.com/dms/image/v2/C5603AQFnwRTNy-wrPA/profile-displayphoto-shrink_400_400/profile-displayphoto-shrink_400_400/0/1649728308197?e=1732147200&v=beta&t=Fd1Fbohi_WVzyu_fa-MwclEnvjbqCW4E5EHuZP13fKA",
content: `Welcome to the AWS NAMER Tech kickoff session! Join our AGS leaders as they dive into AWS's global and regional priorities, understanding how they align with our business objectives and your pivotal role in our strategic plan. Our focus is to ignite your enthusiasm and empower you to innovate, ensuring we deliver exceptional solutions for our customers. This session is designed to set the foundation for a transformative week of learning, equipping you to address challenges, seize opportunities, and drive outstanding results. Let’s embark on this exciting path together, making a significant impact both locally and globally.`,
title: "NAMER Wide Keynote with the AGS Leadership Team",
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#f7f7f7",
},
listContainer: {
flex: 1,
paddingHorizontal: 16,
},
listItemSeparator: {
height: 16,
},
emptyText: {
textAlign: "center",
marginTop: 20,
fontSize: 18,
color: "#999",
},
createButton: {
backgroundColor: "#28a745",
padding: 16,
alignItems: "center",
marginHorizontal: 16,
marginVertical: 16,
borderRadius: 8,
},
createButtonText: {
color: "#fff",
fontSize: 16,
fontWeight: "bold",
},
});
export default SessionList;