Okay, so, I went in different direction from trying to use the portfolio plugins. Not sure whether I should post this here or in a new thread - if so please let me know!
Is someone able take a look at this and tell me what I am doing wrong (and hopefully why / how to fix it)? I’ve spent hours upon hours reading tutorials, writing and making edits to this, but I am very much a beginner and I have come to a point where I’m not sure about what to try next.
The goal: display a list of topics from a specific category on a user’s summary page.
In this use case, it is for an RPG forum where users will create characters to post stories with. I want this plugin to show what characters a user has created so nobody has to dig too far for them. All of the character sheets will be stored in the same forum. So, I figure I just have to create a topic list that gets topics from the correct user and the correct forum.
I have been using the following as reference:
Here is my attempt. So far, the topic list header (topic/replies/activity) is showing up in the correct place, but it’s not populating with topics.
<script type="text/discourse-plugin" version="0.8">
const ajax = require('discourse/lib/ajax').ajax;
const Topic = require('discourse/models/topic').default;
const User = require('discourse/models/user').default;
// Need ajax, Topic, and User
api.registerConnectorClass('above-user-summary-stats', 'character-list', {
// above-user-summary-stats is the plugin outlet, character-list is custom component name
setupComponents(args, component) {
const store = getOwner(this).lookup("service:store");
return ajax(userPath(`/topics/created-by/${this.username_lower}.json`)).then(function (result) {
// lines taken from summary() in user.js model; trying to find the username of the user profile we are viewing so we can access the json of the topics they have created
let characterList = [];
// empty array to push topics into
result.topic_list.topics.forEach.category_id(4)(function(topic){
// topics only from the specific category we want
// around here kris's tutorial had some lines to associate users with the topic. I ignored it because I don't need users aside from the original poster to be displayed with the topic. Is this important?
//topic.posters.forEach(function(poster){
//poster.user = $.grep(featuredUsers, function(e){ return e.id == poster.user_id; })[0];
//});
characterList.push(Topic.create(topic));
// add topics to the topic list
});
component.set('characterList', characterList);
// Set up our component with the topics from the array
}); // end ajax
} // end setupComponents
});
</script>
<script type="text/x-handlebars" data-template-name="/connectors/above-user-summary-stats/character-list">
<div class="custom-character-list-wrapper">
{{topic-list topics=characterList showPosters=false}}
</div>
</script>