-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication
: Mention content (#107)
* Margins for content * Parse mention * Add navigation titles * Create SendMessageMentionContentView * Display all results if query is empty * Create LectureService * View lecture, lecture unit, and slide * Select lecture unit * Select lecture * Select slide
- Loading branch information
1 parent
535407c
commit fdc6945
Showing
15 changed files
with
335 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
ArtemisKit/Sources/Messages/Services/LectureService/LectureService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// LectureService.swift | ||
// | ||
// | ||
// Created by Nityananda Zbil on 30.05.24. | ||
// | ||
|
||
import Common | ||
import SharedModels | ||
|
||
protocol LectureService { | ||
func getLecturesWithSlides(courseId: Int) async -> DataState<[Lecture]> | ||
} | ||
|
||
enum LectureServiceFactory { | ||
static let shared: LectureService = LectureServiceImpl() | ||
} |
40 changes: 40 additions & 0 deletions
40
ArtemisKit/Sources/Messages/Services/LectureService/LectureServiceImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// LectureServiceImpl.swift | ||
// | ||
// | ||
// Created by Nityananda Zbil on 30.05.24. | ||
// | ||
|
||
import APIClient | ||
import Common | ||
import SharedModels | ||
|
||
class LectureServiceImpl: LectureService { | ||
|
||
let client = APIClient() | ||
|
||
struct GetLecturesWithSlidesRequest: APIRequest { | ||
typealias Response = [Lecture] | ||
|
||
let courseId: Int | ||
|
||
var method: HTTPMethod { | ||
.get | ||
} | ||
|
||
var resourceName: String { | ||
"api/courses/\(courseId)/lectures-with-slides" | ||
} | ||
} | ||
|
||
func getLecturesWithSlides(courseId: Int) async -> DataState<[Lecture]> { | ||
let result = await client.sendRequest(GetLecturesWithSlidesRequest(courseId: courseId)) | ||
|
||
switch result { | ||
case let .success((response, _)): | ||
return .done(response: response) | ||
case let .failure(error): | ||
return .failure(error: UserFacingError(error: error)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...Sources/Messages/ViewModels/SendMessageViewModels/SendMessageLecturePickerViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// SendMessageLecturePickerViewModel.swift | ||
// | ||
// | ||
// Created by Nityananda Zbil on 30.05.24. | ||
// | ||
|
||
import SharedModels | ||
import SwiftUI | ||
|
||
@Observable | ||
@MainActor | ||
final class SendMessageLecturePickerViewModel { | ||
|
||
let course: Course | ||
var lectureUnits: [LectureUnit] | ||
|
||
private let delegate: SendMessageMentionContentDelegate | ||
private let lectureService: LectureService | ||
|
||
init( | ||
course: Course, | ||
lectureUnits: [LectureUnit] = [], | ||
delegate: SendMessageMentionContentDelegate, | ||
lectureService: LectureService = LectureServiceFactory.shared | ||
) { | ||
self.course = course | ||
self.lectureUnits = lectureUnits | ||
self.delegate = delegate | ||
self.lectureService = lectureService | ||
} | ||
|
||
func task() async { | ||
let lectures = await lectureService.getLecturesWithSlides(courseId: course.id) | ||
|
||
if case let .done(lectures) = lectures, | ||
let lecture = lectures.first, | ||
let lectureUnits = lecture.lectureUnits { | ||
self.lectureUnits = lectureUnits | ||
} | ||
} | ||
|
||
func select(lecture: Lecture) { | ||
if let title = lecture.title { | ||
delegate.pickerDidSelect("[lecture]\(title)(/courses/\(course.id)/lectures/\(lecture.id))[/lecture]") | ||
} | ||
} | ||
|
||
func select(lectureUnit: LectureUnit) { | ||
if let name = lectureUnit.baseUnit.name, | ||
case let .attachment(attachment) = lectureUnit, | ||
case let .file(file) = attachment.attachment, | ||
let link = file.link, | ||
let url = URL(string: link), | ||
url.pathComponents.count >= 7 { | ||
let path = url.pathComponents[4...] | ||
let id = path.joined(separator: "/") | ||
|
||
delegate.pickerDidSelect("[lecture-unit]\(name)(\(id))[/lecture-unit]") | ||
} | ||
} | ||
|
||
func select(lectureUnit: LectureUnit, slide: Slide) { | ||
if let name = lectureUnit.baseUnit.name, | ||
let slideNumber = slide.slideNumber, | ||
let slideImagePath = slide.slideImagePath, | ||
let url = URL(string: slideImagePath), | ||
url.pathComponents.count >= 9 { | ||
let path = url.pathComponents[4...7] | ||
let id = path.joined(separator: "/") | ||
|
||
delegate.pickerDidSelect("[slide]\(name) Slide \(slideNumber)(\(id))[/slide]") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...Sources/Messages/ViewModels/SendMessageViewModels/SendMessageMentionContentDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// SendMessageMentionContentDelegate.swift | ||
// | ||
// | ||
// Created by Nityananda Zbil on 30.05.24. | ||
// | ||
|
||
struct SendMessageMentionContentDelegate { | ||
var pickerDidSelect: (_ mention: String) -> Void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.