Skip to content

Always showing the same post items #9

Open
@anoels

Description

@anoels

Hello,

I don't know where I am doing wrong at. The problem is that there is a timeline, showing all posts from users a user following, and a profile view, which needs to show only the current user's post. But it also shows the posts of the following users.

Should I make a separate reducer as well as action and state? The following is my current reducer.

enum PostsReducer {
    static var reducer: Reducer<PostsState> {
        return { action, state in
 
            guard let action = action as? PostsAction else {
                return state ?? PostsState()
            }
            var newState = state
            
            switch action {
            case let .updatePosts(userID, posts):
                newState?.userPosts[userID] = posts
                return newState!
            case let .updateListener(userID, listener):
                newState?.postsListeners?[userID] = listener
                return newState!
            case let .updateUserPosts(posts):
                newState?.posts = posts
                return newState!
            case let .updateUserListener(listener):
                newState?.userPostsListener = listener
                return newState!
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions