Skip to content

Commit

Permalink
Apply SwiftFormat changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shp7724 authored and github-actions[bot] committed Mar 1, 2025
1 parent d12f170 commit 8004985
Show file tree
Hide file tree
Showing 22 changed files with 292 additions and 95 deletions.
2 changes: 1 addition & 1 deletion SNUTT-2022/SNUTT/AppState/States/UserState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Jinsup Keum on 2022/06/25.
//

import SwiftUI
import FirebaseAnalytics
import SwiftUI

class UserState {
@Published var accessToken: String?
Expand Down
6 changes: 5 additions & 1 deletion SNUTT-2022/SNUTT/Services/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ struct AuthService: AuthServiceProtocol, UserAuthHandler {

func registerWithLocalId(localId: String, localPassword: String, email: String) async throws {
FirebaseAnalyticsLogger().logEvent(.signUp)
let dto = try await authRepository.registerWithLocalId(localId: localId, localPassword: localPassword, email: email)
let dto = try await authRepository.registerWithLocalId(
localId: localId,
localPassword: localPassword,
email: email
)
saveAccessTokenFromLoginResponse(dto: dto)
try await registerFCMToken()
}
Expand Down
36 changes: 30 additions & 6 deletions SNUTT-2022/SNUTT/Services/LectureService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ struct LectureService: LectureServiceProtocol {

func addLecture(lecture: Lecture, isForced: Bool = false) async throws {
guard let currentTimetable = appState.timetable.current else { return }
let dto = try await lectureRepository.addLecture(timetableId: currentTimetable.id, lectureId: lecture.id, isForced: isForced)
let dto = try await lectureRepository.addLecture(
timetableId: currentTimetable.id,
lectureId: lecture.id,
isForced: isForced
)
let timetable = Timetable(from: dto)
appState.timetable.current = timetable
appState.search.selectedLecture = nil
Expand All @@ -64,7 +68,11 @@ struct LectureService: LectureServiceProtocol {
guard let currentTimetable = appState.timetable.current else { return }
var lectureDto = LectureDto(from: lecture)
lectureDto.class_time_mask = nil
let dto = try await lectureRepository.addCustomLecture(timetableId: currentTimetable.id, lecture: lectureDto, isForced: isForced)
let dto = try await lectureRepository.addCustomLecture(
timetableId: currentTimetable.id,
lecture: lectureDto,
isForced: isForced
)
let timetable = Timetable(from: dto)
appState.timetable.current = timetable
userDefaultsRepository.set(TimetableDto.self, key: .currentTimetable, value: dto)
Expand All @@ -74,7 +82,12 @@ struct LectureService: LectureServiceProtocol {
try checkIfTimeplaceOverlapped(newLecture)

guard let currentTimetable = appState.timetable.current else { return }
let dto = try await lectureRepository.updateLecture(timetableId: currentTimetable.id, oldLecture: .init(from: oldLecture), newLecture: .init(from: newLecture), isForced: isForced)
let dto = try await lectureRepository.updateLecture(
timetableId: currentTimetable.id,
oldLecture: .init(from: oldLecture),
newLecture: .init(from: newLecture),
isForced: isForced
)
let timetable = Timetable(from: dto)
appState.timetable.current = timetable
userDefaultsRepository.set(TimetableDto.self, key: .currentTimetable, value: dto)
Expand All @@ -84,7 +97,10 @@ struct LectureService: LectureServiceProtocol {
guard let currentTimetable = appState.timetable.current,
let timetableLecture = currentTimetable.lectures.first(where: { $0.isEquivalent(with: lecture) })
else { return }
let dto = try await lectureRepository.deleteLecture(timetableId: currentTimetable.id, lectureId: timetableLecture.id)
let dto = try await lectureRepository.deleteLecture(
timetableId: currentTimetable.id,
lectureId: timetableLecture.id
)
let timetable = Timetable(from: dto)
appState.timetable.current = timetable
userDefaultsRepository.set(TimetableDto.self, key: .currentTimetable, value: dto)
Expand All @@ -111,7 +127,11 @@ struct LectureService: LectureServiceProtocol {
}

func fetchIsFirstBookmark() {
appState.timetable.isFirstBookmark = userDefaultsRepository.get(Bool.self, key: .isFirstBookmark, defaultValue: true)
appState.timetable.isFirstBookmark = userDefaultsRepository.get(
Bool.self,
key: .isFirstBookmark,
defaultValue: true
)
}

func bookmarkLecture(lecture: Lecture) async throws {
Expand Down Expand Up @@ -143,7 +163,11 @@ struct LectureService: LectureServiceProtocol {
if let isMapViewExpanded = appState.system.isMapViewExpanded {
return isMapViewExpanded
} else {
let isMapViewExpanded = userDefaultsRepository.get(Bool.self, key: .expandLectureMapView, defaultValue: false)
let isMapViewExpanded = userDefaultsRepository.get(
Bool.self,
key: .expandLectureMapView,
defaultValue: false
)
appState.system.isMapViewExpanded = isMapViewExpanded
return isMapViewExpanded
}
Expand Down
24 changes: 18 additions & 6 deletions SNUTT-2022/SNUTT/Services/SearchService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ struct SearchService: SearchServiceProtocol {
let dto = try await searchRepository.fetchTags(quarter: quarter)
let model = SearchTagList(from: dto)
appState.search.searchTagList = model
guard let recentTagNames = userDefaultsRepository.get([String].self, key: .recentDepartmentTags) else { return }
appState.search.pinnedTagList = model?.tagList.filter { $0.type == .department && recentTagNames.contains($0.text) } ?? []
guard let recentTagNames = userDefaultsRepository.get([String].self, key: .recentDepartmentTags)
else { return }
appState.search.pinnedTagList = model?.tagList
.filter { $0.type == .department && recentTagNames.contains($0.text) } ?? []
}

private func _saveDepartmentTagsToUserDefaults(from tagList: [SearchTag]) {
Expand All @@ -84,8 +86,12 @@ struct SearchService: SearchServiceProtocol {
guard let currentTimetable = timetableState.current else { return }
let tagList = searchState.selectedTagList
_saveDepartmentTagsToUserDefaults(from: tagList)
let timeList = tagList.contains(where: { $0.type == .time && TimeType(rawValue: $0.text) == .range }) ? searchState.selectedTimeRange : nil
let excludedTimeList = tagList.contains(where: { $0.type == .time && TimeType(rawValue: $0.text) == .empty }) ? currentTimetable.timeMask : nil
let timeList = tagList
.contains(where: { $0.type == .time && TimeType(rawValue: $0.text) == .range }) ? searchState
.selectedTimeRange : nil
let excludedTimeList = tagList
.contains(where: { $0.type == .time && TimeType(rawValue: $0.text) == .empty }) ? currentTimetable
.timeMask : nil
let offset = searchState.perPage * searchState.pageNum
let dtos = try await searchRepository.fetchSearchResult(query: searchState.searchText,
quarter: currentTimetable.quarter,
Expand All @@ -95,7 +101,11 @@ struct SearchService: SearchServiceProtocol {
offset: offset,
limit: searchState.perPage)
let models: [Lecture] = dtos.map { Lecture(from: $0) }
FirebaseAnalyticsLogger().logEvent(.searchLecture(.init(query: searchState.searchText, quarter: currentTimetable.quarter.longString(), page: searchState.pageNum)))
FirebaseAnalyticsLogger().logEvent(.searchLecture(.init(
query: searchState.searchText,
quarter: currentTimetable.quarter.longString(),
page: searchState.pageNum
)))
searchState.searchResult = offset == 0 ? models : (searchState.searchResult ?? []) + models
}

Expand Down Expand Up @@ -133,7 +143,9 @@ struct SearchService: SearchServiceProtocol {
}

func selectTimeRangeTag() {
guard let tag = searchState.searchTagList?.tagList.first(where: { $0.type == .time && $0.text == TimeType.range.rawValue }) else {
guard let tag = searchState.searchTagList?.tagList
.first(where: { $0.type == .time && $0.text == TimeType.range.rawValue })
else {
return
}
if searchState.selectedTagList.firstIndex(where: { $0.id == tag.id }) == nil {
Expand Down
20 changes: 16 additions & 4 deletions SNUTT-2022/SNUTT/ViewModels/LectureDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ extension LectureDetailScene {
}

do {
try await lectureService.updateLecture(oldLecture: oldLecture, newLecture: newLecture, isForced: isForced)
try await lectureService.updateLecture(
oldLecture: oldLecture,
newLecture: newLecture,
isForced: isForced
)
return true
} catch let error as STError where error.code == .LECTURE_TIME_OVERLAP {
isLectureOverlapped = true
Expand Down Expand Up @@ -172,7 +176,10 @@ extension LectureDetailScene {
}

func bookmarkLecture(lecture: Lecture) async {
FirebaseAnalyticsLogger().logEvent(.addToBookmark(.init(lectureID: lecture.referenceId, referrer: .lectureDetail)))
FirebaseAnalyticsLogger().logEvent(.addToBookmark(.init(
lectureID: lecture.referenceId,
referrer: .lectureDetail
)))
do {
try await services.lectureService.bookmarkLecture(lecture: lecture)
} catch {
Expand All @@ -195,7 +202,10 @@ extension LectureDetailScene {
}

func addVacancyLecture(lecture: Lecture) async {
FirebaseAnalyticsLogger().logEvent(.addToVacancy(.init(lectureID: lecture.referenceId, referrer: .lectureDetail)))
FirebaseAnalyticsLogger().logEvent(.addToVacancy(.init(
lectureID: lecture.referenceId,
referrer: .lectureDetail
)))
do {
try await services.vacancyService.addLecture(lecture: lecture)
} catch let error as STError where error.code == .INVALID_SEMESTER_FOR_VACANCY_NOTIFICATION {
Expand All @@ -221,7 +231,9 @@ extension LectureDetailScene {

var theme: Theme {
if let currentTimetable = appState.timetable.current {
return appState.theme.themeList.first(where: { $0.id == currentTimetable.themeId || $0.theme == currentTimetable.theme }) ?? Theme(rawValue: 0)
return appState.theme.themeList
.first(where: { $0.id == currentTimetable.themeId || $0.theme == currentTimetable.theme }) ??
Theme(rawValue: 0)
} else { return Theme(rawValue: 0) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ struct ExpandableLectureCell: View {
if lecture.isCustom {
LectureDetailRow(imageName: "tag.white", text: "")
} else {
LectureDetailRow(imageName: "tag.white", text: "\(lecture.department), \(lecture.academicYear)")
LectureDetailRow(
imageName: "tag.white",
text: "\(lecture.department), \(lecture.academicYear)"
)
}
HStack(spacing: 2) {
Image("search.rating.star")
Expand Down Expand Up @@ -92,7 +95,8 @@ struct ExpandableLectureCell: View {
}

LectureCellActionButton(
icon: .asset(name: isVacancyNotificationEnabled ? "search.vacancy.fill" : "search.vacancy"),
icon: .asset(name: isVacancyNotificationEnabled ? "search.vacancy.fill" :
"search.vacancy"),
text: "빈자리알림"
) {
if isVacancyNotificationEnabled {
Expand All @@ -113,14 +117,18 @@ struct ExpandableLectureCell: View {
}
}
}
/// This `sheet` modifier should be called on `HStack` to prevent animation glitch when `dismiss`ed.
/// This `sheet` modifier should be called on `HStack` to prevent animation glitch when
/// `dismiss`ed.
.sheet(isPresented: $isReviewWebViewPresented) {
ReviewScene(
viewModel: .init(container: viewModel.container),
isMainWebView: false,
detailId: reviewDetailId
)
.analyticsScreen(.reviewDetail(.init(lectureID: lecture.referenceId, referrer: viewModel.detailReferrer)))
.analyticsScreen(.reviewDetail(.init(
lectureID: lecture.referenceId,
referrer: viewModel.detailReferrer
)))
.id(reviewDetailId)
}
.sheet(isPresented: $isDetailPagePresented) {
Expand All @@ -130,7 +138,10 @@ struct ExpandableLectureCell: View {
lecture: lecture,
displayMode: .preview(shouldHideDismissButton: false)
)
.analyticsScreen(.lectureDetail(.init(lectureID: lecture.referenceId, referrer: viewModel.detailReferrer)))
.analyticsScreen(.lectureDetail(.init(
lectureID: lecture.referenceId,
referrer: viewModel.detailReferrer
)))
}
}
}
Expand Down Expand Up @@ -210,7 +221,11 @@ extension ExpandableLectureCell {

extension ExpandableLectureCell.ViewModel {
func addLecture(_ lecture: Lecture) async {
FirebaseAnalyticsLogger().logEvent(.addToTimetable(.init(lectureID: lecture.referenceId, timetableID: appState.timetable.current?.id, referrer: lectureActionReferrer)))
FirebaseAnalyticsLogger().logEvent(.addToTimetable(.init(
lectureID: lecture.referenceId,
timetableID: appState.timetable.current?.id,
referrer: lectureActionReferrer
)))
do {
try await services.lectureService.addLecture(lecture: lecture)
} catch {
Expand Down Expand Up @@ -246,7 +261,10 @@ extension ExpandableLectureCell.ViewModel {
}

func addVacancyLecture(_ lecture: Lecture) async {
FirebaseAnalyticsLogger().logEvent(.addToVacancy(.init(lectureID: lecture.referenceId, referrer: lectureActionReferrer)))
FirebaseAnalyticsLogger().logEvent(.addToVacancy(.init(
lectureID: lecture.referenceId,
referrer: lectureActionReferrer
)))
do {
try await services.vacancyService.addLecture(lecture: lecture)
} catch {
Expand All @@ -263,7 +281,10 @@ extension ExpandableLectureCell.ViewModel {
}

func addBookmarkLecture(_ lecture: Lecture) async {
FirebaseAnalyticsLogger().logEvent(.addToBookmark(.init(lectureID: lecture.referenceId, referrer: lectureActionReferrer)))
FirebaseAnalyticsLogger().logEvent(.addToBookmark(.init(
lectureID: lecture.referenceId,
referrer: lectureActionReferrer
)))
isFirstBookmarkAlertPresented = appState.timetable.isFirstBookmark ?? false
do {
try await services.lectureService.bookmarkLecture(lecture: lecture)
Expand Down
11 changes: 9 additions & 2 deletions SNUTT-2022/SNUTT/Views/Components/LectureList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ struct LectureList: View {
LazyVStack(spacing: 0) {
ForEach(lectures) { lecture in
NavigationLink {
LectureDetailScene(viewModel: .init(container: viewModel.container), lecture: lecture, displayMode: .normal)
.analyticsScreen(.lectureDetail(.init(lectureID: lecture.referenceId, referrer: .lectureList)))
LectureDetailScene(
viewModel: .init(container: viewModel.container),
lecture: lecture,
displayMode: .normal
)
.analyticsScreen(.lectureDetail(.init(
lectureID: lecture.referenceId,
referrer: .lectureList
)))
} label: {
VStack(spacing: 0) {
Divider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ struct MenuThemeSheet: View {
.padding(.horizontal, 10)
.padding(.vertical, 5)
.font(STFont.regular14.font)
.background(selectedTheme == theme ? Color(uiColor: .tertiarySystemFill) : .clear)
.background(selectedTheme == theme ? Color(uiColor: .tertiarySystemFill) :
.clear)
.clipShape(Capsule())
}
}
Expand Down
Loading

0 comments on commit 8004985

Please sign in to comment.