@sprucelabs/spruce-feed-view-controllers 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/esm/index-module.d.ts +2 -0
- package/build/esm/index-module.js +2 -0
- package/build/esm/types-module.d.ts +10 -0
- package/build/esm/types-module.js +1 -0
- package/build/esm/types.d.ts +4 -0
- package/build/esm/types.js +1 -0
- package/build/esm/viewControllers/FeedCard.vc.d.ts +19 -0
- package/build/esm/viewControllers/FeedCard.vc.js +81 -0
- package/build/index-module.d.ts +2 -0
- package/build/index-module.js +23 -0
- package/build/types-module.d.ts +10 -0
- package/build/types-module.js +2 -0
- package/build/types.d.ts +4 -0
- package/build/types.js +2 -0
- package/build/viewControllers/FeedCard.vc.d.ts +19 -0
- package/build/viewControllers/FeedCard.vc.js +69 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FeedCardViewController } from "./index-module";
|
|
2
|
+
import { FeedCardViewControllerOptions } from "./viewControllers/FeedCard.vc";
|
|
3
|
+
declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
|
|
4
|
+
interface ViewControllerMap {
|
|
5
|
+
feedCard: FeedCardViewController;
|
|
6
|
+
}
|
|
7
|
+
interface ViewControllerOptionsMap {
|
|
8
|
+
feedCard: FeedCardViewControllerOptions;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
2
|
+
export declare type FeedPredicate = SpruceSchemas.Mercury.v2020_12_25.FeedPredicate;
|
|
3
|
+
export declare type FeedItem = SpruceSchemas.Spruce.v2020_07_22.FeedItem;
|
|
4
|
+
export declare type Feed = SpruceSchemas.Spruce.v2020_07_22.Feed;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractViewController, CardViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { FeedPredicate } from '../types';
|
|
3
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
+
export declare type FeedCardViewControllerOptions = ViewControllerOptions & {
|
|
5
|
+
id?: string;
|
|
6
|
+
};
|
|
7
|
+
export default class FeedCardViewController extends AbstractViewController<Card> {
|
|
8
|
+
static id: string;
|
|
9
|
+
private isLoaded;
|
|
10
|
+
protected cardVc: CardViewController;
|
|
11
|
+
private predicates;
|
|
12
|
+
constructor(options: FeedCardViewControllerOptions);
|
|
13
|
+
getIsLoaded(): boolean;
|
|
14
|
+
load(predicates: FeedPredicate[]): Promise<void>;
|
|
15
|
+
private refresh;
|
|
16
|
+
private handleTryAgain;
|
|
17
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
|
+
import { assertOptions } from '@sprucelabs/schema';
|
|
12
|
+
export default class FeedCardViewController extends AbstractViewController {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options);
|
|
15
|
+
this.isLoaded = false;
|
|
16
|
+
this.predicates = [];
|
|
17
|
+
this.cardVc = this.Controller('card', {
|
|
18
|
+
id: options.id,
|
|
19
|
+
body: {
|
|
20
|
+
isBusy: true,
|
|
21
|
+
sections: [
|
|
22
|
+
{
|
|
23
|
+
feed: {
|
|
24
|
+
items: [],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getIsLoaded() {
|
|
32
|
+
return this.isLoaded;
|
|
33
|
+
}
|
|
34
|
+
load(predicates) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
assertOptions({ predicates }, ['predicates'], `You have to pass the search predicates to load the feed. They are in the form of { source: {...}, target: {...} }[]. If you wanna find anything to AND from a person, you gotta pass personId to both source AND target.`);
|
|
37
|
+
this.predicates = predicates;
|
|
38
|
+
yield this.refresh();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
refresh() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const client = yield this.connectToApi();
|
|
44
|
+
try {
|
|
45
|
+
const [{ feed }] = yield client.emitAndFlattenResponses('get-feed::v2020_12_25', {
|
|
46
|
+
payload: {
|
|
47
|
+
predicates: this.predicates,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
this.cardVc.setSection(0, {
|
|
51
|
+
feed: Object.assign(Object.assign({}, feed), { shouldEnableChat: true }),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
console.error(err.stack || err.message);
|
|
56
|
+
this.cardVc.setCriticalError({
|
|
57
|
+
title: 'Feed error!',
|
|
58
|
+
message: err.message,
|
|
59
|
+
buttons: [
|
|
60
|
+
{
|
|
61
|
+
label: 'Try again',
|
|
62
|
+
onClick: this.handleTryAgain.bind(this),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
this.isLoaded = true;
|
|
68
|
+
this.cardVc.setIsBusy(false);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
handleTryAgain() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
this.cardVc.clearCriticalError();
|
|
74
|
+
yield this.refresh();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
render() {
|
|
78
|
+
return this.cardVc.render();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
FeedCardViewController.id = 'feed-card';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.FeedCardViewController = void 0;
|
|
21
|
+
var FeedCard_vc_1 = require("./viewControllers/FeedCard.vc");
|
|
22
|
+
Object.defineProperty(exports, "FeedCardViewController", { enumerable: true, get: function () { return __importDefault(FeedCard_vc_1).default; } });
|
|
23
|
+
__exportStar(require("./types-module"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FeedCardViewController } from "./index-module";
|
|
2
|
+
import { FeedCardViewControllerOptions } from "./viewControllers/FeedCard.vc";
|
|
3
|
+
declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
|
|
4
|
+
interface ViewControllerMap {
|
|
5
|
+
feedCard: FeedCardViewController;
|
|
6
|
+
}
|
|
7
|
+
interface ViewControllerOptionsMap {
|
|
8
|
+
feedCard: FeedCardViewControllerOptions;
|
|
9
|
+
}
|
|
10
|
+
}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
2
|
+
export declare type FeedPredicate = SpruceSchemas.Mercury.v2020_12_25.FeedPredicate;
|
|
3
|
+
export declare type FeedItem = SpruceSchemas.Spruce.v2020_07_22.FeedItem;
|
|
4
|
+
export declare type Feed = SpruceSchemas.Spruce.v2020_07_22.Feed;
|
package/build/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractViewController, CardViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { FeedPredicate } from '../types';
|
|
3
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
+
export declare type FeedCardViewControllerOptions = ViewControllerOptions & {
|
|
5
|
+
id?: string;
|
|
6
|
+
};
|
|
7
|
+
export default class FeedCardViewController extends AbstractViewController<Card> {
|
|
8
|
+
static id: string;
|
|
9
|
+
private isLoaded;
|
|
10
|
+
protected cardVc: CardViewController;
|
|
11
|
+
private predicates;
|
|
12
|
+
constructor(options: FeedCardViewControllerOptions);
|
|
13
|
+
getIsLoaded(): boolean;
|
|
14
|
+
load(predicates: FeedPredicate[]): Promise<void>;
|
|
15
|
+
private refresh;
|
|
16
|
+
private handleTryAgain;
|
|
17
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
5
|
+
class FeedCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.isLoaded = false;
|
|
9
|
+
this.predicates = [];
|
|
10
|
+
this.cardVc = this.Controller('card', {
|
|
11
|
+
id: options.id,
|
|
12
|
+
body: {
|
|
13
|
+
isBusy: true,
|
|
14
|
+
sections: [
|
|
15
|
+
{
|
|
16
|
+
feed: {
|
|
17
|
+
items: [],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
getIsLoaded() {
|
|
25
|
+
return this.isLoaded;
|
|
26
|
+
}
|
|
27
|
+
async load(predicates) {
|
|
28
|
+
(0, schema_1.assertOptions)({ predicates }, ['predicates'], `You have to pass the search predicates to load the feed. They are in the form of { source: {...}, target: {...} }[]. If you wanna find anything to AND from a person, you gotta pass personId to both source AND target.`);
|
|
29
|
+
this.predicates = predicates;
|
|
30
|
+
await this.refresh();
|
|
31
|
+
}
|
|
32
|
+
async refresh() {
|
|
33
|
+
const client = await this.connectToApi();
|
|
34
|
+
try {
|
|
35
|
+
const [{ feed }] = await client.emitAndFlattenResponses('get-feed::v2020_12_25', {
|
|
36
|
+
payload: {
|
|
37
|
+
predicates: this.predicates,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
this.cardVc.setSection(0, {
|
|
41
|
+
feed: Object.assign(Object.assign({}, feed), { shouldEnableChat: true }),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
console.error(err.stack || err.message);
|
|
46
|
+
this.cardVc.setCriticalError({
|
|
47
|
+
title: 'Feed error!',
|
|
48
|
+
message: err.message,
|
|
49
|
+
buttons: [
|
|
50
|
+
{
|
|
51
|
+
label: 'Try again',
|
|
52
|
+
onClick: this.handleTryAgain.bind(this),
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.isLoaded = true;
|
|
58
|
+
this.cardVc.setIsBusy(false);
|
|
59
|
+
}
|
|
60
|
+
async handleTryAgain() {
|
|
61
|
+
this.cardVc.clearCriticalError();
|
|
62
|
+
await this.refresh();
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
return this.cardVc.render();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.default = FeedCardViewController;
|
|
69
|
+
FeedCardViewController.id = 'feed-card';
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sprucelabs/spruce-feed-view-controllers",
|
|
3
|
+
"description": "Spruce feed view controllers",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"skill": {
|
|
6
|
+
"namespace": "feed"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/sprucelabsai/spruce-feed-skill",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/sprucelabsai/spruce-feed-skill/issues"
|
|
11
|
+
},
|
|
12
|
+
"main": "./build/index-module.js",
|
|
13
|
+
"types": "./build/index-module.d.ts",
|
|
14
|
+
"module": "./build/esm/index-module.js",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"build/index-module.js",
|
|
18
|
+
"build/index-module.d.ts",
|
|
19
|
+
"build/viewControllers/FeedCard.vc.js",
|
|
20
|
+
"build/viewControllers/FeedCard.vc.d.ts",
|
|
21
|
+
"build/esm/index-module.js",
|
|
22
|
+
"build/esm/index-module.d.ts",
|
|
23
|
+
"build/esm/viewControllers/FeedCard.vc.js",
|
|
24
|
+
"build/esm/viewControllers/FeedCard.vc.d.ts",
|
|
25
|
+
"build/types-module.js",
|
|
26
|
+
"build/types-module.d.ts",
|
|
27
|
+
"build/esm/types-module.js",
|
|
28
|
+
"build/esm/types-module.d.ts",
|
|
29
|
+
"build/types.js",
|
|
30
|
+
"build/types.d.ts",
|
|
31
|
+
"build/esm/types.js",
|
|
32
|
+
"build/esm/types.d.ts"
|
|
33
|
+
],
|
|
34
|
+
"keywords": [],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"release": "npm publish"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@sprucelabs/heartwood-view-controllers": "latest"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": "16.x",
|
|
43
|
+
"yarn": "1.x"
|
|
44
|
+
}
|
|
45
|
+
}
|