While working on my dev.to clone in Angular I came across the comments section which can be very tricky to render. As it has a tree like structure which can go infinitely.
├── comment
│ ├── comment ─── comment
│ │ └── comment
│ ├── comment
│ ├── comment ─── comment ─── comment
│ │ └── comment ─── comment ─── comment
│ └── comment
├── comments
│ ├── comment ─── comment
│ │ └── comment
│ └── comment
├──── comment
│ ├── comment
│ └── comment
└──── comments
We never know the actual structure of the comments. I looked closely at the structure and I saw its just like recursion the same component is calling the same component. So I tried that and it worked.
I passed the comments array to a component and it renders it with a ngFor after I call the same component pass to it its children and go about that again and again. You can
Next problem was CSS I wanted to add space before each comment when it goes to the next level but after 4 levels we need to stop adding spaces in comments other wise there will be no space for comments. Here we have one advantage aver the above problem we know the level after which we want to remove the CSS if we don't try to make it generic we can just do
.app-comments .app-comments .app-comments .app-comments {
padding-left: 0;
}
using specificity we can take advantage of us knowing the level at which to remove padding.
If we use any library managing state of such a structure can be a night mare. I used the native details html tag which comes with the toggling functionality in built and we need not manage any state this is the point where I realize how powerful these structures can be.
Working with the details tag was great but I needed the state of it closing and opening in the template. To show and hide some data whenever the state changes. To do that and not manage any state I thought of using template variables and @ViewChild
but failed miserably managing state at each level of an Array of dynamic length array was really hard which is changing its state I have to manage a tree like state for components to to mitigate this I thought lets completely keep the state in the template and I used the same template variable and use the native open property on details element to show and hide elements but nothing was happening. I really tried everything but the open property never changed in the template.
So I got to know that on open close of detail HTML element a toggle event is generated and zone.js has not monkey patched the toggle event. What a pain when you expect something to work in the frame work and it does not work and you need to have deep understanding of the frame to solve it and if if you have a good amount of knowledge you can't solve it. To resolve this I imported ChangeDetectorRef and detectChanges on when the toggle event happens.
]]>Github Repo -
Deployed on Firebase -
Last week we finished details page, article section and basic comments section.
This week I added the complete comments section. It was one the most complex tasks while building the dev.to ui. The comments structure is a bit complex to render. Comments contain a key called children which can again contain comments so it was like a tree like structure.
├── comment
│ ├── comment ─── comment
│ │ └── comment
│ ├── comment
│ ├── comment ─── comment ─── comment
│ │ └── comment ─── comment ─── comment
│ └── comment
├── comments
│ ├── comment ─── comment
│ │ └── comment
│ └── comment
├──── comment
│ ├── comment
│ └── comment
└──── comments
How to render an infinite tree. Then I called the comment component from the comment component. To create a recursion like scenario which will render the entire component tree. I've written details about it in this .
has also added
commit lint to the repo so that reading the commit messages is easy. I'm thankful for that.
I also did my first live stream with on moving over our app from angular-cli to NxDevTools we did the basics in the stream and I went over a lot of questions that I have to why Nx if you want to see how to move your project over Nx please follow us on
we will be migrating the whole dev.to clone to Nx over the live stream. This was my first talk I was a bit nervous but Santosh made me at ease. Thanks Santosh.
So this is where we are right now.
Next week I'll start working on the podcast page.
I now need to know how I'll market this. I'm very bad at marketing. So, I'll need all the help I can get. I am thinking of releasing it on product hunt and posting about it on communities. If you know any communities that help in building communities please let me knew in the comments down below.
My first service I never thought if I start I'll get this far but here I'm am so to anyone who is going t start something I'll say start today. You will reach far after you start. Don't go after perfection
]]>Github Repo -
Deployed on Firebase -
Last week we added details page but did not style the middle articles portion.
This week I added the article section CSS and added basic comments the comments section. Is on a different branch so will not deployed right now.
We have new contributors too who is building the videos detail page did a great job she has already completed it added infinite scroll and made everything responsive too she has already completed her work but there are some small changes after that her work would be merged. To have a look you can have a look at her and let me give you a sneak peek.
This week I had a lot of problems with the CSS because the article body was injected and I still could not do the code highlighting properly. It was really really tiring.
I also resolved other small bugs added GitHub action for deployment on main branch. Lets talk about the small bugs earlier the reactions section was static I added the reactions store so that they are dynamic but there is no reaction api provided by the dev.to/api it so lets see if this is going to be a problem as its structure can change anytime because of no support.
I also ran into the grid overflow problem mostly grid automatically takes the free space using fr units but some elements in it does not play well. I came to know about this . It was a tricky problem because I put an hour into fixing my inner code blocks but the problem was with the grid.
Adding the GitHub action was fun I have with CI/CD but only on Gitlab I didn't think it would be this different adding actions for other repos seems a weird concept to me but maybe it grows on me. Lets have a look at the GitHub action.
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
firebase-deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Setup node version which this action will run
- uses: actions/setup-node@master
with:
node-version: '14.x'
# Install node_modules as we don't push them
- run: npm install
# Build our angular app
- run: npm run build
# Firebase action to deploy. Still don't fully understand this concept
- uses: w9jds/firebase-action@master
# With what arguements will this action run
with:
args: deploy --only hosting --project dev-toclone
# Environment variables with which you want to run your job. To keep them a secret you can set in your repository secrets
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Let me give you the sneak peek of the newly created comments section too this is going to be hard as the way comments are but we are going to use recursion here to render out all the comments. That is going to interesting you will see a new pattern of rendering these types of structures.
- This branch contains the Homepage, Article-detail with comments, Listing page
- This branch contains the comments section of the article detail page
- This branch contains the videos section
I've started a new discussion weather we should move the project to Nx on main branch or keep it on angular-cli. Would love to hear everyone's opinion.
This time I won't add all the commits there are many I "ll highlight the most useful
Next time I'll finish the comments section. if anyone wants to contribute they can connect on twitter with me my handle is my DM's are open or on github.
]]>TutTable
as name and id
as the primary key. Click on create.Next we will study about some more databases available in AWS for various other use cases.
]]>A key-value database is a type of nonrelational database that uses a simple key-value method to store data. A key-value database stores data as a collection of key-value pairs in which a key serves as a unique identifier. Both keys and values can be anything, ranging from simple objects to complex compound objects. Key-value databases are highly partitionable and allow horizontal scaling at scales that other types of databases cannot achieve. For example, Amazon DynamoDB allocates additional partitions to a table if an existing partition fills to capacity and more storage space is required.
Millisecond latency is too slow for some mission critical apps. If you want performance improvement you can use Dax which use caching to improve performance many times. It is a fully managed in memory cache service for Dynamo DB.
]]>I'm starting a new challenge of building 2 products in 6 months. Earlier I always used to postpone building new products to find the perfect opportunity but now I think at least I should make myself ready when the perfect opportunities arrive or make the perfect opportunity myself. Taking ideas in my head to actual products will help a lot in it. I am afraid to start I have nothing to lose still I'm afraid I don't know of what. So, lets try this and see where this goes.
I'll post updates on Saturday and Sunday if anyone is interested. Holding my breath to see what comes of it.
]]>Github Repo -
Deployed on Firebase -
Last week we added basic details page.
This week I added user details and a reaction section in article details. There is no API for adding reactions to actual dev.to site so the reactions component is read-only for now.
This week I have good news did the listings page for us. I am really happy this is a first opensource contribution in my project. Thanks Chellapan
He implemented the masonry layout in this and next I'll write how he implemented the masonry layout.
Now back to my work this time added a global component store for user details in the article-details component. I also had a lot of problems with the layout of the page the layout was not working correctly whatever I set in the grid-template-columns but after putting a lot of time in it I realized its just that article details content is not working correctly either the image was bigger then the body or the code-snippets were. I was really tired of this, to solved this problem my mind told so what is not styled the details content. This made me realize that the problem should be there. Then I checked and then there it was so for now I made images with width 100% and its working fine for now. This is where we are now.
Next week I'll style article details and on the comments section.
As you can see a lot of content was added. Now we will soon dive into improving it more using Nx and Tailwind once we finish the basic application.
]]>So we have created our database we can use it now, we see how easy it was to setup a new DB in AWS if we would have done it on our own with backups, monitoring etc. It would have taken us a 1-2 days. Next we will study about Dynamo DB.
]]>You can setup your own Db on your on premises server or on your Ec2 instances but then you have to take care of backups, replication, scaling, availability, durability. Which is a lot of operational work added to your plate. If you mainly want to focus on developing your applications and don't want to worry about managing and handling your data bases then managed DB's by AWS are your best choice. These managed DB have a built in
Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It allows you to setup many relational DB with many different engines like Amazon Aurora, PostgreSQL, MySQL, MariaDB, Oracle Database, and SQL Server.
Using RDS has the following advantages over traditional Db
Aurora is a special proprietary DB by AWS and you can use Mysql or Postgres it combines the performance and availability of traditional enterprise databases with the simplicity and cost-effectiveness of open source databases. Amazon Aurora is up to five times faster than standard MySQL databases and three times faster than standard PostgreSQL databases. It auto-scales up to 128TB per database instance and delivers high performance and availability with continuous backup to Amazon S3.
Next we will do a Hands on setting up RDS on AWS cloud.
]]>Github Repo -
Deployed on Firebase -
Last week I completed the homepage.
This week I added article details page the styling is left so I added the basic skeleton of the article details page. This will also be divided into 3 sections the reaction section the articles section and the user section.
This week I focused on the article details section and joining the homepage articles to article details section. It was a bit tiresome this week. There were some problems like getting a specific article by path requires you to set the article username which I came to know that can be either username or organization name but if organization name exists it has to be organization name. There is no API to get featured article on homepage earlier I used the articles API and set the first one as featured article but that had a problem that the first article may not necessarily contain an image. The articles API also gave stale articles so I changed it with rising articles and took the first one that has an image. I think the timeline should be better if someone wants to use this as an app. Took a lot of my time yesterday but still there was progress so, I am happy.
Let us talk about the article section I've divided it into 3 parts the article details the comment section and the read next section I was only able to work on article detail section. I got article details using https://dev.to/api/articles/{username}/{slug}
the API and I the same pattern as before a store and and API service.
There is one good news is working on the listings section. The listings section will require masonry layout so maybe I can extract out some directives which makes making masonry layout easy for anyone to use. I'll be releasing articles on his work too after he completes. Here is where I am now.
2.
Tags color and background. Tags in API comes in an a separate array and the colors in a different array I need to mix and match them and it should be reusable because its used everywhere.
is working on the listings section. Waiting for it Chellapan 😁. If anyone want to contribute they can pick anything from the issues section in the repo.
]]>Github Repo -
Deployed on Firebase -
Last week I added article section dev.to clone.
This week we added the tags store and joined the tags to the api. We mostly follow a pattern to add an api service which makes all the api calls and a store service which sores al the data related to that service.
We also added listings using the same pattern. This is the first time we used *rxLet. It really makes working with all Observable in the templates easier do it out. It allows you four states for an observable suspense, error. complete so that you can handle each one of them separately and gets rid of the *ngIf with async pipe. Like if you want to display something else while loading and error is a big disadvantage of the async pipe when used with an api.
There was one interesting thing we did this time we created a reusable component which when passed a tag will show all the top articles from these tags in the last 3 days if you want to check out.
This is how it looks now
Next week we will start working on article details page.
The article tag store and article store are quite common can we make them one. Same for listings HTML and article-tag HTML. I'm not sure what to do about this.
has also offered some help. He will raise a detailed feature request on what he will work on Waiting for that.
If you want to contribute too. I've created a lot of issues. Anyone can work on issues but for feature requests you have to raise a detailed feature request before working on it.
also raised his first pr on the project. Thank you sunny.
]]>Github Repo -
Deployed on Firebase -
Last week I added Article store and sidebar in our dev.to clone.
This week I added the articles section. The articles section is divided into three parts the featured article ie the first article in your feed the rest of the articles section and the top header from where I select the time interval of our feed. Right now the feed is generic not based on any tags and user but I will do that later. Most of the time went in setting up the HTML, CSS for our articles section so I was not able to complete the tags store and the articles header section.
I did some interesting things which you may find interesting.
In normal articles card the font size of title is 24px and in the featured-article section it was 30px. So I thought I should add the title section via content projection but this had one problem that there is no way in Angular to give default content projection the is open for a long time but there is a work around you can define a ref on the template and check if has children then render the projected content or render the default content if it does not have any content projected. To see how I implemented it follow this .
So if you put some styles of your component in the :host selector it can be easily changed in other components too. Like the article card-component as some styles but with the featured card I need to change some styles of the card component. Most of the CSS I need to be changed is global so I put it in host of the article-card component and I was easily able to change the styles to see how I implemented this check this .
Which leads us here
CSS is getting out of hand I had to add a new class again and again every time even to add a small padding value. Its obvious that CSS is going to balloon soon and will get out of hand. So, see some CSS management techniques.
Content projection just to change the size of the title seems overkill. Should it be done via inputs.
Article section header is incomplete.
Let me know in the comments if you think something can be improved.
]]>Github Repo -
Deployed on Firebase -
Last week I created a header component. It was just HTML and it was in the following position.
.
This week I stated adding the body of the dev.to website I used a component to handle all the margins and padding on the body of the dev.to website. And created all body sub-elements as the the children of this Component in routing.
To start with body sub-components I created a home module I created a new module for homepage because people may open other pages before visit our home page so putting our homepage in a different module other than app.module made sense for lazy loading. If your has to be visited before visiting any other pages use home module in app module.
I divided home page into three parts sidebar, articles, extra-info. On careful examination of the dev.to sidebar I divided it into 4 components sidebar-primary, sidebar-social-links, sidebar-tags, sidebar-advertisement. The sidebar-primary will contain all the default options in the sidebar. sidebar-social-links contains all the social links that open in dev.to when clicked on more option in sidebar. Sidebar tags contains tags on dev.to and sidebar-advertisement contain the ad at the bottom of dev.to sidebar.
After building the Basic HTML structure of dev.to sidebar I moved onto the articles section. It is also divided into 3 component featured article, article list, header.
Here we start the use of the . This API is divided into 2 parts one which requires a key one which are open so first I will build everything possible to build with the open API and after that we will build a login where you have to put your key and the key will be stored in localStorage and we will run API requiring API token from there. The first question that should come to your mind is shouldn't that be done first. Later on it will require a lot of refactoring. My answer is I want to do refactoring basically in most test projects lot of refactoring is done so we will intentionally make some mistakes along the way to see how we handle refactoring and updating features. I think half of the work done in software is refactoring or updating old features.
We used the articles open API() to get the list of articles. We created an articles-api service which will fetch the data and a article-store service which uses component store for managing the state of the articles. We will use Michael Hadly push pipe as it is more performant and does not return null when used. I will go into details of async pipe and push pipe some other time.
After doing all this I reached at the following state.
Next week I will add the article section HTML, CSS and add a tag store, tags API for the tags section we created in the sidebar. If you want to know any details regarding anything comment below.
wanted to contribute to this project. Thanks Sunny for your proposal but I work on this on Thursday's only. I don't have much time to manage the project. I proposed if anyone wants to contribute add a feature request in the issues. I will comment I accept on it and then you can build the feature I won't build it but you will have to release an article on how you build that feature.
I'm starting a new series in which we will create a dev.to clone in angular. I will release some work every Thursday. I'm busy on all other days. I will use
Rest we will add stuff as needed and think about it in various scenario's as we go. I'll add stuff to github repo on Thursday and drop an article on what we did on Friday. Follow along if you want to learn more about Angular.
Github Repo -
Deployed on Firebase -
Right now we have created the header component and next we will create the side bar.
Each commit message will tell what we have done in that commit. Follow alone if you want to learn angular and let me know if any enhancements you think are needed create an issue on the repo if you want we can discuss there.
]]>