Skip to content

Commit

Permalink
move macOS code into Mio folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kloenk committed Jun 13, 2021
1 parent 1cee1e0 commit 7178dfe
Show file tree
Hide file tree
Showing 13 changed files with 612 additions and 406 deletions.
69 changes: 69 additions & 0 deletions Mio/Conversations/RecentRoomsView.swift
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: [])
}
}
84 changes: 84 additions & 0 deletions Mio/Conversations/RoomContainerView.swift
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: [])
}
}*/
61 changes: 61 additions & 0 deletions Mio/Settings/SettingsContainerView.swift
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()
}
}
22 changes: 22 additions & 0 deletions Mio/Shared Views/ImagePicker.swift
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()
}
}
50 changes: 50 additions & 0 deletions Mio/Shared Views/MessageTextViewWrapper.swift
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
}
}
Loading

0 comments on commit 7178dfe

Please sign in to comment.