mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
jumbomoji searching works
This commit is contained in:
5 files changed
+179
-13
No files matched your search
@@ -49,6 +49,8 @@
|
||||
A97322A12FA7B9C8004B657D /* JumboMoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A02FA7B9C8004B657D /* JumboMoji.swift */; };
|
||||
A97322A22FA7B9C8004B657D /* JumboMoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A02FA7B9C8004B657D /* JumboMoji.swift */; };
|
||||
A97322A32FA7B9C8004B657D /* JumboMoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A02FA7B9C8004B657D /* JumboMoji.swift */; };
|
||||
A97322A52FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */; };
|
||||
A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */; };
|
||||
A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; };
|
||||
A975F91A2FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */; };
|
||||
A975F9202FA52B3600A5C62E /* AddToPackMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */; };
|
||||
@@ -219,6 +221,7 @@
|
||||
A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; };
|
||||
A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; };
|
||||
A97322A02FA7B9C8004B657D /* JumboMoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumboMoji.swift; sourceTree = "<group>"; };
|
||||
A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumboMojiTestView.swift; sourceTree = "<group>"; };
|
||||
A975F9182FA38C8D00A5C62E /* EmojiPackGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPackGridView.swift; sourceTree = "<group>"; };
|
||||
A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToPackMenuView.swift; sourceTree = "<group>"; };
|
||||
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
|
||||
@@ -363,6 +366,7 @@
|
||||
A957C1732ECCE2CE00EA3EE9 /* SettingsView.swift */,
|
||||
A955B3F42EC22EE900E1732D /* SearchView.swift */,
|
||||
A975F91F2FA52B3600A5C62E /* AddToPackMenuView.swift */,
|
||||
A97322A42FA8CA2B004B657D /* JumboMojiTestView.swift */,
|
||||
);
|
||||
path = SwiftUI;
|
||||
sourceTree = "<group>";
|
||||
@@ -711,6 +715,7 @@
|
||||
A9104C802EB4022500D160EA /* MSSticker.swift in Sources */,
|
||||
A9A7A43F2F6835F800BB84C6 /* Trending.swift in Sources */,
|
||||
A9A7A4422F68360200BB84C6 /* GifObject.swift in Sources */,
|
||||
A97322A62FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */,
|
||||
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */,
|
||||
A975F9192FA38C8D00A5C62E /* EmojiPackGridView.swift in Sources */,
|
||||
A957C1772ECD008E00EA3EE9 /* Bundle.swift in Sources */,
|
||||
@@ -836,6 +841,7 @@
|
||||
A9CD6C392EDDE37500B7F421 /* EmojiPackManager.swift in Sources */,
|
||||
A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */,
|
||||
A955B3F62EC22EE900E1732D /* SearchView.swift in Sources */,
|
||||
A97322A52FA8CA2B004B657D /* JumboMojiTestView.swift in Sources */,
|
||||
A9BDEADF2F82BC93002798DF /* NoStickersView.swift in Sources */,
|
||||
A97BFFC02F9E745C000441E5 /* EmojiCollectionViewCell.swift in Sources */,
|
||||
A9B9A8322EB2CD29004C9245 /* SlackResponse.swift in Sources */,
|
||||
|
||||
+116
-13
@@ -6,28 +6,131 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreGraphics
|
||||
|
||||
struct JumboMoji {
|
||||
struct JumboMoji: CustomStringConvertible, Hashable {
|
||||
var baseName: String
|
||||
var width: Int
|
||||
var height: Int
|
||||
var baseName: String
|
||||
var type: JumboMoji.Style
|
||||
var items: [String]
|
||||
|
||||
// init(baseName: String, items: [String]) {
|
||||
// let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) }
|
||||
//
|
||||
//
|
||||
// let coordinates = itemsBaseNameRemoved.map { $0.dropLast($0.split(separator: "-").last?.count ?? 0) }.split(separator: "-").map { Int(String($0)) }
|
||||
// self.width = width
|
||||
// self.height = height
|
||||
// self.baseName = baseName
|
||||
// self.type = type
|
||||
// self.items = items
|
||||
// }
|
||||
var description: String {
|
||||
self.baseName + " " + "\(width)x\(height)"
|
||||
}
|
||||
|
||||
init(baseName: String, items: [String]) {
|
||||
fatalError()
|
||||
let itemsBaseNameRemoved = items.map { String($0.dropFirst(baseName.count+1)) }
|
||||
var coordinates: [(Int, Int)] = []
|
||||
for item in itemsBaseNameRemoved {
|
||||
let split = item.dropLast(item.split(separator: "-").last?.count ?? 0)
|
||||
print(split)
|
||||
}
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.baseName = baseName
|
||||
self.type = .grid
|
||||
self.items = items
|
||||
}
|
||||
|
||||
init?(components: [JumboMoji.Components]) {
|
||||
guard components.allSatisfy({$0.baseName == components.first?.baseName}) else { return nil }
|
||||
self.baseName = components.first!.baseName
|
||||
|
||||
let coords = components.map { CGPoint(x: $0.x, y: $0.y) }
|
||||
guard let width = Int(coords.sorted { $0.x > $1.x }.first?.x.formatted() ?? "") else { return nil }
|
||||
self.width = width
|
||||
guard let height = Int(coords.sorted { $0.y > $1.y }.first?.y.formatted() ?? "") else { return nil }
|
||||
self.height = height
|
||||
|
||||
self.type = .grid
|
||||
self.items = components.map { "\($0.baseName)-\($0.coordinate)-\($0.id)-" }
|
||||
}
|
||||
|
||||
enum Style {
|
||||
case grid
|
||||
case btn
|
||||
}
|
||||
|
||||
static func from(names input: [String]) -> [JumboMoji] {
|
||||
guard input.count > 0 else { return [] }
|
||||
let input = input.sorted()
|
||||
|
||||
var jumboMojiComponents: [String: [JumboMoji.Components]] = [:]
|
||||
for i in input.indices {
|
||||
guard let currentComponents = splitIntoComponents(string: input[i]) else { continue }
|
||||
|
||||
if jumboMojiComponents.isEmpty || jumboMojiComponents[currentComponents.baseName] == nil {
|
||||
jumboMojiComponents[currentComponents.baseName] = [currentComponents]
|
||||
} else {
|
||||
jumboMojiComponents[currentComponents.baseName]?.append(currentComponents)
|
||||
}
|
||||
}
|
||||
|
||||
print(jumboMojiComponents.mapValues({JumboMoji(components: $0)}).count)
|
||||
var result: [JumboMoji] = []
|
||||
for item in jumboMojiComponents {
|
||||
if let jumbomoji = JumboMoji(components: item.value) {
|
||||
result.append(jumbomoji)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
static func splitIntoComponents(string input: String) -> JumboMoji.Components? {
|
||||
var string = input
|
||||
|
||||
var baseNameCount: Int = -1
|
||||
for char in string {
|
||||
if Int(String(char)) == nil {
|
||||
baseNameCount += 1
|
||||
} else { break }
|
||||
}
|
||||
guard baseNameCount > -1 && baseNameCount != input.count else { return nil }
|
||||
let baseName = String(input.prefix(baseNameCount))
|
||||
string = String(string.dropFirst(baseName.count+1))
|
||||
guard input.dropFirst(baseNameCount).first == "-" else { return nil }
|
||||
|
||||
var coordCount = 1
|
||||
var freeSkip = 1
|
||||
for char in string {
|
||||
if Int(String(char)) == nil {
|
||||
guard freeSkip > 0 else { break }
|
||||
freeSkip -= 1
|
||||
continue
|
||||
} else {
|
||||
coordCount += 1
|
||||
}
|
||||
}
|
||||
let coord = String(string.prefix(coordCount))
|
||||
let coordSplit = coord.split(separator: "-").map { String($0) }
|
||||
guard coord.contains("-") &&
|
||||
Int(coordSplit.first ?? "x") != nil &&
|
||||
Int(coordSplit.last ?? "x") != nil
|
||||
else { return nil }
|
||||
string = String(string.dropFirst(coordCount+1))
|
||||
|
||||
let id = string
|
||||
|
||||
return JumboMoji.Components(
|
||||
baseName: baseName,
|
||||
coordinate: coord,
|
||||
id: id
|
||||
)
|
||||
}
|
||||
|
||||
struct Components {
|
||||
var baseName: String
|
||||
var coordinate: String
|
||||
var x: Int {
|
||||
let split = coordinate.split(separator: "-").first ?? "0"
|
||||
return Int(split) ?? 0
|
||||
}
|
||||
var y: Int {
|
||||
let split = coordinate.split(separator: "-").last ?? "0"
|
||||
return Int(split) ?? 0
|
||||
}
|
||||
var id: String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// JumboMojiTestView.swift
|
||||
// StickerSlack
|
||||
//
|
||||
// Created by neon443 on 04/05/2026.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct JumboMojiTestView: View {
|
||||
@State var hoarder: EmojiHoarder
|
||||
@State var searchTerm: String = ""
|
||||
@State var searchResult: [String] = []
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
TextField("search", text: $searchTerm)
|
||||
.autocorrectionDisabled()
|
||||
.onChange(of: searchTerm) { _ in
|
||||
searchResult = hoarder.trie.search(for: searchTerm, previousQuery: nil, previousResult: nil)
|
||||
}
|
||||
ForEach(JumboMoji.from(names: searchResult), id: \.self) { jumboMoji in
|
||||
VStack {
|
||||
ForEach(0..<jumboMoji.height, id: \.self) { row in
|
||||
ForEach(0..<jumboMoji.width, id: \.self) { col in
|
||||
StickerPreview(sticker: hoarder.trie.dict[jumboMoji.items[row+col]] ?? .test)
|
||||
}
|
||||
}
|
||||
// EmojiCollectionView(
|
||||
// hoarder: hoarder,
|
||||
// items: jumboMoji.items,
|
||||
// pack: nil,
|
||||
// width: CGFloat(jumboMoji.width),
|
||||
// style: .jumboMoji
|
||||
// )
|
||||
Text(jumboMoji.description)
|
||||
}
|
||||
}
|
||||
Divider()
|
||||
// ForEach(searchResult, id: \.self) { item in
|
||||
// Text(item)
|
||||
// .border(JumboMoji.splitIntoComponents(string: item) == nil ? .clear : .red)
|
||||
// .foregroundStyle(.gray)
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
JumboMojiTestView(hoarder: EmojiHoarder())
|
||||
}
|
||||
@@ -112,6 +112,11 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
Section("Debug") {
|
||||
NavigationLink {
|
||||
JumboMojiTestView(hoarder: hoarder)
|
||||
} label: {
|
||||
Label("jumbomoji search", systemImage: "text.page.badge.magnifyingglass")
|
||||
}
|
||||
NavigationLink {
|
||||
EmojiCollectionView(
|
||||
hoarder: hoarder,
|
||||
|
||||
@@ -45,6 +45,7 @@ class Trie: ObservableObject {
|
||||
}
|
||||
|
||||
func search(for query: String, previousQuery: String?, previousResult: Set<String>?) -> [String] {
|
||||
guard !query.isEmpty else { return [] }
|
||||
var result: Set<String> = wordlist
|
||||
if let previousQuery,
|
||||
let previousResult,
|
||||
|
||||