Here's how I solved my focus problem-
1. Have a clear work/rest-of-life boundary. Have a clear set of hours or days of week where you work or learn things related to work. End your work on that boundary. Follow with a small end-of-work ritual. Spend time with hobbies, family, friends, etc. And set time aside vigilantly. When you know that you have to end working, you stop diverting your attention, and try to get stuff done as quickly as possible. When the boundary is blurry or non-existent, you can always do work "later". You can slack for little while "now".
2. Timebox. Have clearly defined boxes of thirty minutes blocks for definite tasks. Hell or high water, do not do anything else in the assigned time.
3. Time track. Just write down in a plain-text file or paper- what you did last. Note the times- both start and end. Whenever you are about to lose focus- you are reminded instantly that you have to log the time.
4. Plan concretely beforehand. Make up your mind about what you are going to do- and how much- before you begin doing something. Write it down. This pushes you towards doing that.
Aside from this techniques, as a general change-agent in your life, you should start meditating. Just read "Mindfulness in Plain English" by Bhante Gunaratana and/or "The Mind Illuminated" by Culadasa. This has immensely benefited my life- much beyond alleviating my focus problem.
I have personally seen minimizing social media usage to 15-20 minutes has helped me focus much more easily. I use social media just 15-20 minutes per day, and only in a particular time.
Even if I wait at a store or ride the elevator, I rather stare at the wall than pull up my phone.
I recommend two books and a podcast-
* Deep Work by Cal Newport
* Pragmatic Thinking and Learning by Andy Hunt
* Huberman Lab Podcast