Skip to content

Commit f4bc9b0

Browse files
committed
add: implement basic functions of the watch app.
1 parent 00e22f5 commit f4bc9b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+794
-163
lines changed

Comentor.xcodeproj/project.pbxproj

+95-20
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<array/>
5+
</plist>

Comentor.xcodeproj/xcuserdata/steve.xcuserdatad/xcschemes/xcschememanagement.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<key>Comentor.xcscheme_^#shared#^_</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>1</integer>
15+
<integer>0</integer>
1616
</dict>
1717
<key>WatchComentor Watch App.xcscheme_^#shared#^_</key>
1818
<dict>
1919
<key>orderHint</key>
20-
<integer>2</integer>
20+
<integer>1</integer>
2121
</dict>
2222
</dict>
2323
</dict>

Comentor/Comentor.swift Comentor/ComentorApp.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// Comentor_NeueApp.swift
3-
// Comentor-Neue
2+
// ComentorApp.swift
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -9,7 +9,7 @@ import SwiftUI
99
import SwiftData
1010

1111
@main
12-
struct Comentor_NeueApp: App {
12+
struct ComentorApp: App {
1313

1414
var body: some Scene {
1515
WindowGroup {

Comentor/ContentView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ContentView.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Model/ComentorChat.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ComentorChat.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -14,6 +14,7 @@ import SwiftData
1414
final class ComentorChat {
1515
var title: String
1616
var timestamp: Date
17+
var isPinned: Bool = false
1718

1819
@Relationship(.cascade, inverse: \Dialogue.chat)
1920
var dialogues: [Dialogue] = []

Comentor/Model/Dialogue.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Dialogue.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -12,7 +12,6 @@ import SwiftData
1212

1313
@Model
1414
final class Dialogue {
15-
var dialogueIdentifier: UUID
1615
var ask: String
1716
var answer: String = ""
1817
var timestamp: Date
@@ -22,7 +21,6 @@ final class Dialogue {
2221

2322
init(_ ask: String) {
2423
self.ask = ask
25-
self.dialogueIdentifier = UUID()
2624
self.timestamp = Date()
2725
}
2826
}

Comentor/Model/Roadmap.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Roadmap.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -13,7 +13,6 @@ import SwiftUI
1313

1414
@Model
1515
final class Roadmap {
16-
var roadmapIdentifier: UUID
1716
var title: String
1817
var category: String
1918
var creationDate: Date
@@ -28,14 +27,12 @@ final class Roadmap {
2827
var steps: [Step] = []
2928

3029
init(_ title: String, category: StudyCategory) {
31-
self.roadmapIdentifier = UUID()
3230
self.title = title
3331
self.category = category.rawValue
3432
self.creationDate = Date()
3533
}
3634

3735
init(_ title: String, category: String) {
38-
self.roadmapIdentifier = UUID()
3936
self.title = title
4037
self.category = category
4138
self.creationDate = Date()

Comentor/Model/Step.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Step.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Model/Tag.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Tag.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Navigation/Navigation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Navigation.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Navigation/SidebarNavigation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SidebarNavigation.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Navigation/TabNavigation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// TabNavigation.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Navigation/WelcomeView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// WelcomeView.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Views/Chat/ChatDetail.swift

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ChatDetail.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -15,9 +15,6 @@ struct ChatDetail: View {
1515
@Query
1616
private var chats: [ComentorChat]
1717

18-
@Query
19-
private var dialogues: [Dialogue]
20-
2118
var chat: ComentorChat
2219

2320
@FocusState private var isTypingMessage: Bool
@@ -48,7 +45,6 @@ struct ChatDetail: View {
4845
.scrollTransition(axis: .vertical) { content, phase in
4946
content
5047
.opacity(phase.isIdentity ? 1.0 : 0.20)
51-
// .blur(radius: phase.isIdentity ? 0.0 : 3.0)
5248
.scaleEffect(phase.isIdentity ? 1.0 : 0.9)
5349
}
5450
}
@@ -181,10 +177,11 @@ struct ChatDetail: View {
181177

182178
Task {
183179
let (newAnswer, success) = await sendAndReceive(with: dialoguesToSend)
184-
let latestDialogue = dialogues.sorted(by: {$0.timestamp < $1.timestamp}).last!
185-
latestDialogue.answer = newAnswer
186-
latestDialogue.success = success
187-
try! modelContext.save()
180+
if let latestDialogue = chat.latestDialogue {
181+
latestDialogue.answer = newAnswer
182+
latestDialogue.success = success
183+
try! modelContext.save()
184+
}
188185
isRequestingAnswer = false
189186

190187
}

Comentor/Views/Chat/ChatDialogueCell.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ChatDialogueCell.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -50,7 +50,7 @@ struct ChatDialogueCell: View {
5050
.comentorAnswerMarkdownStyle()
5151
.animation(.spring, value: currentReceivedMessage)
5252
} else {
53-
if dialogue.answer != "" {
53+
if dialogue.answer != "" && dialogue.success {
5454
MarkdownText(dialogue.answer)
5555
.padding()
5656
.background(.secondary.opacity(0.2))

Comentor/Views/Chat/ChatListItem.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
//
22
// ChatListItem.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
77

88
import SwiftUI
9-
import SwiftData
109

1110
struct ChatListItem: View {
12-
@Environment(\.modelContext) private var modelContext
13-
1411
var chat: ComentorChat
1512

1613
var body: some View {

Comentor/Views/Chat/ChatView.swift

+46-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// ChatView.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//
@@ -24,7 +24,32 @@ struct ChatView: View {
2424

2525
var body: some View {
2626
List(selection: $selection) {
27-
ForEach(chats) { chat in
27+
if chats.contains(where: { $0.isPinned }) {
28+
Section("Pinned") {
29+
ForEach(chats.filter({ $0.isPinned })) { chat in
30+
ChatListItem(chat: chat)
31+
.swipeActions(edge: .trailing) {
32+
Button(role: .destructive) {
33+
deleteChat(chat)
34+
} label: {
35+
Label("Delete", systemImage: "trash")
36+
}
37+
}
38+
.swipeActions(edge: .leading) {
39+
Button {
40+
withAnimation {
41+
chat.isPinned.toggle()
42+
}
43+
} label: {
44+
Label(chat.isPinned ? "Unpin" : "Pin",
45+
systemImage: chat.isPinned ? "pin.slash.fill" : "pin.fill")
46+
.tint(.yellow)
47+
}
48+
}
49+
}
50+
}
51+
}
52+
ForEach(chats.filter({ !$0.isPinned })) { chat in
2853
ChatListItem(chat: chat)
2954
.swipeActions(edge: .trailing) {
3055
Button(role: .destructive) {
@@ -33,6 +58,16 @@ struct ChatView: View {
3358
Label("Delete", systemImage: "trash")
3459
}
3560
}
61+
.swipeActions(edge: .leading) {
62+
Button {
63+
withAnimation {
64+
chat.isPinned.toggle()
65+
}
66+
} label: {
67+
Label("Pin", systemImage: chat.isPinned ? "pin.slash.fill" : "pin.fill")
68+
.tint(.yellow)
69+
}
70+
}
3671
}
3772
}
3873
.listStyle(.plain)
@@ -73,19 +108,18 @@ struct ChatView: View {
73108
actions: {
74109
TextField("Enter title here…", text: $newChatTitle)
75110
Button("Add") {
76-
if !newChatTitle.isEmpty {
77-
withAnimation {
78-
if chats.contains(where: { $0.title == newChatTitle}) {
79-
invalidTitle = true
80-
} else {
81-
let newChat = ComentorChat(newChatTitle)
82-
modelContext.insert(newChat)
83-
newChatTitle = ""
84-
selection = chats.first(where: {$0.title == newChat.title})
85-
}
111+
withAnimation {
112+
if chats.contains(where: { $0.title == newChatTitle}) {
113+
invalidTitle = true
114+
} else {
115+
let newChat = ComentorChat(newChatTitle)
116+
modelContext.insert(newChat)
117+
newChatTitle = ""
118+
selection = chats.first(where: {$0.title == newChat.title})
86119
}
87120
}
88121
}
122+
.disabled(newChatTitle.isEmpty)
89123

90124
Button("Cancel", role: .cancel) {
91125
newChatTitle = ""

Comentor/Views/Chat/OpenAISettingsForm.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// OpenAISettingsForm.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/11.
66
//

Comentor/Views/Chat/RoadmapGenerationStatusToast.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// RoadmapGenerationStatusToast.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/11.
66
//

Comentor/Views/Search/SearchCategoryDetail.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SearchCategoryDetail.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/10.
66
//

Comentor/Views/Search/SearchCategoryGrid.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SearchCategoryGrid.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/10.
66
//

Comentor/Views/Search/SearchCategoryGridItem.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SearchCategoryGridItem.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/10.
66
//

Comentor/Views/Search/SearchView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SearchView.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/9.
66
//

Comentor/Views/StudyNow/RoadmapDetail.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// RoadmapDetail.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/10.
66
//

Comentor/Views/StudyNow/RoadmapDetailStepCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// RoadmapDetailStepCell.swift
3-
// Comentor-Neue
3+
// Comentor
44
//
55
// Created by 徐嗣苗 on 2023/6/11.
66
//

0 commit comments

Comments
 (0)