|
@@ -7,9 +7,20 @@ import * as get from "./lib/getters";
|
|
import { domain, wsLocation } from "./config";
|
|
import { domain, wsLocation } from "./config";
|
|
import proposalPosts from "./proposalPosts";
|
|
import proposalPosts from "./proposalPosts";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
|
|
+//import moment from "moment";
|
|
|
|
|
|
// types
|
|
// types
|
|
-import { Api, Block, Handles, IState, Member } from "./types";
|
|
|
|
|
|
+import {
|
|
|
|
+ Api,
|
|
|
|
+ Block,
|
|
|
|
+ Handles,
|
|
|
|
+ IState,
|
|
|
|
+ Member,
|
|
|
|
+ Category,
|
|
|
|
+ Channel,
|
|
|
|
+ Post,
|
|
|
|
+ Thread,
|
|
|
|
+} from "./types";
|
|
import { types } from "@joystream/types";
|
|
import { types } from "@joystream/types";
|
|
import { Seat } from "@joystream/types/augment/all/types";
|
|
import { Seat } from "@joystream/types/augment/all/types";
|
|
import { ApiPromise, WsProvider } from "@polkadot/api";
|
|
import { ApiPromise, WsProvider } from "@polkadot/api";
|
|
@@ -62,6 +73,18 @@ class App extends React.Component<IProps, IState> {
|
|
this.setState({ councilElection });
|
|
this.setState({ councilElection });
|
|
let stageEndsAt: number = termEndsAt;
|
|
let stageEndsAt: number = termEndsAt;
|
|
|
|
|
|
|
|
+ let lastCategory = await get.currentCategoryId(api);
|
|
|
|
+ this.fetchCategories(api, lastCategory);
|
|
|
|
+
|
|
|
|
+ let lastChannel = await get.currentChannelId(api);
|
|
|
|
+ this.fetchChannels(api, lastChannel);
|
|
|
|
+
|
|
|
|
+ let lastPost = await get.currentPostId(api);
|
|
|
|
+ this.fetchPosts(api, lastPost);
|
|
|
|
+
|
|
|
|
+ let lastThread = await get.currentThreadId(api);
|
|
|
|
+ this.fetchThreads(api, lastThread);
|
|
|
|
+
|
|
api.rpc.chain.subscribeNewHeads(
|
|
api.rpc.chain.subscribeNewHeads(
|
|
async (header: Header): Promise<void> => {
|
|
async (header: Header): Promise<void> => {
|
|
// current block
|
|
// current block
|
|
@@ -79,6 +102,22 @@ class App extends React.Component<IProps, IState> {
|
|
this.setState({ proposalCount });
|
|
this.setState({ proposalCount });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const currentChannel = await get.currentChannelId(api);
|
|
|
|
+ if (currentChannel > lastChannel)
|
|
|
|
+ lastChannel = await this.fetchChannels(api, currentChannel);
|
|
|
|
+
|
|
|
|
+ const currentCategory = await get.currentCategoryId(api);
|
|
|
|
+ if (currentCategory > lastCategory)
|
|
|
|
+ lastCategory = await this.fetchCategories(api, currentCategory);
|
|
|
|
+
|
|
|
|
+ const currentPost = await get.currentPostId(api);
|
|
|
|
+ if (currentPost > lastPost)
|
|
|
|
+ lastPost = await this.fetchPosts(api, currentPost);
|
|
|
|
+
|
|
|
|
+ const currentThread = await get.currentThreadId(api);
|
|
|
|
+ if (currentThread > lastThread)
|
|
|
|
+ lastThread = await this.fetchThreads(api, currentThread);
|
|
|
|
+
|
|
const postCount = await api.query.proposalsDiscussion.postCount();
|
|
const postCount = await api.query.proposalsDiscussion.postCount();
|
|
this.setState({ proposalComments: Number(postCount) });
|
|
this.setState({ proposalComments: Number(postCount) });
|
|
|
|
|
|
@@ -112,6 +151,139 @@ class App extends React.Component<IProps, IState> {
|
|
this.save("tokenomics", data);
|
|
this.save("tokenomics", data);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async fetchChannels(api: Api, lastId: number) {
|
|
|
|
+ for (let id = lastId; id > 0; id--) {
|
|
|
|
+ if (this.state.channels.find((c) => c.id === id)) continue;
|
|
|
|
+ console.log(`fetching channel ${id}`);
|
|
|
|
+ const data = await api.query.contentWorkingGroup.channelById(id);
|
|
|
|
+
|
|
|
|
+ const handle = String(data.handle);
|
|
|
|
+ const title = String(data.title);
|
|
|
|
+ const description = String(data.description);
|
|
|
|
+ const avatar = String(data.avatar);
|
|
|
|
+ const banner = String(data.banner);
|
|
|
|
+ const content = String(data.content);
|
|
|
|
+ const ownerId = Number(data.owner);
|
|
|
|
+ const accountId = String(data.role_account);
|
|
|
|
+ const publicationStatus =
|
|
|
|
+ data.publication_status === "Public" ? true : false;
|
|
|
|
+ const curation = String(data.curation_status);
|
|
|
|
+ const createdAt = data.created;
|
|
|
|
+ const principal = Number(data.principal_id);
|
|
|
|
+
|
|
|
|
+ const channel: Channel = {
|
|
|
|
+ id,
|
|
|
|
+ handle,
|
|
|
|
+ title,
|
|
|
|
+ description,
|
|
|
|
+ avatar,
|
|
|
|
+ banner,
|
|
|
|
+ content,
|
|
|
|
+ ownerId,
|
|
|
|
+ accountId,
|
|
|
|
+ publicationStatus,
|
|
|
|
+ curation,
|
|
|
|
+ createdAt,
|
|
|
|
+ principal,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ //console.debug(data, channel);
|
|
|
|
+ const channels = this.state.channels.concat(channel);
|
|
|
|
+ this.save("channels", channels);
|
|
|
|
+ }
|
|
|
|
+ return lastId;
|
|
|
|
+ }
|
|
|
|
+ async fetchCategories(api: Api, lastId: number) {
|
|
|
|
+ for (let id = lastId; id > 0; id--) {
|
|
|
|
+ if (this.state.categories.find((c) => c.id === id)) continue;
|
|
|
|
+ console.debug(`fetching category ${id}`);
|
|
|
|
+ const data = await api.query.forum.categoryById(id);
|
|
|
|
+
|
|
|
|
+ const threadId = Number(data.thread_id);
|
|
|
|
+ const title = String(data.title);
|
|
|
|
+ const description = String(data.description);
|
|
|
|
+ const createdAt = Number(data.created_at.block);
|
|
|
|
+ const deleted = data.deleted;
|
|
|
|
+ const archived = data.archived;
|
|
|
|
+ const subcategories = Number(data.num_direct_subcategories);
|
|
|
|
+ const moderatedThreads = Number(data.num_direct_moderated_threads);
|
|
|
|
+ const unmoderatedThreads = Number(data.num_direct_unmoderated_threads);
|
|
|
|
+ const position = Number(data.position_in_parent_category);
|
|
|
|
+ const moderatorId = String(data.moderator_id);
|
|
|
|
+
|
|
|
|
+ const category: Category = {
|
|
|
|
+ id,
|
|
|
|
+ threadId,
|
|
|
|
+ title,
|
|
|
|
+ description,
|
|
|
|
+ createdAt,
|
|
|
|
+ deleted,
|
|
|
|
+ archived,
|
|
|
|
+ subcategories,
|
|
|
|
+ moderatedThreads,
|
|
|
|
+ unmoderatedThreads,
|
|
|
|
+ position,
|
|
|
|
+ moderatorId,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ //console.debug(data, category);
|
|
|
|
+ const categories = this.state.categories.concat(category);
|
|
|
|
+ this.save("categories", categories);
|
|
|
|
+ }
|
|
|
|
+ return lastId;
|
|
|
|
+ }
|
|
|
|
+ async fetchPosts(api: Api, lastId: number) {
|
|
|
|
+ for (let id = lastId; id > 0; id--) {
|
|
|
|
+ if (this.state.posts.find((p) => p.id === id)) continue;
|
|
|
|
+ console.debug(`fetching post ${id}`);
|
|
|
|
+ const data = await api.query.forum.postById(id);
|
|
|
|
+
|
|
|
|
+ const threadId = Number(data.thread_id);
|
|
|
|
+ const text = data.current_text;
|
|
|
|
+ //const moderation = data.moderation;
|
|
|
|
+ //const history = data.text_change_history;
|
|
|
|
+ //const createdAt = moment(data.created_at);
|
|
|
|
+ const createdAt = data.created_at;
|
|
|
|
+ const authorId = String(data.author_id);
|
|
|
|
+
|
|
|
|
+ const post: Post = { id, threadId, text, authorId, createdAt };
|
|
|
|
+
|
|
|
|
+ //console.debug(data, post);
|
|
|
|
+ const posts = this.state.posts.concat(post);
|
|
|
|
+ this.save("posts", posts);
|
|
|
|
+ }
|
|
|
|
+ return lastId;
|
|
|
|
+ }
|
|
|
|
+ async fetchThreads(api: Api, lastId: number) {
|
|
|
|
+ for (let id = lastId; id > 0; id--) {
|
|
|
|
+ if (this.state.threads.find((t) => t.id === id)) continue;
|
|
|
|
+ console.debug(`fetching thread ${id}`);
|
|
|
|
+ const data = await api.query.forum.threadById(id);
|
|
|
|
+
|
|
|
|
+ const title = String(data.title);
|
|
|
|
+ const categoryId = Number(data.category_id);
|
|
|
|
+ const nrInCategory = Number(data.nr_in_category);
|
|
|
|
+ const moderation = data.moderation;
|
|
|
|
+ const createdAt = String(data.created_at.block);
|
|
|
|
+ const authorId = String(data.author_id);
|
|
|
|
+
|
|
|
|
+ const thread: Thread = {
|
|
|
|
+ id,
|
|
|
|
+ title,
|
|
|
|
+ categoryId,
|
|
|
|
+ nrInCategory,
|
|
|
|
+ moderation,
|
|
|
|
+ createdAt,
|
|
|
|
+ authorId,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ //console.debug(data, thread);
|
|
|
|
+ const threads = this.state.threads.concat(thread);
|
|
|
|
+ this.save("threads", threads);
|
|
|
|
+ }
|
|
|
|
+ return lastId;
|
|
|
|
+ }
|
|
|
|
+
|
|
async fetchCouncils(api: Api, currentRound: number) {
|
|
async fetchCouncils(api: Api, currentRound: number) {
|
|
if (this.state.councils.length)
|
|
if (this.state.councils.length)
|
|
return this.state.councils.map((council) =>
|
|
return this.state.councils.map((council) =>
|
|
@@ -328,6 +500,18 @@ class App extends React.Component<IProps, IState> {
|
|
const proposals = this.load("proposals");
|
|
const proposals = this.load("proposals");
|
|
if (proposals) this.setState({ proposals });
|
|
if (proposals) this.setState({ proposals });
|
|
}
|
|
}
|
|
|
|
+ loadChannels() {
|
|
|
|
+ const channels = this.load("channels");
|
|
|
|
+ if (channels) this.setState({ channels });
|
|
|
|
+ }
|
|
|
|
+ loadCategories() {
|
|
|
|
+ const categories = this.load("categories");
|
|
|
|
+ if (categories) this.setState({ categories });
|
|
|
|
+ }
|
|
|
|
+ loadPosts() {
|
|
|
|
+ const posts = this.load("posts");
|
|
|
|
+ if (posts) this.setState({ posts });
|
|
|
|
+ }
|
|
loadThreads() {
|
|
loadThreads() {
|
|
const threads = this.load("threads");
|
|
const threads = this.load("threads");
|
|
if (threads) this.setState({ threads });
|
|
if (threads) this.setState({ threads });
|
|
@@ -368,7 +552,10 @@ class App extends React.Component<IProps, IState> {
|
|
console.log(`Loading data`);
|
|
console.log(`Loading data`);
|
|
await this.loadMembers();
|
|
await this.loadMembers();
|
|
await this.loadCouncils();
|
|
await this.loadCouncils();
|
|
|
|
+ await this.loadCategories();
|
|
|
|
+ await this.loadChannels();
|
|
await this.loadProposals();
|
|
await this.loadProposals();
|
|
|
|
+ await this.loadPosts();
|
|
await this.loadThreads();
|
|
await this.loadThreads();
|
|
await this.loadValidators();
|
|
await this.loadValidators();
|
|
await this.loadNominators();
|
|
await this.loadNominators();
|