Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/JS-4632: Multiplayer survey #739

Merged
merged 6 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/json/survey.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"0": {
"register": {
"url": "https://community.anytype.io/survey0"
},

"1": {
"delete": {
"url": "https://community.anytype.io/survey1"
},

"2": {
"pmf": {
"url": "https://community.anytype.io/survey2#anytypeid=%s"
},

"3": {
"object": {
"url": "https://community.anytype.io/survey3"
},

"shared": {
"url": "https://community.anytype.io/survey4"
}
}
6 changes: 5 additions & 1 deletion src/json/text.json
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@
"edgeType1": "Relation",

"survey0Title": "Time to take a survey!",
"survey0Text": "Hi there, We hope you're enjoying your experience in Anytype! We'd love to hear your feedback so we can keep improving the product.",
"survey0Text": "Hi there! We hope you're enjoying your experience in Anytype! We'd love to hear your feedback so we can keep improving the product.",
"survey0Confirm": "Let's Go!",
"survey0Cancel": "Skip",
"survey1Title": "Help us to become better",
Expand All @@ -1654,6 +1654,10 @@
"survey3Text": "Hi there, we hope you're enjoying your experience with Anytype! Would you take 5 minutes to help us improve our product?",
"survey3Confirm": "Sure, let's go",
"survey3Cancel": "No thanks",
"survey4Title": "Hi there!",
"survey4Text": "We’d love if you’d help us improve Anytype by taking part in this 3-minute survey.",
"survey4Confirm": "Let’s Go!",
"survey4Cancel": "No thanks",

"widget0Name": "Link",
"widget0Description": "Compact version of the Object",
Expand Down
19 changes: 10 additions & 9 deletions src/ts/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,19 @@ export interface ButtonComponent {
};

export enum SurveyType {
Register = 0,
Delete = 1,
Pmf = 2,
Object = 3,
Register = 0,
Delete = 1,
Pmf = 2,
Object = 3,
Shared = 4,
};

export enum SliceOperation {
None = 0,
Add = 1,
Move = 2,
Remove = 3,
Replace = 4,
None = 0,
Add = 1,
Move = 2,
Remove = 3,
Replace = 4,
};

export interface Dataset {
Expand Down
66 changes: 47 additions & 19 deletions src/ts/lib/survey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { I, Storage, UtilCommon, analytics, Renderer, translate, UtilObject, UtilSpace, UtilData, UtilDate } from 'Lib';
import { popupStore, authStore } from 'Store';

const Surveys = require('json/survey.json');

class Survey {
Expand All @@ -8,7 +9,7 @@ class Survey {
const fn = `check${I.SurveyType[type]}`;

if (this[fn]) {
this[fn]();
this[fn](type);
};
};

Expand All @@ -33,7 +34,8 @@ class Survey {

onConfirm (type: I.SurveyType) {
const { account } = authStore;
const survey = Surveys[type];
const t = I.SurveyType[type].toLowerCase();
const survey = Surveys[t];
const param: any = {};

switch (type) {
Expand Down Expand Up @@ -78,9 +80,9 @@ class Survey {
return Number(profile?.createdDate) || 0;
};

checkPmf () {
checkPmf (type: I.SurveyType) {
const time = UtilDate.now();
const obj = Storage.getSurvey(I.SurveyType.Pmf);
const obj = Storage.getSurvey(type);
const timeRegister = this.getTimeRegister();
const lastCompleted = Number(obj.time || Storage.get('lastSurveyTime')) || 0;
const lastCanceled = Number(obj.time || Storage.get('lastSurveyCanceled')) || 0;
Expand All @@ -90,41 +92,39 @@ class Survey {
const registerTime = timeRegister <= time - week;
const completeTime = obj.complete && registerTime && (lastCompleted <= time - month);
const cancelTime = obj.cancel && registerTime && (lastCanceled <= time - month);
const randSeed = 10000000;
const rand = UtilCommon.rand(0, randSeed);

// Show this survey to 5% of users
if ((rand > randSeed * 0.05) && !completeTime) {
Storage.setSurvey(I.SurveyType.Pmf, { time });
if (this.checkRandSeed(5) && !completeTime) {
Storage.setSurvey(type, { time });
return;
};

if (!popupStore.isOpen() && (cancelTime || !lastCompleted) && !completeTime) {
this.show(I.SurveyType.Pmf);
this.show(type);
};
};

checkRegister () {
checkRegister (type: I.SurveyType) {
const timeRegister = this.getTimeRegister();
const isComplete = this.isComplete(I.SurveyType.Register);
const isComplete = this.isComplete(type);
const surveyTime = timeRegister && ((UtilDate.now() - 86400 * 7 - timeRegister) > 0);

if (!isComplete && surveyTime && !popupStore.isOpen()) {
this.show(I.SurveyType.Register);
this.show(type);
};
};

checkDelete () {
const isComplete = this.isComplete(I.SurveyType.Delete);
checkDelete (type: I.SurveyType) {
const isComplete = this.isComplete(type);

if (!isComplete) {
this.show(I.SurveyType.Delete);
this.show(type);
};
};

checkObject () {
checkObject (type: I.SurveyType) {
const timeRegister = this.getTimeRegister();
const isComplete = this.isComplete(I.SurveyType.Object);
const isComplete = this.isComplete(type);

if (isComplete || !timeRegister) {
return;
Expand All @@ -138,11 +138,39 @@ class Survey {
limit: 50,
}, (message: any) => {
if (!message.error.code && (message.records.length >= 50)) {
this.show(I.SurveyType.Object);
this.show(type);
};
});
};

}
checkShared (type: I.SurveyType) {
const isComplete = this.isComplete(type);
if (isComplete) {
return;
};

const { account } = authStore;
const check = UtilSpace.getList().filter(it => it.isShared && (it.creator == UtilSpace.getParticipantId(it.targetSpaceId, account.id)));
if (!check.length) {
return;
};

// Show this survey to 10% of users
if (!this.checkRandSeed(10)) {
Storage.setSurvey(type, { complete: true });
return;
};

this.show(type);
};

checkRandSeed (percent: number) {
const randSeed = 10000000;
const rand = UtilCommon.rand(0, randSeed);

return rand < randSeed * percent / 100;
};

};

export default new Survey();
3 changes: 1 addition & 2 deletions src/ts/lib/util/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ class UtilData {
Storage.set('bgColor', 'orange');
};

Survey.check(I.SurveyType.Register);
Survey.check(I.SurveyType.Object);
[ I.SurveyType.Register, I.SurveyType.Object, I.SurveyType.Shared ].forEach(it => Survey.check(it));

const space = UtilSpace.getSpaceview();

Expand Down
Loading