@vendasta/codex v2.0.0
codex SDK
The Codex deals with two main concepts: Questions and Answers. There are two services for dealing with these concepts, the ListQuestionsService and the QuestionService.
QuestionService
This one is straight forward, just inject an instance and use it as needed. It has the following capabilities:
getQuestion
- get a question by its idgetComments
- return a list of comments for a question idcommentOnQuestion
- make a comment on a questioncreateQuestion
- create a question in the Codex and get its id back for future use.markCommentAsAnswer
- mark a comment on a question as the answer to itmarkCommentAsStale
- mark a comment on a question as "stale", this will also unmark it as the answer.deleteQuestion
- delete a question by its id
ListQuestionsService
When you are dealing with listing and loading multiple questions at once, it's time for the ListQuestionsService. It exposes some observables that your component can mirror:
questions$
- the list of questions that has been retrieved over the life of the service, i.e. this will update if you load more questionshasMore$
- an observable boolean that will let you know if there are still more resultsnextCursor$
- an observable string that you can use to load more questionsloading$
- an observable boolean that should indicate whether an api request is currently being made.totalResults$
- an observable int that has the total results of the list api
Using this service might look something like this. Here's an example component using this service:
import { ListQuestionsService } from './lib/';
class MyComponent {
loading$ = this.listQuestions.loading$;
questions$ = this.listQuestions.questions$;
hasMore$ = this.listQuestions.hasMore$;
nextCursor$ = this.listQuestions.nextCursor$;
totalResults$ = this.listQuestions.totalResults$;
constructor(private listQuestions: ListQuestionsService) {}
ngOnInit() {
// Set a custom page size first.
this.listQuestions.pageSize = 20;
this.listQuestions.loadQuestions();
}
}
That's it. You'll be able to show a Load More type of button or do infinite scroll, whichever you prefer. The easiest
way to get the cursor to the loadMoreQuestions
function is to subscribe to it in your component and pass it on each
click of the load more button or what have you. You can specify the size of each page by setting that on the service,
like in the example above.