Skip to content

Commit

Permalink
Merge pull request #106 from 42Caterpie/feature/modify-competitionVie…
Browse files Browse the repository at this point in the history
…w-Design
  • Loading branch information
hekang42 authored Mar 19, 2022
2 parents e9f0a80 + 58bf8af commit 56de862
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 75 deletions.
14 changes: 9 additions & 5 deletions Git-Challenges/Git-Challenges.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
730952C427C4BF66007A1155 /* Encodable+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 730952C327C4BF66007A1155 /* Encodable+Extension.swift */; };
730952C627C4BFA6007A1155 /* RandomNumberGenarator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 730952C527C4BFA6007A1155 /* RandomNumberGenarator.swift */; };
730952C827C4BFC7007A1155 /* ValidRoomID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 730952C727C4BFC7007A1155 /* ValidRoomID.swift */; };
730BC43927E4241A00D89FF6 /* UserImageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 730BC43827E4241A00D89FF6 /* UserImageService.swift */; };
731FF2A82796B296001CD5E7 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 731FF2A72796B296001CD5E7 /* Theme.swift */; };
7320A758279E6FD20021371C /* ColorThemeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7320A757279E6FD20021371C /* ColorThemeService.swift */; };
733D9DFE27D9F1780062ECF2 /* KeyboardObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 733D9DFD27D9F1780062ECF2 /* KeyboardObserver.swift */; };
Expand Down Expand Up @@ -59,7 +60,6 @@
73E1A83F27993C8400E1BDFE /* BadgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E1A83E27993C8400E1BDFE /* BadgeView.swift */; };
73E1A84127993CB500E1BDFE /* BadgeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E1A84027993CB500E1BDFE /* BadgeViewModel.swift */; };
73E1A84327994DC800E1BDFE /* Badge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E1A84227994DC800E1BDFE /* Badge.swift */; };
73E33FA92796C35300BF994D /* NameCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E33FA82796C35300BF994D /* NameCardViewModel.swift */; };
73E33FAB2796C36F00BF994D /* NameCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E33FAA2796C36F00BF994D /* NameCard.swift */; };
73E7F07727927A3A0045AC5F /* Commit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E7F07627927A3A0045AC5F /* Commit.swift */; };
73E7F07A27927B9D0045AC5F /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E7F07927927B9D0045AC5F /* String+Extensions.swift */; };
Expand Down Expand Up @@ -129,6 +129,7 @@
730952C327C4BF66007A1155 /* Encodable+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Encodable+Extension.swift"; sourceTree = "<group>"; };
730952C527C4BFA6007A1155 /* RandomNumberGenarator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomNumberGenarator.swift; sourceTree = "<group>"; };
730952C727C4BFC7007A1155 /* ValidRoomID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValidRoomID.swift; sourceTree = "<group>"; };
730BC43827E4241A00D89FF6 /* UserImageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserImageService.swift; sourceTree = "<group>"; };
731FF2A72796B296001CD5E7 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
7320A757279E6FD20021371C /* ColorThemeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorThemeService.swift; sourceTree = "<group>"; };
7326007627B1068400650FC6 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -162,7 +163,6 @@
73E1A83E27993C8400E1BDFE /* BadgeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BadgeView.swift; sourceTree = "<group>"; };
73E1A84027993CB500E1BDFE /* BadgeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BadgeViewModel.swift; sourceTree = "<group>"; };
73E1A84227994DC800E1BDFE /* Badge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Badge.swift; sourceTree = "<group>"; };
73E33FA82796C35300BF994D /* NameCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameCardViewModel.swift; sourceTree = "<group>"; };
73E33FAA2796C36F00BF994D /* NameCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NameCard.swift; sourceTree = "<group>"; };
73E7F07627927A3A0045AC5F /* Commit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Commit.swift; sourceTree = "<group>"; };
73E7F07927927B9D0045AC5F /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -279,6 +279,7 @@
A83AA0F027998FA80006A718 /* NotificationManager.swift */,
735AA3C427916A16000E4E8C /* UserInfoService.swift */,
7320A757279E6FD20021371C /* ColorThemeService.swift */,
730BC43827E4241A00D89FF6 /* UserImageService.swift */,
);
path = Service;
sourceTree = "<group>";
Expand Down Expand Up @@ -370,7 +371,6 @@
isa = PBXGroup;
children = (
73E1A84027993CB500E1BDFE /* BadgeViewModel.swift */,
73E33FA82796C35300BF994D /* NameCardViewModel.swift */,
73EDBD70279A815300C9B6F0 /* LoginViewModel.swift */,
A8E9B2AF27C657B8006403E2 /* CompetitionRoomViewModel.swift */,
);
Expand Down Expand Up @@ -522,6 +522,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
730BC43927E4241A00D89FF6 /* UserImageService.swift in Sources */,
73E7F07727927A3A0045AC5F /* Commit.swift in Sources */,
A83AA0F127998FA80006A718 /* NotificationManager.swift in Sources */,
733D9DFE27D9F1780062ECF2 /* KeyboardObserver.swift in Sources */,
Expand Down Expand Up @@ -557,7 +558,6 @@
A8AD131227DB44980023E344 /* CompetitionInProgressView.swift in Sources */,
73751ED6279D6A76006A8F94 /* ActivityIndicator.swift in Sources */,
A83AA0EF2799857F0006A718 /* SettingView.swift in Sources */,
73E33FA92796C35300BF994D /* NameCardViewModel.swift in Sources */,
730952C827C4BFC7007A1155 /* ValidRoomID.swift in Sources */,
73E0EAA027B4F25D0083F408 /* UserDefaults+Extensions.swift in Sources */,
A8A113352793F95F00F9C984 /* Constants.swift in Sources */,
Expand Down Expand Up @@ -761,6 +761,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = "Let's Git it!/Let's Git it!.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.0;
DEVELOPMENT_ASSET_PATHS = "";
Expand All @@ -783,6 +784,7 @@
MARKETING_VERSION = 3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.github.Caterpie;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -800,7 +802,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.0;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 4L7K3ZV8H2;
DEVELOPMENT_TEAM = 9TH57H8UP9;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Let's Git it!/Info.plist";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand Down Expand Up @@ -831,6 +833,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = StaticWidgetExtension.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.0;
DEVELOPMENT_TEAM = 9TH57H8UP9;
Expand All @@ -847,6 +850,7 @@
MARKETING_VERSION = 3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.github.Caterpie.LetsWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
struct CreateRoomModalView: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@EnvironmentObject var competitionService: CompetitionService
@EnvironmentObject var showModalView: ShowModalView
@State var title: String = ""
@State var startDate: Date = Date()
@State var maxParticipants: Int = 2
Expand Down Expand Up @@ -93,7 +94,7 @@ struct CreateRoomModalView: View {
maxParticipants: maxParticipants
)
competitionService.createRoom(with: roomData)
self.presentationMode.wrappedValue.dismiss()
showModalView.showCreateRoomModal = false
} label: {
ZStack {
RoundedRectangle(cornerRadius: 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
struct JoinRoomModalView: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@EnvironmentObject var competitionMainViewModel: CompetitionService
@EnvironmentObject var showModalView: ShowModalView
@State var roomNumber: String = ""

var body: some View {
Expand Down Expand Up @@ -40,7 +41,7 @@ struct JoinRoomModalView: View {
Button {
competitionMainViewModel.joinRoom(roomNumber)
if competitionMainViewModel.isJoinable {
self.presentationMode.wrappedValue.dismiss()
showModalView.showJoinRoomModal = false
}
} label: {
ZStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class CompetitionService: ObservableObject {
else {
return
}

completionHandler(roomData)
}
}
Expand Down
54 changes: 54 additions & 0 deletions Git-Challenges/Let's Git it!/Service/UserImageService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// UserImage.swift
// Let's Git it!
//
// Created by 강희영 on 2022/03/18.
//

import SwiftUI

class UserImageService: ObservableObject {
@Published var savedUserProfileImage: [String: Data] = [:]

func currentUserProfileImage() -> some View {
let userID = UserDefaults.shared.string(forKey: "userId") ?? ""
let url = URL(string: "https://github.com/\(userID).png?s=80")!

if let data = try? Data(contentsOf: url) {
return Image(uiImage: UIImage(data: data)!)
.resizable()
.clipShape(Circle())
.frame(width: 77, height: 77)
} else {
return Image(systemName: "questionmark.circle.fill")
.resizable()
.clipShape(Circle())
.frame(width: 77, height: 77)
}
}

func userProfileImage(ID userID: String) -> some View {
let imageData: Data

if self.savedUserProfileImage[userID] != nil {
imageData = self.savedUserProfileImage[userID]!
} else {
let url = URL(string: "https://github.com/\(userID).png?s=40")!

if let data = try? Data(contentsOf: url) {
imageData = data
self.savedUserProfileImage.updateValue(imageData, forKey: userID)
} else {
return AnyView(Image(systemName: "questionmark.circle.fill")
.resizable()
.foregroundColor(.gray)
.clipShape(Circle())
.frame(width: 30, height: 30))
}
}
return AnyView(Image(uiImage: UIImage(data: imageData)!)
.resizable()
.clipShape(Circle())
.frame(width: 30, height: 30))
}
}
61 changes: 41 additions & 20 deletions Git-Challenges/Let's Git it!/View/CompetitionMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@

import SwiftUI

class ShowModalView: ObservableObject {
@Published var showCreateRoomModal: Bool = false
@Published var showJoinRoomModal: Bool = false
}

struct CompetitionMainView: View {
@State private var backgroundBlur: CGFloat = 0
@State private var halfModalOffset = uiSize.height - 500
@State private var showActionSheet: Bool = false
@State private var showCreateRoomModal: Bool = false
@State private var showJoinRoomModal: Bool = false
@ObservedObject var keyboard: KeyboardObserver = KeyboardObserver()
@ObservedObject var competitionService = CompetitionService()
@ObservedObject var showModalView = ShowModalView()
@ObservedObject var userImageService = UserImageService()

private func toolbar() -> some View {
HStack {
Spacer()
Button {
if (!(showActionSheet || showJoinRoomModal || showCreateRoomModal)) {
if (!(showActionSheet ||
showModalView.showJoinRoomModal ||
showModalView.showCreateRoomModal)) {
showActionSheet = true
}
} label: {
Expand All @@ -39,13 +46,15 @@ struct CompetitionMainView: View {
.foregroundColor(.white)
.shadow(radius: 10)
VStack {
if showJoinRoomModal {
if showModalView.showJoinRoomModal {
JoinRoomModalView()
.environmentObject(competitionService)
.environmentObject(showModalView)
.frame(height: 350)
} else {
CreateRoomModalView()
.environmentObject(competitionService)
.environmentObject(showModalView)
.frame(height: 350)
}
Spacer()
Expand All @@ -57,14 +66,21 @@ struct CompetitionMainView: View {
}

private func competitionRoomCell(_ room: RoomData) -> some View {
return HStack {
VStack (alignment: .leading) {
Text("\(room.title)")
.font(.system(size: 18, weight: .bold))
Text("\(room.startDate) ~")
return VStack (alignment: .leading) {
Text("\(room.title)")
.font(.system(size: 18, weight: .bold))
Text("\(room.startDate) ~")
HStack {
ForEach (room.participants, id: \.self) { userID in
userImageService
.userProfileImage(ID: userID)
.padding(.horizontal, -10)
}
Spacer()
}
Spacer()
.padding(.leading, 10)
}
.padding(.leading, 20)
.modifier(CardModifier(height: 144))
.padding([.vertical], 5)
}
Expand All @@ -91,14 +107,18 @@ struct CompetitionMainView: View {
}
Spacer()
}
.disabled(showActionSheet || showJoinRoomModal || showCreateRoomModal)
.disabled(showActionSheet ||
showModalView.showJoinRoomModal ||
showModalView.showCreateRoomModal)
.onTapGesture {
showActionSheet = false
showJoinRoomModal = false
showCreateRoomModal = false
showModalView.showJoinRoomModal = false
showModalView.showCreateRoomModal = false
}
.blur(radius: showJoinRoomModal || showActionSheet || showCreateRoomModal ? 3 : 0)
if showJoinRoomModal || showCreateRoomModal {
.blur(radius: showActionSheet ||
showModalView.showJoinRoomModal ||
showModalView.showCreateRoomModal ? 3 : 0)
if showModalView.showJoinRoomModal || showModalView.showCreateRoomModal {
halfModalView()
}
}
Expand All @@ -110,8 +130,8 @@ struct CompetitionMainView: View {
buttons: [
.default(
Text("Make Room"),
action: { showCreateRoomModal = true }),
.default(Text("Join Room"), action: { showJoinRoomModal = true }),
action: { showModalView.showCreateRoomModal = true }),
.default(Text("Join Room"), action: { showModalView.showJoinRoomModal = true }),
.cancel({ showActionSheet = false })
])
}
Expand All @@ -120,13 +140,14 @@ struct CompetitionMainView: View {
VStack {
toolbar()
gameListandModalView()
.actionSheet(isPresented: $showActionSheet) {
makeJoinActionsheet()
}
.actionSheet(isPresented: $showActionSheet) {
makeJoinActionsheet()
}
}
.navigationBarTitle("")
.navigationBarHidden(true)
.onAppear {
competitionService.requestRoomDatas()
self.keyboard.addObserver()
}
.onDisappear {
Expand Down
1 change: 0 additions & 1 deletion Git-Challenges/Let's Git it!/View/MainTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct MainTabView: View {
.tabItem {
Image(systemName: "house")
}

CompetitionMainView()
.tabItem {
Image(systemName: "gamecontroller.fill")
Expand Down
8 changes: 2 additions & 6 deletions Git-Challenges/Let's Git it!/View/NameCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import SwiftUI

struct NameCardView: View {
@EnvironmentObject private var userInfoService: UserInfoService
@ObservedObject var nameCardViewModel = NameCardViewModel()

@ObservedObject private var userImageService = UserImageService()
let userId = UserDefaults.shared.string(forKey: "userId") ?? ""
let themeEmojis = getThemeEmojis()

Expand Down Expand Up @@ -40,10 +39,7 @@ struct NameCardView: View {
private var nameCard: some View {
HStack {
Spacer()
Image(uiImage: nameCardViewModel.image)
.resizable()
.clipShape(Circle())
.frame(width: 77, height: 77)
userImageService.currentUserProfileImage()
Spacer()
Spacer()
VStack (spacing: 0) {
Expand Down
Loading

0 comments on commit 56de862

Please sign in to comment.