Skip to content

Commit

Permalink
Merge pull request #108 from DeveloperAcademy-POSTECH/105-refcode-ref…
Browse files Browse the repository at this point in the history
…actoring

[Feat/#105]code refactoring
  • Loading branch information
HappyDoran authored May 24, 2024
2 parents 9a30735 + 8a305fd commit 8b7d16d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 93 deletions.
18 changes: 6 additions & 12 deletions DDooing/DDooing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
4F3F81422BFE10AE008C920C /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF515932BF33F810056531C /* HomeView.swift */; };
4F3F81542BFE63CA008C920C /* AppModelContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F3F81532BFE63CA008C920C /* AppModelContainer.swift */; };
4F3F81552BFE63CA008C920C /* AppModelContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F3F81532BFE63CA008C920C /* AppModelContainer.swift */; };
4F8D878D2BFF864F006BEF4A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4F8D878C2BFF84DF006BEF4A /* GoogleService-Info.plist */; };
4F8D878E2BFF8650006BEF4A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4F8D878C2BFF84DF006BEF4A /* GoogleService-Info.plist */; };
4FAD25B02BF3339A00EBD37A /* DDooingApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FAD25AF2BF3339A00EBD37A /* DDooingApp.swift */; };
4FAD25B22BF3339A00EBD37A /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FAD25B12BF3339A00EBD37A /* MainView.swift */; };
4FAD25B42BF3339B00EBD37A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FAD25B32BF3339B00EBD37A /* Assets.xcassets */; };
Expand Down Expand Up @@ -138,7 +140,7 @@
4F3F813B2BFDDCEC008C920C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4F3F813D2BFDDDE2008C920C /* WidgetColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetColor.swift; sourceTree = "<group>"; };
4F3F81532BFE63CA008C920C /* AppModelContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppModelContainer.swift; sourceTree = "<group>"; };
4F3F81582BFECEBA008C920C /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
4F8D878C2BFF84DF006BEF4A /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
4FAD25AC2BF3339A00EBD37A /* DDooing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DDooing.app; sourceTree = BUILT_PRODUCTS_DIR; };
4FAD25AF2BF3339A00EBD37A /* DDooingApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDooingApp.swift; sourceTree = "<group>"; };
4FAD25B12BF3339A00EBD37A /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -322,7 +324,7 @@
4FAD25A32BF3339A00EBD37A = {
isa = PBXGroup;
children = (
4F3F81582BFECEBA008C920C /* GoogleService-Info.plist */,
4F8D878C2BFF84DF006BEF4A /* GoogleService-Info.plist */,
4FBE64CB2BFDCB80008363A0 /* DDooingWidgetExtension.entitlements */,
4FAD25AE2BF3339A00EBD37A /* DDooing */,
4FAD25BF2BF3339B00EBD37A /* DDooingTests */,
Expand Down Expand Up @@ -387,7 +389,6 @@
4FBE64AE2BFDA19E008363A0 /* Recovered References */ = {
isa = PBXGroup;
children = (
9F2C6FE52BFD76A000B5C7A7 /* GoogleService-Info.plist */,
);
name = "Recovered References";
sourceTree = "<group>";
Expand Down Expand Up @@ -415,13 +416,6 @@
name = Frameworks;
sourceTree = "<group>";
};
790BA2342BFDCFD100A1E364 /* Recovered References */ = {
isa = PBXGroup;
children = (
);
name = "Recovered References";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -570,12 +564,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4F8D878D2BFF864F006BEF4A /* GoogleService-Info.plist in Resources */,
4FAD25B72BF3339B00EBD37A /* Preview Assets.xcassets in Resources */,
4F1A59492BF8892000C3EF2C /* Pretendard-Bold.otf in Resources */,
9F2C6FE62BFD76A000B5C7A7 /* GoogleService-Info.plist in Resources */,
4F3F813C2BFDDCEC008C920C /* Assets.xcassets in Resources */,
4F1A59432BF8892000C3EF2C /* Pretendard-Regular.otf in Resources */,
10CAF9592BFE66AE00318EB0 /* GoogleService-Info.plist in Resources */,
4F1A59552BF8892000C3EF2C /* Pretendard-SemiBold.otf in Resources */,
4F1A594C2BF8892000C3EF2C /* Pretendard-Thin.otf in Resources */,
4F1A594F2BF8892000C3EF2C /* Pretendard-Black.otf in Resources */,
Expand Down Expand Up @@ -624,6 +617,7 @@
buildActionMask = 2147483647;
files = (
4F3F813F2BFDDEDC008C920C /* Assets.xcassets in Resources */,
4F8D878E2BFF8650006BEF4A /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 0 additions & 1 deletion DDooing/DDooing/Views/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct HomeView: View {
var body: some View {
NavigationStack{
VStack {

Image("Heart button")
.resizable()
.aspectRatio(contentMode: .fit)
Expand Down
84 changes: 40 additions & 44 deletions DDooing/DDooing/Views/ShowMessage/ShowMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,22 @@ struct ShowMessageView: View {
var body: some View {
NavigationStack {
VStack {

Spacer()

HStack {
Text("오늘의 메세지")
.font(.largeTitle.bold())
Spacer()
}
.padding()
.padding(.top, 10)

Spacer()


ScrollView {
Image(imageName(for: recivedMessages.count))
.resizable()
.frame(width: 140, height: 130)
.scaledToFill()

Text("오늘 받은 메세지만 확인할 수 있습니다.")
.font(.pretendardThin14)
.foregroundStyle(.secondary)
Expand All @@ -62,7 +58,7 @@ struct ShowMessageView: View {
Text("아직 받은 메세지가 없어요 ( ⚈̥̥̥̥̥́⌢⚈̥̥̥̥̥̀)")
.font(.pretendardRegular16)
.frame(width: 400,height: 400)


} else {
ForEach(recivedMessages.sorted(by: { $0.time > $1.time })) { message in
Expand Down Expand Up @@ -107,26 +103,26 @@ struct ShowMessageView: View {
} else {
Spacer()
}
Text(formattedTime(from: message.time))
.foregroundStyle(.secondary)
.font(.footnote)
.padding(.trailing, 20)
Text(formattedTime(from: message.time))
.foregroundStyle(.secondary)
.font(.footnote)
.padding(.trailing, 20)
}
.padding(.top, 20)
}
.padding(.top, 20)
}
}
}
}
.onAppear {
addObserveMessages()

if let user = Auth.auth().currentUser {
self.checkAndDeleteOldMessages(userAUID: user.uid)
.onAppear {
addObserveMessages()
if let user = Auth.auth().currentUser {
self.checkAndDeleteOldMessages(userAUID: user.uid)
}
}
}
}
}

// 메세지 개수에 따른 이미지 변경 함수
func imageName(for messageCount: Int) -> String {
switch messageCount {
Expand All @@ -150,45 +146,44 @@ struct ShowMessageView: View {
private func addObserveMessages() {
observeMessages { messageData in
if let text = messageData["messageText"] as? String,
let timestamp = messageData["timeStamp"] as? Timestamp,
let isStarred = messageData["isStarred"] as? Bool,
let messageId = messageData["messageId"] as? String {
self.fetchMyConnectedNickname { nickname in
// 중복 체크: 이미 추가된 메시지인지 확인
if !self.recivedMessages.contains(where: { $0.messageId == messageId }) {
let message = RecivedMessage(messageId: messageId, name: nickname, text: text, time: timestamp.dateValue(), isStarred: isStarred)
self.recivedMessages.append(message)
}
let timestamp = messageData["timeStamp"] as? Timestamp,
let isStarred = messageData["isStarred"] as? Bool,
let messageId = messageData["messageId"] as? String {
self.fetchMyConnectedNickname { nickname in
// 중복 체크: 이미 추가된 메시지인지 확인
if !self.recivedMessages.contains(where: { $0.messageId == messageId }) {
let message = RecivedMessage(messageId: messageId, name: nickname, text: text, time: timestamp.dateValue(), isStarred: isStarred)
self.recivedMessages.append(message)
}
}
}
}

// db에서 메세지가 삭제되면 뷰에서도 삭제되게 하기
observeMessages { messageData, documentID, changeType in
if let text = messageData["messageText"] as? String,
let timestamp = messageData["timeStamp"] as? Timestamp,
let isStarred = messageData["isStarred"] as? Bool,
let messageId = messageData["messageId"] as? String {
self.fetchMyConnectedNickname { nickname in
switch changeType {
case .added:
if !self.recivedMessages.contains(where: { $0.messageId == messageId }) {
let message = RecivedMessage(messageId: messageId, name: nickname, text: text, time: timestamp.dateValue(), isStarred: isStarred)
self.recivedMessages.append(message)
}
case .removed:
if let index = self.recivedMessages.firstIndex(where: { $0.messageId == messageId }) {
self.recivedMessages.remove(at: index)
}
default:
break
let timestamp = messageData["timeStamp"] as? Timestamp,
let isStarred = messageData["isStarred"] as? Bool,
let messageId = messageData["messageId"] as? String {
self.fetchMyConnectedNickname { nickname in
switch changeType {
case .added:
if !self.recivedMessages.contains(where: { $0.messageId == messageId }) {
let message = RecivedMessage(messageId: messageId, name: nickname, text: text, time: timestamp.dateValue(), isStarred: isStarred)
self.recivedMessages.append(message)
}
case .removed:
if let index = self.recivedMessages.firstIndex(where: { $0.messageId == messageId }) {
self.recivedMessages.remove(at: index)
}
default:
break
}
}
}
}
}


func observeMessages(completion: @escaping ([String: Any]) -> Void) {
let db = Firestore.firestore()

Expand Down Expand Up @@ -285,6 +280,7 @@ struct ShowMessageView: View {




#Preview {
ShowMessageView(partnerUID: nil)
}
3 changes: 3 additions & 0 deletions DDooing/DDooingWidget/DDooingWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ struct SimpleEntry: TimelineEntry {
}

struct DDooingWidget: Widget {
init() {
FirebaseApp.configure()
}

let kind: String = "DDooingWidget"

Expand Down
36 changes: 0 additions & 36 deletions DDooing/GoogleService-Info.plist

This file was deleted.

0 comments on commit 8b7d16d

Please sign in to comment.