Sign up
Login
New paste
English
English
Português
Sign up
Login
New Paste
Browse
import SwiftUI import SwiftUIFlux import Combine // MARK: - Movies List struct MoviesList: ConnectedView { struct Props { let searchedMovies: [Int]? let searchedKeywords: [Keyword]? let searcherdPeoples: [Int]? let recentSearches: [String] } enum SearchFilter: Int { case movies, peoples } // MARK: - binding @State private var searchFilter: Int = SearchFilter.movies.rawValue @State private var searchTextWrapper = MoviesSearchTextWrapper() @State private var isSearching = false // MARK: - Public var let movies: [Int] let displaySearch: Bool var pageListener: MoviesPagesListener? var headerView: AnyView? // MARK: - Computed Props func map(state: AppState, dispatch: @escaping DispatchFunction) -> Props { if isSearching { return Props(searchedMovies: state.moviesState.search[searchTextWrapper.searchText], searchedKeywords: state.moviesState.searchKeywords[searchTextWrapper.searchText]?.prefix(5).map{ $0 }, searcherdPeoples: state.peoplesState.search[searchTextWrapper.searchText], recentSearches: state.moviesState.recentSearches.map{ $0 }) } return Props(searchedMovies: nil, searchedKeywords: nil, searcherdPeoples: nil, recentSearches: []) } // MARK: - Computed views private func moviesRows(props: Props) -> some View { ForEach(isSearching ? props.searchedMovies ?? [] : movies, id: \.self) { id in NavigationLink(destination: MovieDetail(movieId: id)) { MovieRow(movieId: id) } } } private func movieSection(props: Props) -> some View { Group { if isSearching { Section(header: Text("Sonuçlar: \(searchTextWrapper.searchText)")) { if isSearching && props.searchedMovies == nil { Text("Filmler aranıyor...") } else if isSearching && props.searchedMovies?.isEmpty == true { Text("Sonuç yok") } else { moviesRows(props: props) } } } else { Section { moviesRows(props: props) } } } } private func peoplesSection(props: Props) -> some View { Section { if isSearching && props.searcherdPeoples == nil { Text("Kişiler aranıyor...") } else if isSearching && props.searcherdPeoples?.isEmpty == true { Text("Sonuç yok") } else { ForEach(props.searcherdPeoples ?? [], id: \.self) { id in NavigationLink(destination: PeopleDetail(peopleId: id)) { PeopleRow(peopleId: id) } } } } } private func keywordsSection(props: Props) -> some View { Section(header: Text("Anahtar kelimeler")) { ForEach(props.searchedKeywords ?? []) {keyword in NavigationLink(destination: MovieKeywordList(keyword: keyword)) { Text(keyword.name) } } } } private var searchField: some View { SearchField(searchTextWrapper: searchTextWrapper, placeholder: "Film veya kişi arayın", isSearching: $isSearching) .onPreferenceChange(OffsetTopPreferenceKey.self) { _ in UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } } private var searchFilterView: some View { Picker(selection: $searchFilter, label: Text("")) { Text("Filmler").tag(SearchFilter.movies.rawValue) Text("Kişiler").tag(SearchFilter.peoples.rawValue) }.pickerStyle(SegmentedPickerStyle()) } // MARK: - Body func body(props: Props) -> some View { List { if displaySearch { Section { searchField } } if headerView != nil && !isSearching { Section { headerView! } } if isSearching { searchFilterView if props.searchedKeywords != nil && searchFilter == SearchFilter.movies.rawValue { keywordsSection(props: props) } } if isSearching && searchFilter == SearchFilter.peoples.rawValue { peoplesSection(props: props) } else { movieSection(props: props) } if !movies.isEmpty || props.searchedMovies?.isEmpty == false { Rectangle() .foregroundColor(.clear) .onAppear { if self.isSearching && props.searchedMovies?.isEmpty == false { self.searchTextWrapper.searchPageListener.currentPage += 1 } else if self.pageListener != nil && !self.isSearching && !self.movies.isEmpty { self.pageListener?.currentPage += 1 } } } } .listStyle(PlainListStyle()) .animation(.spring()) } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Português
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree