-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
612 additions
and
406 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// RecentRoomsView.swift | ||
// Mio | ||
// | ||
// Created by Finn Behrens on 13.06.21. | ||
// Copyright © 2021 Kilian Koeltzsch. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import MatrixSDK | ||
|
||
import NioKit | ||
|
||
struct RecentRoomsView: View { | ||
@EnvironmentObject var store: AccountStore | ||
|
||
@Binding var selectedNavigationItem: SelectedNavigationItem? | ||
@Binding var selectedRoomId: ObjectIdentifier? | ||
|
||
let rooms: [NIORoom] | ||
|
||
private var joinedRooms: [NIORoom] { | ||
rooms.filter {$0.room.summary.membership == .join} | ||
} | ||
|
||
private var invitedRooms: [NIORoom] { | ||
rooms.filter {$0.room.summary.membership == .invite} | ||
} | ||
|
||
var body: some View { | ||
NavigationView { | ||
List { | ||
if !invitedRooms.isEmpty { | ||
RoomsListSection( | ||
sectionHeader: L10n.RecentRooms.PendingInvitations.header, | ||
rooms: invitedRooms, | ||
onLeaveAlertTitle: L10n.RecentRooms.PendingInvitations.Leave.alertTitle, | ||
selectedRoomId: $selectedRoomId | ||
) | ||
} | ||
|
||
RoomsListSection( | ||
sectionHeader: invitedRooms.isEmpty ? nil : L10n.RecentRooms.Rooms.header , | ||
rooms: joinedRooms, | ||
onLeaveAlertTitle: L10n.RecentRooms.Leave.alertTitle, | ||
selectedRoomId: $selectedRoomId | ||
) | ||
|
||
} | ||
.listStyle(SidebarListStyle()) | ||
.navigationTitle("Mio") | ||
.frame(minWidth: Style.minSidebarWidth) | ||
.toolbar { | ||
ToolbarItem(placement: .cancellationAction) { | ||
Button(action: { self.selectedNavigationItem = .newConversation }) { | ||
Label(L10n.RecentRooms.AccessibilityLabel.newConversation, | ||
systemImage: SFSymbol.newConversation.rawValue) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct RecentRoomsView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
RecentRoomsView(selectedNavigationItem: .constant(nil), selectedRoomId: .constant(nil), rooms: []) | ||
} | ||
} |
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,84 @@ | ||
import SwiftUI | ||
import Combine | ||
import MatrixSDK | ||
|
||
import NioKit | ||
|
||
struct RoomContainerView: View { | ||
@ObservedObject var room: NIORoom | ||
|
||
@State private var showAttachmentPicker = false | ||
@State private var showImagePicker = false | ||
@State private var eventToReactTo: String? | ||
@State private var showJoinAlert = false | ||
|
||
private var roomView: RoomView { | ||
RoomView( | ||
events: room.events(), | ||
isDirect: room.isDirect, | ||
showAttachmentPicker: $showAttachmentPicker, | ||
onCommit: { message in | ||
self.room.send(text: message) | ||
}, | ||
onReact: { eventId in | ||
self.eventToReactTo = eventId | ||
}, | ||
onRedact: { eventId, reason in | ||
self.room.redact(eventId: eventId, reason: reason) | ||
}, | ||
onEdit: { message, eventId in | ||
self.room.edit(text: message, eventId: eventId) | ||
} | ||
) | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: 0) { | ||
Divider() // TBD: This might be better done w/ toolbar styling | ||
roomView | ||
} | ||
.navigationTitle(Text(room.summary.displayname ?? "")) | ||
// TODO: action sheet | ||
.sheet(item: $eventToReactTo) { eventId in | ||
ReactionPicker { reaction in | ||
self.room.react(toEventId: eventId, emoji: reaction) | ||
self.eventToReactTo = nil | ||
} | ||
} | ||
// TODO: join alert | ||
.onAppear { | ||
switch self.room.summary.membership { | ||
case .invite: | ||
self.showJoinAlert = true | ||
case .join: | ||
self.room.markAllAsRead() | ||
default: | ||
break | ||
} | ||
} | ||
.environmentObject(room) | ||
// TODO: background sheet thing | ||
.background(Color(.textBackgroundColor)) | ||
.frame(minWidth: Style.minTimelineWidth) | ||
} | ||
|
||
// TODO: port me to macOS | ||
/* | ||
private var attachmentPickerSheet: ActionSheet { | ||
ActionSheet( | ||
title: Text(verbatim: L10n.Room.Attachment.selectType), buttons: [ | ||
.default(Text(verbatim: L10n.Room.Attachment.typePhoto), action: { | ||
self.showImagePicker = true | ||
}), | ||
.cancel() | ||
] | ||
) | ||
}*/ | ||
} | ||
|
||
|
||
/*struct RecentRoomsContainerView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
RecentRoomsView(selectedNavigationItem: .constant(nil), selectedRoomId: .constant(nil), rooms: []) | ||
} | ||
}*/ |
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,61 @@ | ||
// | ||
// SettingsContainerView.swift | ||
// Mio | ||
// | ||
// Created by Finn Behrens on 13.06.21. | ||
// Copyright © 2021 Kilian Koeltzsch. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import NioKit | ||
|
||
struct SettingsContainerView: View { | ||
@EnvironmentObject var store: AccountStore | ||
|
||
var body: some View { | ||
MacSettingsView(logoutAction: { | ||
async { | ||
await self.store.logout() | ||
} | ||
}) | ||
} | ||
} | ||
|
||
private struct MacSettingsView: View { | ||
@AppStorage("accentColor") private var accentColor: Color = .purple | ||
let logoutAction: () -> Void | ||
|
||
var body: some View { | ||
Form { | ||
Section { | ||
Picker(selection: $accentColor, label: Text(verbatim: L10n.Settings.accentColor)) { | ||
ForEach(Color.allAccentOptions, id: \.self) { color in | ||
HStack { | ||
Circle() | ||
.frame(width: 20) | ||
.foregroundColor(color) | ||
Text(color.description.capitalized) | ||
} | ||
.tag(color) | ||
} | ||
} | ||
// No icon picker on macOS | ||
} | ||
|
||
Section { | ||
Button(action: self.logoutAction) { | ||
Text(verbatim: L10n.Settings.logOut) | ||
} | ||
} | ||
} | ||
.padding() | ||
.frame(maxWidth: 320) | ||
} | ||
} | ||
|
||
struct SettingsContainerView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SettingsContainerView() | ||
} | ||
} |
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,22 @@ | ||
// | ||
// ImagePicker.swift | ||
// Mio | ||
// | ||
// Created by Finn Behrens on 13.06.21. | ||
// Copyright © 2021 Kilian Koeltzsch. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ImagePicker: View { | ||
|
||
var body: some View { | ||
Text("Sorry, no image picker on macOS yet :-/") | ||
} | ||
} | ||
|
||
struct ImagePicker_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ImagePicker() | ||
} | ||
} |
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,50 @@ | ||
// | ||
// MessageTextViewWrapper.swift | ||
// Mio | ||
// | ||
// Created by Finn Behrens on 13.06.21. | ||
// Copyright © 2021 Kilian Koeltzsch. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import NioKit | ||
|
||
class MessageTextView: NSTextView { | ||
convenience init(attributedString: NSAttributedString, linkColor: UXColor, | ||
maxSize: CGSize) | ||
{ | ||
self.init() | ||
backgroundColor = .clear | ||
textContainerInset = .zero | ||
isEditable = false | ||
linkTextAttributes = [ | ||
.foregroundColor: linkColor, | ||
.underlineStyle: NSUnderlineStyle.single.rawValue, | ||
] | ||
|
||
self.insertText(attributedString, | ||
replacementRange: NSRange(location: 0, length: 0)) | ||
self.maxSize = maxSize | ||
|
||
// don't resist text wrapping across multiple lines | ||
setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | ||
} | ||
} | ||
|
||
struct MessageTextViewWrapper: NSViewRepresentable { | ||
let attributedString: NSAttributedString | ||
let linkColor: NSColor | ||
let maxSize: CGSize | ||
|
||
func makeNSView(context: Context) -> MessageTextView { | ||
MessageTextView(attributedString: attributedString, linkColor: linkColor, maxSize: maxSize) | ||
} | ||
|
||
func updateNSView(_ uiView: MessageTextView, context: Context) { | ||
// nothing to update | ||
} | ||
|
||
func makeCoordinator() { | ||
// nothing to coordinate | ||
} | ||
} |
Oops, something went wrong.