2020-01-02 23:59:02 +00:00
|
|
|
import { graphql } from '../api';
|
|
|
|
import { sitesFragment, releasesFragment } from '../fragments';
|
|
|
|
import { curateNetwork } from '../curate';
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2019-11-15 01:37:17 +00:00
|
|
|
function initNetworksActions(store, _router) {
|
2020-01-02 23:59:02 +00:00
|
|
|
async function fetchNetworkBySlug(networkSlug, limit = 100) {
|
|
|
|
const { network } = await graphql(`
|
|
|
|
query Network(
|
|
|
|
$networkSlug: String!
|
|
|
|
$limit:Int = 1000,
|
|
|
|
$after:Date = "1900-01-01",
|
|
|
|
$before:Date = "2100-01-01",
|
|
|
|
) {
|
|
|
|
network: networkBySlug(slug: $networkSlug) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
sites {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
${releasesFragment}
|
|
|
|
network {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
networkSlug,
|
|
|
|
limit,
|
|
|
|
after: store.getters.after,
|
|
|
|
before: store.getters.before,
|
2019-11-15 01:37:17 +00:00
|
|
|
});
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
return curateNetwork(network);
|
2019-11-10 03:20:22 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
async function fetchNetworks({ _commit }, networkSlug) {
|
|
|
|
if (networkSlug) {
|
|
|
|
return fetchNetworkBySlug(networkSlug);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { networks } = await graphql(`
|
|
|
|
query Networks {
|
|
|
|
networks {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
url
|
|
|
|
${sitesFragment}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
2019-11-10 03:20:22 +00:00
|
|
|
|
2020-01-02 23:59:02 +00:00
|
|
|
return networks.map(network => curateNetwork(network));
|
2019-11-10 03:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fetchNetworks,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initNetworksActions;
|