Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/incremental community fields #643

Merged
merged 17 commits into from
Sep 29, 2021

Conversation

henriquecbuss
Copy link
Member

@henriquecbuss henriquecbuss commented Sep 24, 2021

What issue does this PR close

Closes #640

Changes Proposed ( a list of new changes introduced by this PR)

  • Adicionada nova variedade de BroadcastMsg: CommunityFieldLoaded
  • Alguns campos da comunidade, como uploads e objectives não são mais carregados junto com a comunidade. Podemos usar a BroadcastMsg acima para pedir ao LoggedIn fazer uma query e pegar esses campos

Lista de todos os campos afetados:

  • Objectives
  • Uploads

Esse PR estabelece uma boa estrutura para termos mais campos que podem ser carregados separados da comunidade. Para adicionar um novo campo nesse estilo:

  1. Adicionar o campo em Community.Model com um tipo de RemoteData (Graphql.Http.Error field) field
  2. Adicionar um novo construtor ao tipo Field. O nome deve ser composto do nome do campo seguido por Field (e.g. ObjectivesField)
  3. Adicionar um novo construtor ao tipo FieldValue. O nome deve ser composto do nome do campo seguido por Value, e possuir o valor do campo (e.g. ObjectivesValue (List Objective))
  4. Preencher as funções que lidam com esses tipos (setFieldValue, setFieldAsLoading, isFieldLoading e maybeFieldValue)

Páginas podem solicitar o campo usando as mensagens LoggedIn.External:

  • RequestedCommunityField Community.Field recebe um Community.Field, e verifica se a selectedCommunity de loggedIn já possui o campo. Se sim, manda o valor por uma BroadcastMsg. Se não, executa uma query para buscar o campo e envia uma BroadcastMsg quando receber o resultado.
  • RequestedReloadCommunityField é similar à mensagem acima, mas sempre executa a query para buscar o campo. Útil para forçar o reload de algum campo.

Para receber o campo, devem usar um receiveBroadcast, fazendo pattern match em LoggedIn.CommunityFieldLoaded e o campo desejado (e.g. LoggedIn.CommunityFieldLoaded community (Community.Objectives objectives)). O objeto community é repassado para evitar estados impossíveis, onde o campo está carregado, mas a comunidade não.

How to test ( a list of instructions on how to test this PR)

  • Navegue pelo app nas páginas onde os dados acima precisam ser mostrados
  • Verifique se o funcionamento do app nessas páginas permanece normal

@henriquecbuss henriquecbuss marked this pull request as ready for review September 28, 2021 19:43
src/elm/Community.elm Outdated Show resolved Hide resolved
src/elm/Community.elm Show resolved Hide resolved
Copy link
Member

@lucca65 lucca65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐎

src/elm/Community.elm Show resolved Hide resolved
)
community.objectives
|> List.head
List.find (.id >> (==) model.objectiveId) objectives
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took a minute to got what was going there >> operator is weird

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a good way 👽

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, point-free can be confusing sometimes.

In this case I kind of like how it reads if you just ignore all the punctuation:
find [something where] id == model.objectiveId

@henriquecbuss henriquecbuss merged commit 7bc58e0 into master Sep 29, 2021
@henriquecbuss henriquecbuss deleted the enhancement/incremental-community-fields branch September 29, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load community fields incrementally
2 participants