Skip to content

Commit b23ec3c

Browse files
authored
Merge pull request #440 from joreilly/add_nationality
add nationality
2 parents 50a872e + 40e2578 commit b23ec3c

File tree

9 files changed

+191
-14
lines changed

9 files changed

+191
-14
lines changed

PeopleInSpaceSwiftUI/PeopleInSpaceSwiftUI/ContentView.swift

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ struct PersonView: View {
134134
.font(.subheadline)
135135
.foregroundColor(.secondary)
136136

137+
if !person.nationality.isEmpty {
138+
Text(person.nationality)
139+
.font(.caption)
140+
.foregroundColor(.secondary)
141+
}
142+
137143
// Add a subtle bio preview if available
138144
if let bio = person.personBio, !bio.isEmpty {
139145
Text(bio.prefix(50) + (bio.count > 50 ? "..." : ""))
@@ -160,6 +166,8 @@ struct PersonDetailsScreen: View {
160166
let person: Assignment
161167

162168
var body: some View {
169+
// Compose share text once for use in toolbar
170+
let shareText = "Astronaut: \(person.name) — Craft: \(person.craft)\(person.nationality.isEmpty ? "" : " — Nationality: \(person.nationality)")"
163171
ScrollView {
164172
VStack(alignment: .center, spacing: 0) {
165173
// Header with astronaut name and craft
@@ -190,20 +198,53 @@ struct PersonDetailsScreen: View {
190198
.frame(height: 300)
191199
.clipShape(RoundedRectangle(cornerRadius: 16))
192200
} placeholder: {
193-
VStack {
194-
ProgressView()
195-
.progressViewStyle(CircularProgressViewStyle())
196-
Text("Loading image...")
197-
.font(.caption)
198-
.foregroundColor(.secondary)
199-
.padding(.top, 8)
201+
if (person.personImageUrl ?? "").isEmpty {
202+
VStack(spacing: 8) {
203+
Image(systemName: "person.crop.circle.fill")
204+
.font(.system(size: 64))
205+
.foregroundColor(.secondary)
206+
Text("No image available")
207+
.font(.caption)
208+
.foregroundColor(.secondary)
209+
}
210+
} else {
211+
VStack {
212+
ProgressView()
213+
.progressViewStyle(CircularProgressViewStyle())
214+
Text("Loading image...")
215+
.font(.caption)
216+
.foregroundColor(.secondary)
217+
.padding(.top, 8)
218+
}
200219
}
201220
}
202221
.frame(height: 300)
203222
}
204223
.padding(.horizontal)
205224
.padding(.bottom, 24)
206225

226+
// Nationality section (shown if available)
227+
if !person.nationality.isEmpty {
228+
VStack(alignment: .leading, spacing: 12) {
229+
Text("Nationality")
230+
.font(.title3)
231+
.fontWeight(.semibold)
232+
.foregroundColor(.primary)
233+
Text(person.nationality)
234+
.font(.body)
235+
.foregroundColor(.primary)
236+
.frame(maxWidth: .infinity, alignment: .leading)
237+
}
238+
.padding(24)
239+
.background(
240+
RoundedRectangle(cornerRadius: 16)
241+
.fill(Color(.systemBackground))
242+
.shadow(color: Color.black.opacity(0.1), radius: 10, x: 0, y: 5)
243+
)
244+
.padding(.horizontal)
245+
.padding(.bottom, 24)
246+
}
247+
207248
// Bio section with card styling
208249
if let bio = person.personBio, !bio.isEmpty {
209250
VStack(alignment: .leading, spacing: 16) {
@@ -286,9 +327,17 @@ struct PersonDetailsScreen: View {
286327
}
287328
.background(Color(.systemGroupedBackground).edgesIgnoringSafeArea(.all))
288329
.navigationBarTitleDisplayMode(.inline)
330+
.toolbar {
331+
ToolbarItem(placement: .navigationBarTrailing) {
332+
ShareLink(item: shareText) {
333+
Image(systemName: "square.and.arrow.up")
334+
}
335+
}
336+
}
289337
}
290338
}
291339

340+
292341
struct ContentView_Previews: PreviewProvider {
293342
static var previews: some View {
294343
ContentView()

app/src/main/java/com/surrus/peopleinspace/persondetails/PersonDetailsScreen.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,44 @@ fun PersonDetailsContent(person: Assignment, innerPadding: PaddingValues) {
111111
}
112112
}
113113

114+
Spacer(modifier = Modifier.size(16.dp))
115+
116+
if (person.nationality.isNotBlank()) {
117+
Card(
118+
modifier = Modifier
119+
.fillMaxWidth()
120+
.padding(horizontal = 16.dp),
121+
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
122+
) {
123+
Row(
124+
modifier = Modifier
125+
.fillMaxWidth()
126+
.padding(16.dp),
127+
verticalAlignment = Alignment.CenterVertically
128+
) {
129+
Icon(
130+
imageVector = Icons.Default.Person,
131+
contentDescription = null,
132+
tint = MaterialTheme.colorScheme.primary,
133+
modifier = Modifier.size(24.dp)
134+
)
135+
Spacer(modifier = Modifier.width(16.dp))
136+
Column {
137+
Text(
138+
text = "Nationality",
139+
style = MaterialTheme.typography.labelMedium,
140+
color = MaterialTheme.colorScheme.onSurfaceVariant
141+
)
142+
Text(
143+
text = person.nationality,
144+
style = MaterialTheme.typography.titleMedium,
145+
color = MaterialTheme.colorScheme.onSurface
146+
)
147+
}
148+
}
149+
}
150+
}
151+
114152
Spacer(modifier = Modifier.size(16.dp))
115153
PersonBio(person.personBio)
116154
}

app/src/main/java/com/surrus/peopleinspace/personlist/PersonListScreen.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ fun PersonView(index: Int, person: Assignment, personSelected: (person: Assignme
256256
style = MaterialTheme.typography.bodyMedium,
257257
color = MaterialTheme.colorScheme.onSurfaceVariant
258258
)
259+
if (person.nationality.isNotBlank()) {
260+
Spacer(modifier = Modifier.height(2.dp))
261+
Text(
262+
text = person.nationality,
263+
style = MaterialTheme.typography.bodySmall,
264+
color = MaterialTheme.colorScheme.onSurfaceVariant
265+
)
266+
}
259267
}
260268
}
261269
}

backend/src/jvmMain/kotlin/PeopleData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ val currentPeopleInSpace = listOf(
4343
name = "Sergey Ryzhikov",
4444
personImageUrl = "https://images.squarespace-cdn.com/content/v1/580e44a7c534a53b3fc3bedf/ffb6609c-6adb-40c6-8c5f-670472072acb/WIIS_Ryzhikov.jpg?format=1000w",
4545
personBio = "Sergey Nikolayevich Ryzhiko born on August 19, 1974, lieutenant colonel of Russian Air Force, is a Russian cosmonaut, selected in 2006. Ryzhikov launched on his first spaceflight onboard the Soyuz MS-02 spacecraft. He spent approximately six months onboard the International Space Station taking part in Expedition 49/50, returning to Earth on April 10, 2017.",
46-
nationality = "",
46+
nationality = "Russian",
4747
),
4848
Assignment(
4949
craft = "ISS",

common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ class PeopleInSpaceRepository(
4040

4141
override fun fetchPeopleAsFlow(): Flow<List<Assignment>> {
4242
return peopleInSpaceQueries.selectAll(
43-
mapper = { name, craft, personImageUrl, personBio ->
43+
mapper = { name, craft, personImageUrl, personBio, nationality ->
4444
Assignment(
4545
name = name,
4646
craft = craft,
4747
personImageUrl = personImageUrl,
48-
personBio = personBio
48+
personBio = personBio,
49+
nationality = nationality
4950
)
5051
}
5152
).asFlow().mapToList(Dispatchers.Default)
@@ -65,7 +66,8 @@ class PeopleInSpaceRepository(
6566
it.name,
6667
it.craft,
6768
it.personImageUrl,
68-
it.personBio
69+
it.personBio,
70+
it.nationality
6971
)
7072
}
7173
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE People ADD COLUMN nationality TEXT NOT NULL DEFAULT '';

common/src/commonMain/sqldelight/com/surrus/peopleinspace/db/PeopleInSpace.sq

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ CREATE TABLE IF NOT EXISTS People(
22
name TEXT NOT NULL PRIMARY KEY,
33
craft TEXT NOT NULL,
44
personImageUrl TEXT,
5-
personBio TEXT
5+
personBio TEXT,
6+
nationality TEXT NOT NULL DEFAULT ''
67
);
78

89
insertItem:
9-
INSERT OR REPLACE INTO People(name, craft, personImageUrl, personBio) VALUES(?,?,?,?);
10+
INSERT OR REPLACE INTO People(name, craft, personImageUrl, personBio, nationality) VALUES(?,?,?,?,?);
1011

1112
selectAll:
1213
SELECT * FROM People;

compose-desktop/src/main/kotlin/main.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ fun PersonView(
236236
color = if (isSelected) SpaceDarkBlue.copy(alpha = 0.7f) else SpaceGray
237237
)
238238
)
239+
240+
val nationality = person.nationality
241+
if (nationality.isNotBlank()) {
242+
Spacer(modifier = Modifier.height(2.dp))
243+
Text(
244+
text = "Nationality: $nationality",
245+
style = MaterialTheme.typography.body2.copy(
246+
color = if (isSelected) SpaceDarkBlue.copy(alpha = 0.7f) else SpaceGray
247+
)
248+
)
249+
}
239250
}
240251
}
241252
}
@@ -282,6 +293,25 @@ fun PersonDetailsView(person: Assignment) {
282293
)
283294
)
284295
}
296+
297+
val nationality = person.nationality
298+
if (nationality.isNotBlank()) {
299+
Surface(
300+
color = SpaceLightBlue,
301+
shape = RoundedCornerShape(16.dp),
302+
modifier = Modifier.padding(vertical = 4.dp)
303+
) {
304+
Text(
305+
"Nationality: $nationality",
306+
modifier = Modifier.padding(horizontal = 16.dp, vertical = 6.dp),
307+
style = TextStyle(
308+
color = SpaceDarkBlue,
309+
fontWeight = FontWeight.Medium,
310+
fontSize = 14.sp
311+
)
312+
)
313+
}
314+
}
285315
}
286316

287317
Spacer(modifier = Modifier.height(24.dp))

compose-web/src/wasmJsMain/kotlin/Main.kt

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ fun PersonView(
255255
)
256256
)
257257
}
258+
259+
if (person.nationality.isNotBlank()) {
260+
Spacer(modifier = Modifier.height(2.dp))
261+
Text(
262+
text = person.nationality,
263+
style = TextStyle(
264+
color = Color.Gray,
265+
fontSize = 12.sp
266+
)
267+
)
268+
}
258269
}
259270
}
260271
}
@@ -331,7 +342,44 @@ fun PersonDetailsView(person: Assignment) {
331342
}
332343

333344
Spacer(modifier = Modifier.height(32.dp))
334-
345+
346+
// Nationality section (if available)
347+
if (person.nationality.isNotBlank()) {
348+
Card(
349+
modifier = Modifier.fillMaxWidth(),
350+
colors = CardDefaults.cardColors(
351+
containerColor = Color(0xFFF9F9F9)
352+
),
353+
shape = RoundedCornerShape(8.dp)
354+
) {
355+
Column(modifier = Modifier.padding(16.dp)) {
356+
Text(
357+
"Nationality",
358+
style = TextStyle(
359+
fontSize = 20.sp,
360+
fontWeight = FontWeight.Bold,
361+
color = primaryColor
362+
),
363+
modifier = Modifier.padding(bottom = 8.dp)
364+
)
365+
366+
Divider(color = Color.LightGray)
367+
368+
Spacer(modifier = Modifier.height(12.dp))
369+
370+
Text(
371+
person.nationality,
372+
style = TextStyle(
373+
fontSize = 16.sp,
374+
color = Color.DarkGray
375+
)
376+
)
377+
}
378+
}
379+
380+
Spacer(modifier = Modifier.height(24.dp))
381+
}
382+
335383
// Bio section
336384
Card(
337385
modifier = Modifier.fillMaxWidth(),

0 commit comments

Comments
 (0)