Commit 4260850c authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add support for amendementUpserted subscription.

parent 0c3b5650
......@@ -1219,60 +1219,7 @@
{
"name": "amendementUpserted",
"description": "",
"args": [
{
"name": "bibard",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "bibardSuffixe",
"description": "",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "legislature",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "organe",
"description": "",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
}
],
"args": [],
"type": {
"kind": "OBJECT",
"name": "Amendement",
......
......@@ -124,6 +124,27 @@ const prochainADiscuterFragment = gql`
type graphqlClient = ApolloClient.generatedApolloClient;
let createAmendementUpsertedSubscriptionQuery: unit => ApolloClient.queryObj = [%bs.raw
{|
function () {
return {
query: gql`
subscription onAmendementUpserted {
amendementUpserted {
...AmendementFragment
}
}
${amendementFragment}
${auteurFragment}
${cosignatairesMentionLibreFragment}
`,
variables: {
}
};
}
|}
];
let createGraphqlClient: (string, string) => graphqlClient = [%bs.raw
{|
function (httpUrl, wsUrl) {
......
......@@ -112,6 +112,9 @@ let amendement = (json: Js.Json.t) : amendement =>
sortEnSeance: json |> field("sortEnSeance", sortEnSeance)
};
let amendementUpsertedWrapper = (json: Js.Json.t) : amendement =>
Json.Decode.(json |> field("amendementUpserted", amendement));
let amendementWrapper = (json: Js.Json.t) : amendementWrapper =>
Json.Decode.{
alineaLabel: json |> field("alineaLabel", string),
......
......@@ -10,6 +10,7 @@ type page =
type action =
| CloseSnackbar
| GotAmendement(Js.Json.t)
| GotProchainADiscuter(Js.Json.t)
| Navigate(page, string)
| ScrollToHash(string);
......@@ -34,6 +35,16 @@ let make = (~discussion, ~graphqlClient, ~hash, ~path, _children) => {
...component,
initialState: () => {discussion, openSnackbar: false, page: pathToPage(path)},
subscriptions: self => [
Sub(
() =>
GraphqlSubscription.subscribe(
~graphqlClient,
~query=Apollo.createAmendementUpsertedSubscriptionQuery(),
~receiver=data =>
self.send(GotAmendement(data))
),
GraphqlSubscription.unsubscribe
),
Sub(
() =>
GraphqlSubscription.subscribe(
......@@ -52,6 +63,37 @@ let make = (~discussion, ~graphqlClient, ~hash, ~path, _children) => {
reducer: (action, state) =>
switch action {
| CloseSnackbar => ReasonReact.Update({...state, openSnackbar: false})
| GotAmendement(data) =>
/* Js.log2("GotAmendement", data); */
let discussion = state.discussion;
let amendement = Decoders.amendementUpsertedWrapper(data);
if (amendement.bibard == discussion.bibard
&& amendement.bibardSuffixe == discussion.bibardSuffixe
&& amendement.legislature == discussion.legislature
&& amendement.organeAbrv == discussion.organe) {
let amendementsWrappers =
discussion.amendements
|> Array.map((amendementWrapper: amendementWrapper) =>
if (amendementWrapper.numero == amendement.numeroReference) {
{
...amendementWrapper,
amendement: Some(amendement),
sort: amendement.sortEnSeance
};
} else {
amendementWrapper;
}
);
ReasonReact.Update({
...state,
discussion: {
...discussion,
amendements: amendementsWrappers
}
});
} else {
ReasonReact.NoUpdate;
};
| GotProchainADiscuter(data) =>
/* Js.log2("GotProchainADiscuter", data); */
let discussion = state.discussion;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment