Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Stop syncing for non authenticated users
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallino16 committed Mar 8, 2021
1 parent 7a4adbf commit 52efade
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 66 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11

## [Download from mac App Store](https://apps.apple.com/us/app/id1527428847)

![black_light_theme](https://user-images.githubusercontent.com/1506323/101370529-e48ce700-38a9-11eb-8a53-6cabada85a7e.png)

![black_light_theme](https://user-images.githubusercontent.com/1506323/110323754-5560ae00-8015-11eb-98a3-7822772cbe00.png)

## Features

Expand All @@ -28,18 +27,21 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11
* Light & Dark Mode
* Theme selection
* Atom file icons
* Share snippet via [carbon.now.sh](https://carbon.now.sh/)
* Create snippets via deeplinks from StackOverflow via [a Chrome Extension](https://chrome.google.com/webstore/detail/snip-extractor/fioamfejealgknedajclejcnbilifopf)


## Editor

[CodeMirror-SwiftUI](https://github.com/Pictarine/CodeMirror-SwiftUI) is a fork from [CodeMirror-Swift](https://github.com/ProxymanApp/CodeMirror-Swift) by [NghiaTranUIT](https://github.com/NghiaTranUIT) 🙏, repackaged for SwiftUI.

* CodeMirror v5.57.0
* CodeMirror v5.59.4
* Show/Hide invisible characters
* Font size
* Line Wrapping
* 100+ themes available
* Autocompletion hints (ctrl+space)
* Reindent (ctrl+i)


# Incoming
Expand All @@ -49,6 +51,12 @@ Snip is a lightweight snippets manager built with SwiftUI + Combine for macOS 11
- Search


## Contributors

* [DKeu](https://dkeu.de/) for german Translation


## Contributing

Contributions are always welcome!

129 changes: 66 additions & 63 deletions Snip/Components/Sidebar/SnipItemsListAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,76 +143,79 @@ struct SnipItemsListAction {
static func syncGists() -> SnipItemsListAction {
return .init { current in

let currentSnips = current

DispatchQueue.global().async {
SyncManager.shared.pullGists()
.sink(receiveCompletion: { (_) in },
receiveValue: { (gists) in

Publishers.MergeMany(gists.map( { SyncManager.shared.pullGist(id: $0.id) }))
.collect()
.sink(receiveCompletion: { (_) in},
receiveValue: { (gists) in

var syncedSnips: [SnipItem] = []

// Transform all Gists to snipItems
gists.forEach { (gist) in
gist.files.forEach { (_, file) in
let snipItem = file.toSnipItem()
snipItem.gistNodeId = gist.nodeId
snipItem.gistId = gist.id
snipItem.gistURL = gist.url
snipItem.remoteURL = gist.url
snipItem.syncState = .synced
syncedSnips.append(snipItem)
}
}

// Remove synced state of snips absent from Gists
currentSnips.allGist.forEach { (snipItem) in
let syncedSnip = syncedSnips.first(where: { $0.gistId == snipItem.gistId && $0.name == snipItem.name })
if let syncedSnip = syncedSnip {
DispatchQueue.main.async {
let snipToSync = snipItem
snipToSync.snippet = syncedSnip.snippet
snipToSync.syncState = .synced
snipToSync.gistId = syncedSnip.gistId
snipToSync.gistURL = syncedSnip.gistURL
snipToSync.gistNodeId = syncedSnip.gistNodeId
snipToSync.remoteURL = syncedSnip.remoteURL
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
if SyncManager.shared.isAuthenticated {
let currentSnips = current

DispatchQueue.global().async {
SyncManager.shared.pullGists()
.sink(receiveCompletion: { (_) in },
receiveValue: { (gists) in

Publishers.MergeMany(gists.map( { SyncManager.shared.pullGist(id: $0.id) }))
.collect()
.sink(receiveCompletion: { (_) in},
receiveValue: { (gists) in

var syncedSnips: [SnipItem] = []

// Transform all Gists to snipItems
gists.forEach { (gist) in
gist.files.forEach { (_, file) in
let snipItem = file.toSnipItem()
snipItem.gistNodeId = gist.nodeId
snipItem.gistId = gist.id
snipItem.gistURL = gist.url
snipItem.remoteURL = gist.url
snipItem.syncState = .synced
syncedSnips.append(snipItem)
}
}
else {
DispatchQueue.main.async {
let snipToSync = snipItem
snipToSync.gistId = nil
snipToSync.gistURL = nil
snipToSync.gistNodeId = nil
snipToSync.syncState = .local
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))

// Remove synced state of snips absent from Gists
currentSnips.allGist.forEach { (snipItem) in
let syncedSnip = syncedSnips.first(where: { $0.gistId == snipItem.gistId && $0.name == snipItem.name })
if let syncedSnip = syncedSnip {
DispatchQueue.main.async {
let snipToSync = snipItem
snipToSync.snippet = syncedSnip.snippet
snipToSync.syncState = .synced
snipToSync.gistId = syncedSnip.gistId
snipToSync.gistURL = syncedSnip.gistURL
snipToSync.gistNodeId = syncedSnip.gistNodeId
snipToSync.remoteURL = syncedSnip.remoteURL
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
}
}
else {
DispatchQueue.main.async {
let snipToSync = snipItem
snipToSync.gistId = nil
snipToSync.gistURL = nil
snipToSync.gistNodeId = nil
snipToSync.syncState = .local
SnippetManager.shared.trigger(action: .updateExistingItem(newestItem: snipToSync))
}
}
}
}

// Add Gists
syncedSnips.forEach { (syncedSnip) in
let snipItem = currentSnips.first(where: { $0.gistId == syncedSnip.gistId })
if snipItem == nil {
DispatchQueue.main.async {
SnippetManager.shared.trigger(action: .addSnippet(syncedSnip))
// Add Gists
syncedSnips.forEach { (syncedSnip) in
let snipItem = currentSnips.first(where: { $0.gistId == syncedSnip.gistId })
if snipItem == nil {
DispatchQueue.main.async {
SnippetManager.shared.trigger(action: .addSnippet(syncedSnip))
}
}
}
}

})
.store(in: &stores)

})
.store(in: &stores)
})
.store(in: &stores)

})
.store(in: &stores)
}
}

}
}

Expand Down

0 comments on commit 52efade

Please sign in to comment.