-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathReputations.tsx
More file actions
103 lines (89 loc) · 2.41 KB
/
Reputations.tsx
File metadata and controls
103 lines (89 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import * as React from "react";
import { Observable } from "rxjs";
import { IReputationQueryOptions as FilterOptions } from "@daostack/arc.js";
import {
Arc as Protocol,
ArcConfig as ProtocolConfig,
InferredReputation as Component,
ReputationEntity as Entity,
ReputationData as Data,
CProps,
ComponentList,
ComponentListLogs,
ComponentListProps,
} from "../";
import { CreateContextFeed } from "../runtime/ContextFeed";
type RequiredProps = ComponentListProps<Entity, FilterOptions>;
interface InferredProps extends RequiredProps {
config: ProtocolConfig;
}
class InferredReputations extends ComponentList<InferredProps, Component> {
createObservableEntities(): Observable<Entity[]> {
const { config, filter } = this.props;
if (!config) {
throw Error(
"Arc Config Missing: Please provide this field as a prop, or use the inference component."
);
}
return Entity.search(config.connection, filter);
}
renderComponent(
entity: Entity,
children: any,
index: number
): React.ComponentElement<CProps<Component>, any> {
const { config } = this.props;
return (
<Component
key={`${entity.id}_${index}`}
address={entity.address}
config={config}
entity={entity}
>
{children}
</Component>
);
}
public static get Entities() {
return CreateContextFeed(
this.EntitiesContext.Consumer,
this.LogsContext.Consumer,
"Reputations"
);
}
public static get Logs() {
return CreateContextFeed(
this.LogsContext.Consumer,
this.LogsContext.Consumer,
"Reputations"
);
}
protected static EntitiesContext = React.createContext<Entity[] | undefined>(
undefined
);
protected static LogsContext = React.createContext<
ComponentListLogs | undefined
>(undefined);
}
class Reputations extends React.Component<RequiredProps> {
render() {
const { children, sort, filter } = this.props;
return (
<Protocol.Config>
{(config: ProtocolConfig) => (
<InferredReputations config={config} sort={sort} filter={filter}>
{children}
</InferredReputations>
)}
</Protocol.Config>
);
}
public static get Entities() {
return InferredReputations.Entities;
}
public static get Logs() {
return InferredReputations.Logs;
}
}
export default Reputations;
export { Reputations, InferredReputations };