<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thomas Step on Medium]]></title>
        <description><![CDATA[Stories by Thomas Step on Medium]]></description>
        <link>https://medium.com/@thomasstep?source=rss-8d6f2871c893------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qN5fDX8nCcWbUMneSg9xuw.jpeg</url>
            <title>Stories by Thomas Step on Medium</title>
            <link>https://medium.com/@thomasstep?source=rss-8d6f2871c893------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:03:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thomasstep/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Google OAuth Verification Experience]]></title>
            <link>https://thomasstep.medium.com/google-oauth-verification-experience-47f65f023764?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/47f65f023764</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[entrepreneurship]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 00:00:29 GMT</pubDate>
            <atom:updated>2024-02-02T13:31:39.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U0SSWtxZwBNOpxac" /><figcaption>Photo by <a href="https://unsplash.com/@alexdudar?utm_source=medium&amp;utm_medium=referral">Alex Dudar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I wanted to take some time to document my Google OAuth consent screen verification process. There were a couple of times throughout the 3 months I worked on getting my OAuth application verified that I tried to look online for others’ journeys and I found very few. None of the blogs that I found said that the process was quick and painless, and I would like to add my voice to that group. I still have the email chain which started on August 25th and ended on November 14. The process took me almost 3 full months to complete.</p><p>I want to say from the start that this is Google’s product and I support them putting whatever restrictions in place that they want. All I am saying is that the process felt long and dragged out with unclear feedback in the emails. But gaining access to their product is obviously something worth the time investment. I think having a library of examples, completed assets, and/or screenshots of passing applications would have been very helpful compared to my needing to read through legal-sounding documents about branding and privacy policies.</p><p>The problems that I had varied and I wanted to list a few of them out so that anyone in a similar position to me can hopefully gain some insight into what they need to adjust in their application.</p><p>In the first feedback email, I had issues with my privacy policy, branding, and demo video. I needed to make my privacy policy more easily accessible and add the standard “Google Limited Use Disclosure” clause to my privacy policy. Easy enough. I also had inconsistent branding with my project because the project’s name in the Google Cloud console was different from the application I was trying to authorize. I ended up changing the project’s name in the Google Cloud console. Then came the validation of app functionality. Whenever I took my original demo video, my popup window was not large enough for the reviewers to see the full URL. They are specifically looking to see the client ID. I retook the video, and whenever the popup showed up, I spent time highlighting/scrolling through the full URL slowly. Finally, I sent my confirmation email that I had worked on the problems.</p><p>The second feedback email was a smaller list thankfully. I still had privacy policy issues because my privacy policy wasn’t clearly located on my app’s homepage (I forgot to scroll down in my demo video showing it). I took a screenshot of the added link in the app’s footer to send back with my reply email. I was also flagged still for branding issues, but this time related to Google’s own branding. The authorization button that users clicked on my app did not follow their guidelines. They did send me a screenshot this time and I used similar text as them on my button. My confirmation email went back out to them.</p><p>Six weeks later, my third feedback email came in. Still inconsistent branding. My app’s name previously was “Google Calendar for [Saas Marketplace]” and I took the Google-related text out of the name (another feedback issue they had in the first email). Now they were claiming that the app’s name was too generic. To be fair, the Saas Marketplace’s name is very generic. So I came up with a different, more descriptive name. Also, they wanted me to add the Google Calendar icon to my authorization button. My confirmation email went back out.</p><p>Six more weeks and the fourth and final feedback email rolled in. I needed to add an app icon for the authorization consent screen that matched my branding elsewhere. Easy enough. My confirmation email was sent promptly.</p><p>Two short days later I received my email that my application was verified.</p><p>I had no idea that the process would involve so much branding scrutiny. The journey was lengthy but ultimately worth it. I know and understand why Google does this and at the end of the day they get the final say in who can use their product. They just want high-quality products associated with theirs. I hope anyone else going through this process and having similar problems gained some insight into what needs to be done to verify your application. The next time I do this, I imagine the whole process will be a lot smoother after this first experience.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/google-oauth-verification-experience"><em>https://thomasstep.com</em></a><em> on January 24, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47f65f023764" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Slack App]]></title>
            <link>https://thomasstep.medium.com/building-a-slack-app-a49d7451e132?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/a49d7451e132</guid>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 00:00:26 GMT</pubDate>
            <atom:updated>2024-01-26T16:11:35.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3evBUS3JtvNw8OjB" /><figcaption>Photo by <a href="https://unsplash.com/@scottwebb?utm_source=medium&amp;utm_medium=referral">Scott Webb</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Over the past few months, I got really into building apps for a marketplace. I threw together an app that I thought was fun just to see if anyone on that platform would use it about a year and a half ago. About 6 months ago, I received an email regarding adding features to that application. I had not thought about it over the year that it was live, and I was surprised to see that I had users when I looked at the statistics. I agreed to make their feature, and I started looking around for other opportunities to build applications for that marketplace.</p><p>One of the integrations that was missing was between their SaaS and Slack. Slack is a fairly well-used tool so I was surprised that no one had made that integration yet. I use it daily in my job, and I thought it could lead to benefits down the road as far as automating parts of my job. For that reason alone building a Slack application would be beneficial.</p><p>There were a couple of things I needed to quickly learn about Slack applications before I could even start building out my own. First was learning how they are distributed, then came all the permissions and APIs, and finally came writing the code that received events from Slack and acted on them.</p><h3>Distribution</h3><p>Slack apps can be distributed in several ways. Applications can be privately distributed, which would work well for an application custom-made for yourself and not intended for a wider audience. Applications can be publicly distributed, which means that others can use them but the developer (me) needs to provide users with a way to install or authorize the application. Lastly, applications can be publicly distributed through Slack’s official marketplace. I ultimately went with the public distribution method without going to the official Slack marketplace.</p><p>Slack, like most large SaaS providers, authorizes using OAuth, and they provide a pretty handy library to help with that authorization. The idea here is that your application sits and waits for someone to decide to authorize it. Once a Slack admin authorizes your application to access certain parts of their Slack workspace, then your application can post messages or listen for certain events like emoji reactions. The library that Slack offers to ease all of its operations is called <a href="https://api.slack.com/tools/bolt">Bolt</a> and it is offered in JavaScript, Python, and Java.</p><p>Since we are now getting into technicalities, it is worth pointing out that I built my Slack application using AWS Lambda. One strange adaptation I had to make to the Bolt boilerplate code was to run the OAuth receiver in a Lambda. Slack claims that there is a way to do this out-of-the-box, but it did not work for me or any of the other people online who submitted issues to their repository. I had to instead run the OAuth receiver portion of Bolt as an Express receiver and then use a package called <a href="https://www.npmjs.com/package/aws-serverless-express">aws-serverless-express</a> to run that Express receiver through Lambda. This is something that I want to circle back to at some point because that package is deprecated, but this is where I am at the moment.</p><p>Slack provides a little <a href="https://api.slack.com/authentication/oauth-v2#buttongen">generator</a> to create your own “Add to Slack” button which a user would click to kick off the Slack OAuth installation sequence. The “Redirect URI” would lead users to your OAuth receiver where final processing can be completed such as storing the installation details. The installation details provided in the OAuth receiver include the owner information for the Slack workspace, the bot token for that workspace, and the permission scopes given to the bot. Once the pertinent information is stored in your database, your application is officially installed in their Slack workspace.</p><h3>Permissions</h3><p>The permissions in Slack are intuitive but necessary to talk about. Permissions are part of the OAuth URL (in the “Add to Slack” button) and once those permissions are requested, your bot is stuck with them. Make sure that you know which permissions you need now and will need for future planned features.</p><p>Knowing which permissions you need is as easy as shopping around the <a href="https://api.slack.com/methods">API documentation</a>. Each API method will also list out the required scopes to perform that operation. As you write out functionality for your application, just make sure to also keep a running list of the minimum required scopes needed to implement that functionality.</p><p>What happens if you need permissions that you did not ask for during the installation? Fear not, there are ways to request additional permissions from your users. I have already needed to increase the amount of permissions that my users need to give my bot. The gist of requesting new permissions is that the user will need to reinstall your application. This means that they will need to navigate to a new OAuth installation URL with the added scopes. This can be obtained by using the “Add to Slack” button generator mentioned earlier.</p><p>Now the trickier part is, how do you get your users to click that button or navigate to your updated URL? I asked Slack’s support team the same question. Their answer was to either use the bot token to send them a direct message or you have to revoke their token, which is essentially uninstalling the app for them. I didn’t like either of those methods.</p><p>I opted for my own solution. There is a method in the Slack API called <a href="https://api.slack.com/methods/chat.postEphemeral">postEphemeral</a> which posts a message that only one user can see. I added some temporary logic to listen to messages, check the bot&#39;s allowed scopes (information stored by my OAuth receiver), and send the user an ephemeral message about needing to update. This allowed me to send my users notifications that they needed to reinstall for the latest features without disrupting their service. After they reinstalled, my OAuth receiver updated their bot token and allowed scopes stored in my database, and they never saw the message again.</p><h3>APIs</h3><p>Now comes the bread and butter of everything. What is a modern application if you can’t interact with it? Anything you can do in the Slack UI, you can do through the API, and more. The <a href="https://api.slack.com/methods">Slack API is well-documented</a> and is easy to use. If you are using Bolt, some of the common actions, like replying to messages, <a href="https://slack.dev/bolt-js/concepts#message-sending">have much easier-to-use function calls</a>. Otherwise, you will need to instantiate a Slack client to interact with their API. I used <a href="https://www.npmjs.com/package/@slack/web-api">@slack/web-api</a> since I was writing this application in JavaScript.</p><pre>const { WebClient, LogLevel } = require(&#39;@slack/web-api&#39;);<br><br>// const slackInstallationToken = readBotTokenFromDatabase();<br><br>const client = new WebClient(slackInstallationToken, {<br>  logLevel: LogLevel.INFO,<br>});</pre><p>On the documentation page for a given API method, there will be a row near the top called “Method access”. Click on your preferred language and it will show you the name of the function you will need to call to access the method through the client.</p><p>Every event receiver written will also have access to the web client, but more on that in the next section.</p><h3>Receiving Slack Events</h3><p>The API is great, but Slack events might be more fun. This is where your application not only gets to interact with Slack but also gets to interact with users based on their actions. There are loads of <a href="https://api.slack.com/events">event types that we can listen to</a> with the most popular being <a href="https://api.slack.com/events/message">messages</a>.</p><p>Using Bolt makes receiving events a breeze. There is some initial setup in the Slack app management console to tell Slack where to send your events and which events you want to listen to, but after that, you only need to list out your event listeners and write logic to handle them. Bolt takes care of transforming requests into friendlier formats.</p><p>Each event handler gets access to a couple of important pieces of information: event, client, and logger. The event is the payload of the actual event as it is seen in its documentation. The client is an instance of the web API client that I mentioned in the <a href="https://thomasstep.com/blog/building-a-slack-app#apis">APIs section</a>. The logger is a logger, although I preferred to use my logging solution. Any event type can be listened to by passing that type as a parameter in the listener setup, but you will need to repeat this for as many events as you want to handle. Here is what a listener setup might look like.</p><pre>app.event(&#39;reaction_added&#39;, async ({event, client}) =&gt; {<br>  // Handle reaction<br>});</pre><p>There is obviously more about Bolt that I will not bring up here. Their documentation is great and there seems to be a decent community online around building with Bolt.</p><h3>You’re Live!</h3><p>Now you have a way for users to install your application, your bot can interact with the Slack API, and you can react to your user’s actions. You’re up and ready to go. I really enjoyed putting my application together and building with Slack. It’s quick, easy, and rewarding. Have fun building your own application!</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/building-a-slack-app"><em>https://thomasstep.com</em></a><em> on January 19, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a49d7451e132" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Sweatspaces and the Mom Test]]></title>
            <link>https://thomasstep.medium.com/building-sweatspaces-and-the-mom-test-38202e22c3f4?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/38202e22c3f4</guid>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[marketing]]></category>
            <category><![CDATA[entrepreneurship]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 00:00:58 GMT</pubDate>
            <atom:updated>2023-08-03T14:01:51.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lrKe9-8DviBhMg6G" /><figcaption>Photo by <a href="https://unsplash.com/@ussamaazam?utm_source=medium&amp;utm_medium=referral">Ussama Azam</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Well…I built something else. This one is a much larger project than my previous projects, but I can’t tell yet whether it was worth the extra effort. I have a goal to one day create a product that people use and enjoy. I have tried a couple of times throughout my short online career to do that with Elsewhere, Crow Auth, Papyrus, various APIs and marketplace widgets, and now Sweatspaces. I have yet to have anything gain traction. Probably due to my lack of marketing. Sweatspaces was a larger endeavor because it involved multiple microservices. Maybe someday I’ll make an architecture post similar to the ones I have done in the past.</p><p>With the larger time cost of building this out, I wanted to keep giving it more attention and decided that I would start reaching out to people who I thought would use the product. Sweatspaces is a marketplace of sorts that connects people who want to rent out their home gyms to people who want a more private workout experience. The only reason I built it was because I wanted to rent a home gym for the same reason. I would build one but I don’t have space in my house or garage.</p><p>I started finding people online and started getting in contact with them. This is not the first time I have done <a href="https://thomasstep.com/blog/how-long-until-you-call-it-quits">cold outreach</a>, but I felt like this product was better. While there have been some interested souls I started coming across a concept that I had not applied, which is to do this type of work before building the product. I thought I had something this time because I personally wanted to use it. But I am not everyone else and I can’t force my wants on anyone.</p><p>I’m sure most people in the startup space have already encountered the idea of the <a href="https://www.momtestbook.com/">Mom Test</a>. The idea is to talk to your potential customers before you ever build something to validate that it is something worth building. Another key though is not to ask them if they think the idea is good, but rather to ask them about their problems. If they coincidentally bring up the problem you are trying to solve, you can go a little deeper and see what they do to solve it now, how much it costs them, and then finally if they would buy something to solve it. The book explains it far better than I can or want to.</p><p>The gist is that after building out Sweatspaces, I learned an important lesson. Marketing should come after validation. Building should come after validation. Everything, really, should come after validation. And talking to potential customers shouldn’t be about validating your idea, it should be about listening to them and the problems that they face. That way you already know that the problem you are solving is a worthy one. Now the next step for me is to figure out where to find the people I want to build solutions for and how to decode that information from what they are saying.</p><p>Just learning about a topic does not always result in me fully absorbing it. I hope that writing this down and being able to reflect on it will help me move forward and do the correct thing. I need applied lessons to fully absorb a topic and this was one of them.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/building-sweatspaces-and-the-mom-test"><em>https://thomasstep.com</em></a><em> on July 28, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38202e22c3f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Triathlon]]></title>
            <link>https://thomasstep.medium.com/my-first-triathlon-ef1ac466a774?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef1ac466a774</guid>
            <category><![CDATA[cycling]]></category>
            <category><![CDATA[running]]></category>
            <category><![CDATA[fitness]]></category>
            <category><![CDATA[triathlon]]></category>
            <category><![CDATA[swimming]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 00:00:34 GMT</pubDate>
            <atom:updated>2023-08-03T13:21:00.922Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uqWdHDA81gSa0fey" /><figcaption>Photo by <a href="https://unsplash.com/@asoggetti?utm_source=medium&amp;utm_medium=referral">Alessio Soggetti</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’m taking a step away from the technology discussion for this post. Last weekend I completed my first triathlon. I have been training in all three disciplines (swim, bike, run) for a couple of years now but I had not signed up for a race because I didn’t want to spend the money. I wanted to recap my race and briefly discuss my training leading up to it.</p><p>First came the swim, which was somehow the most surprising of the portions. This was the first time I had swum in open water. I knew that it was a bad idea but I did not have an opportunity otherwise to swim in open water. Not being able to see the bottom was not too bad but having people (obstacles) around me was a problem. Everyone swimming into each other was confusing and resulted in me looking up only to be met by many other confused looks of others around me. Quite comical.</p><p>The most surprising bit of the swim was my result. This was only supposed to be a 550-meter swim (my GPS said 650+), so I expected to get out of the water somewhere around 12 minutes. Much to my surprise I clocked in under 11 minutes. I guess I wanted to get out of the situation so badly that I swam possibly the fastest swim for that length in my life. But who knows, I don’t track my swim paces like I do cycling and running.</p><p>T1 went slower than I expected. I’m no professional triathlete, and I told myself that as I ran up to my bike. I ended up taking my time and sitting down to dry off my feet and put on socks and shoes. Out of transition, I did a sort of (?) flying mount onto my bike. Definitely smoother than the other people around me but not graceful.</p><p>Onto the bike portion. I had fun but this was also the leg of the race that I knew I would have fun on. The race was not draft-legal but no one wanted to follow that rule (I tried as best as I could). I passed some people but not a great amount. Most people I passed were on road bikes, some on TT bikes, and some on commuter bikes. The cyclists that surprised me most were the ones with fully kitted-out TT bikes. The airy whooshing sounds they made as they passed me going about 30 were unforgettable. I would love to give someone that same experience sometime in the future. (I am now in the market for a TT bike.) I was targeting ~20 mph (~32 kph) for the entire section which was 13 miles. I stayed surprisingly true to my goal and got off the bike after slightly less than 40 minutes.</p><p>Next came the run. Near the end of the bike, I started worrying about the run. My legs were feeling a little sluggish and I had not consumed as much water as I wanted. Also, a run off of an intense bike was fairly uncommon for me.</p><p>I tried to start the run not at a specific pace but by feel. I had run enough brick sessions leading up to this that I knew I would be able to cook (relatively) later on but that my body doesn’t like being pushed right off the bike. I was passed by multiple people. After the first mile or so I caught up to them though and started feeling much better. The rest of the run was good and I ended up negative splitting the entire 5k.</p><p>I happily accepted my water at the finish line and jumped into an ice bath which was a welcome amenity. I finished in 1 hour 18 minutes for a 550-yard swim (650 yd GPS), 13-mile bike, and 5-kilometer run. I forgot to mention at the start but I ran this in Houston in July. The weather was better than normal but still extremely hot and humid.</p><p>Training wise I kept everything super simple, and I did not use a training plan. I knew that the distance wasn’t going to be a problem, just the heat and humidity. I did most of my training around lunchtime to try and get the best acclimatization that I could. I alternated cycling and running during the week (the exact days shifted). I took an odd Monday or Friday off if I felt like it otherwise I trained every day. On the weekends I tried to get in one long bike (~2 hours) and one medium-ish run (~1 hour) with a swim sprinkled in now and then. The last month before the race I added in a brick run off my long bike to get my legs used to that feeling.</p><p>All in all, it was a great experience and I look forward to doing it again. What I would have changed is to try and get out to do an open water swim. At least one would have helped before the real deal. As far as training goes, I would have loved to do more intensity/speed work, but in this weather, it is hard enough just to get out and train.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/finishing-my-first-triathlon"><em>https://thomasstep.com</em></a><em> on July 28, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef1ac466a774" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API Pagination with DynamoDB]]></title>
            <link>https://thomasstep.medium.com/api-pagination-with-dynamodb-480d4ce78254?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/480d4ce78254</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 00:00:54 GMT</pubDate>
            <atom:updated>2023-04-18T13:41:39.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JPjCFiY6w82bSWbU" /><figcaption>Photo by <a href="https://unsplash.com/es/@disguise_truth?utm_source=medium&amp;utm_medium=referral">Anastasia Zhenina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I recently posted about <a href="https://thomasstep.com/blog/api-calls-with-pagination-in-react">reading from a paginated API in React</a>, and in this post, I wanted to write about the flip side of that: implementing pagination in an API with DynamoDB as the database. For these code snippets, I will be using Go but the same strategy and similar API calls will apply to any language dealing with DynamoDB. First I will discuss what my end goal was before I started implementing this, then I will break down the steps, and finally, I will add some code snippets to accompany the steps.</p><p>I wanted to implement pagination for my API because it was very easy to see how quickly a set of entities was going to grow and I wanted to add some sort of limit to my payloads. After reading about several strategies for implementing API pagination, I settled on using a token-based strategy. The idea around this is to return an opaque token to the user and when that same token is given back to the API, the result will continue based on where it left it as signified by the token. For my purposes, I wanted to add a pagination object to my payload with a nextToken field.</p><pre>{<br>  &quot;other&quot;: &quot;property&quot;,<br>  &quot;pagination&quot;: {<br>    &quot;nextToken&quot;: &quot;thisisthenexttoken&quot;<br>  }<br>}</pre><p>Here are the steps that I broke this down into.</p><ol><li>Update API to accept limit and nextToken query parameters where pagination is desired.</li><li>Have reasonable defaults for those parameters. For example, limit = 20 and nextToken = null.</li><li>Decode the nextToken from base64 and unmarshal the JSON string into an object/struct. (This will make more sense by the end of the steps.)</li><li>Pass the values to the DynamoDB Query or Scan call (those are the only two that are paginated) using the Limit and ExclusiveStartKey values.</li><li>Read the resulting value in LastEvaluatedKey from the DynamoDB call. If it is empty, return the nextToken as null. Otherwise, marshal the LastEvaluatedKey to a JSON string then encode to base64.</li><li>Return the encoded string as the nextToken.</li></ol><p>Hopefully that all makes sense. If not, I would suggest going back over it and making sure you understand the idea behind the code snippets. Also, these snippets assume that you are already familiar with the AWS SDK for Go. There is information that you will need to understand and be able to replace such as the table name. All that to say that these are not copy-and-paste ready.</p><h3>1. Update API to accept limit and nextToken query parameters where pagination is desired.</h3><p>This step is very API-specific, and not something that is probably out of scope for this post.</p><h3>2. Have reasonable defaults for those parameters. For example, limit = 20 and nextToken = null.</h3><p>This step is very API-specific, and not something that is probably out of scope for this post.</p><h3>3. Decode the nextToken from base64 and unmarshal the JSON string into an object/struct. (This will make more sense by the end of the steps.)</h3><p>For some extra context, I am using the &quot;github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue&quot; package to help marshal and unmarshal generic maps.</p><pre>if nextToken != &quot;&quot; {<br>  exclStartString, decErr := base64.StdEncoding.DecodeString(nextToken)<br>  if decErr != nil {<br>    logger.Error(&quot;Failed to decode nextToken from base64&quot;,<br>      zap.Error(decErr),<br>    )<br>    return entries, &quot;&quot;, decErr<br>  }<br><br>  logger.Debug(&quot;Base64 decode complete&quot;, zap.Any(&quot;exclStartString&quot;, exclStartString))<br><br>  /*<br>    type DdbPrimaryKey struct {<br>      Id          string `dynamodbav:&quot;id&quot;`<br>      SecondaryId string `dynamodbav:&quot;secondaryId&quot;`<br>    }<br>  */<br>  entry := &amp;types.DdbPrimaryKey{}<br>  jsonErr := json.Unmarshal(exclStartString, entry)<br>  if jsonErr != nil {<br>    logger.Error(&quot;Failed to unmarshal nextToken&quot;,<br>      zap.Error(jsonErr),<br>    )<br>    return entries, &quot;&quot;, jsonErr<br>  }<br><br>  logger.Debug(&quot;JSON unmarshal complete&quot;, zap.Any(&quot;entry&quot;, entry))<br><br>  marshalledStartKey, marshalErr := attributevalue.MarshalMap(entry)<br>  if marshalErr != nil {<br>    logger.Error(&quot;Failed to marshal entry to map[string]AttributeValue&quot;,<br>      zap.Error(marshalErr),<br>    )<br>    return entries, &quot;&quot;, marshalErr<br>  }<br><br>  logger.Debug(&quot;AV marshal complete&quot;, zap.Any(&quot;marshalledStartKey&quot;, marshalledStartKey))<br><br>  startKey = marshalledStartKey<br>}</pre><h3>4. Pass the values to the DynamoDB Query or Scan call (those are the only two that are paginated) using the Limit and ExclusiveStartKey values.</h3><pre>queryInput := &amp;dynamodb.QueryInput{<br>  TableName:                 aws.String(config.PrimaryTableName),<br>  KeyConditionExpression:    expr.KeyCondition(),<br>  ExpressionAttributeNames:  expr.Names(),<br>  ExpressionAttributeValues: expr.Values(),<br>  Limit:                     aws.Int32(limit),<br>}<br><br>if len(startKey) != 0 {<br>  queryInput.ExclusiveStartKey = startKey<br>}<br><br>queryRes, queryErr := ddbClient.Query(context.TODO(), queryInput)</pre><h3>5. Read the resulting value in LastEvaluatedKey from the DynamoDB call. If it is empty, return the nextToken as null. Otherwise, marshal the LastEvaluatedKey to a JSON string then encode to base64.</h3><pre>if len(queryRes.LastEvaluatedKey) != 0 {<br>  logger.Debug(&quot;Last evalualted key&quot;, zap.Any(&quot;queryRes.LastEvaluatedKey&quot;, queryRes.LastEvaluatedKey))<br>  lastEvalKey := &amp;types.DdbPrimaryKey{}<br>  marshalErr := attributevalue.UnmarshalMap(queryRes.LastEvaluatedKey, lastEvalKey)<br>  if marshalErr != nil {<br>    logger.Error(&quot;Failed to unmarshal map[string]AttributeValue to entry&quot;,<br>      zap.Error(marshalErr),<br>    )<br>    return entries, &quot;&quot;, marshalErr<br>  }<br><br>  logger.Debug(&quot;AV unmarshal complete&quot;, zap.Any(&quot;lastEvalKey&quot;, lastEvalKey))<br><br>  lastEvalString, jsonErr := json.Marshal(lastEvalKey)<br>  if jsonErr != nil {<br>    logger.Error(&quot;Failed to marshal last evaluated key json&quot;,<br>      zap.Error(jsonErr),<br>    )<br>    return entries, &quot;&quot;, jsonErr<br>  }<br><br>  logger.Debug(&quot;JSON marshal complete&quot;, zap.Any(&quot;lastEvalString&quot;, lastEvalString))<br><br>  // lastEvalB64 will be returned as nextToken in the resulting payload<br>  lastEvalB64 := base64.StdEncoding.EncodeToString([]byte(lastEvalString))<br>}</pre><h3>6. Return the encoded string as the nextToken.</h3><p>How you do this is up to you and your API framework.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/api-pagination-with-dynamodb"><em>https://thomasstep.com</em></a><em> on April 10, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=480d4ce78254" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API Calls with Pagination in React]]></title>
            <link>https://thomasstep.medium.com/api-calls-with-pagination-in-react-75b603ec125d?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/75b603ec125d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 00:00:46 GMT</pubDate>
            <atom:updated>2023-04-17T13:42:08.784Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BO1HGFomuo0rg857" /><figcaption>Photo by <a href="https://unsplash.com/@impatrickt?utm_source=medium&amp;utm_medium=referral">Patrick Tomasso</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I wanted to share a simple strategy that I implemented when reading entities from an API that used pagination. For some context, this was for <a href="https://elsewhere.thomasstep.com/">Elsewhere</a>. There are possibly many many entries that can be part of a trip. Reading the entities is paginated so the payload is not an unbounded size. The pagination strategy is using a token for the next page and if there are no more pages, then the token is null. A payload might look like the following</p><pre>{<br>  &quot;entries&quot;: [<br>    {<br>      &quot;id&quot;: &quot;bbfbe7ac-8c10-4d4b-b512-99925db13604&quot;,<br>      &quot;name&quot;: &quot;entry name&quot;,<br>      &quot;startTimestamp&quot;: &quot;2023-01-29T01:00:00.000Z&quot;,<br>      &quot;endTimestamp&quot;: &quot;2023-01-29T03:00:00.000Z&quot;,<br>      &quot;createdBy&quot;: &quot;666e7d31-6692-4852-81fe-40eeb6c35d0b&quot;,<br>      &quot;location&quot;: {<br>        &quot;latitude&quot;: 44.208788215176114,<br>        &quot;longitude&quot;: -69.06005859375<br>      }<br>    }<br>  ],<br>  &quot;pagination&quot;: {<br>    &quot;nextToken&quot;: &quot;eyJJZCI6Ijk4YjViOGRmLTM1MWItNGJkOC04YTFkLWIwM2JlZjA3OTdjYiIsIlNlY29uZGFyeUlkIjoiY29uZmlnIn0=&quot;<br>  }<br>}</pre><p>The pagination.nextToken is what we are after.</p><p>The front end wants to read all of the entries and display them for the user, but it needs to essentially loop through the results to read them all. I started with a new piece of state that I called nextToken (very fitting) initialized as null. Then came the initial call to the API with whatever properties I wanted like a limit in a useEffect hook that ran whenever the component mounted meaning the second parameter was an empty array. The call is run alongside other initialization. During that initial call, I check the length of the array of paginated results returned and the nextToken. I check the length of the array because if it is less than the limit, I already know we have read all the results and I can be done. If the array is equal to the limit and the nextToken is not null, then I set the nextToken state to whatever the value in the payload was.</p><p>To loop through the rest of the pages, I wrote another useEffect hook that only triggers on a nextToken state change (the second parameter is [nextToken]). (It is also important to note that the hook starts by checking that the nextToken state is not null.) Whenever the hook triggers, I read another page with the same limit and pass in the nextToken provided by the state. The same checking applies to the resulting payload for another page. If the array size is equal to the limit and the nextToken value in the payload is set, then I update the nextToken state for the hook to run another time. The new page&#39;s results are appended to the existing results, which ends up building out the whole set of information.</p><p>Here is what an implementation might look like.</p><pre>function MyComponent() {<br>  const [entries, setEntries] = useState([]);<br>  const [nextToken, setNextToken] = useState(null);<br><br>  useEffect(() =&gt; {<br>    if (!token || !router.isReady) {<br>      return;<br>    }<br><br>    fetch(`paginated.resource/entries?${new URLSearchParams({ limit })}`)<br>      .then((res) =&gt; {<br>        if (res.status !== 200) throw new Error(&#39;Unhandled status code&#39;);<br><br>        return res.json();<br>      })<br>      .then((data) =&gt; {<br>        const resEntries = data.entries;<br>        const resNextToken = data.pagination.nextToken;<br>        setEntries(resEntries);<br>        if (resEntries.length === limit &amp;&amp; resNextToken) {<br>          setNextToken(resNextToken);<br>        }<br>      })<br>      .catch((err) =&gt; {<br>        console.error(err)<br>      });<br>  }, [router, token]);<br><br>  // Scroll through pagination<br>  useEffect(() =&gt; {<br>    if (!nextToken) return;<br><br>    const params = {<br>      limit,<br>      nextToken,<br>    };<br>    fetch(`paginated.resource/entries?${new URLSearchParams(params)}`)<br>      .then((res) =&gt; {<br>        if (res.status !== 200) throw new Error(&#39;Unhandled status code&#39;);<br><br>        return res.json();<br>      })<br>      .then((data) =&gt; {<br>        const resEntries = data.entries;<br>        const resNextToken = data.pagination.nextToken;<br>        const newEntries = Array.from(entries);<br>        newEntries.push(...resEntries);<br>        setEntries(newEntries);<br>        if (resEntries.length === limit &amp;&amp; resNextToken) {<br>          setNextToken(resNextToken);<br>        }<br>      })<br>      .catch((err) =&gt; {<br>        console.error(err)<br>      });<br>  }, [nextToken]);<br><br>  return (<br>    &lt;Something /&gt;<br>  );<br>}</pre><p>Of course, many pieces might need to be filled in or adjusted for your specific use case. Hopefully, this gives you a jumping-off point of how someone else somewhere in the world has gone about reading from a paginated API.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/api-calls-with-pagination-in-react"><em>https://thomasstep.com</em></a><em> on April 10, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75b603ec125d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Google Maps and Search with React]]></title>
            <link>https://thomasstep.medium.com/using-google-maps-and-search-with-react-4d6ea0bada03?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d6ea0bada03</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 00:00:00 GMT</pubDate>
            <atom:updated>2023-04-15T02:46:47.322Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9iVYH1vODTl27uN0" /><figcaption>Photo by <a href="https://unsplash.com/@geojango_maps?utm_source=medium&amp;utm_medium=referral">GeoJango Maps</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When I started remaking <a href="https://elsewhere.thomasstep.com/">Elsewhere</a> I knew I wanted to refresh the map. The first version of Elsewhere used a third part React component that helped render Google Maps. It was fine but a few features were missing and it was not actively developed. When I started thinking of other options, I was going to switch over to Mapbox. They seem to have a clean, first-party React component that’s ready to use. Fast forward to putting my hands on the keyboard ready to code, and I searched for something that lead me to a <a href="https://github.com/googlemaps/react-wrapper">first-party Google Maps React component</a>. This post will be about working with the @googlemaps/react-wrapper component, showing some code built around/with it, and hopefully giving others a good jumping-off point for integrating Google Maps into their applications.</p><p>First things first, you will need an API key to use this component. Google Maps isn’t free. Go to the <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjjveOdwpb-AhWtmmoFHeW5DsgQFnoECAsQAQ&amp;url=https%3A%2F%2Fconsole.cloud.google.com%2F&amp;usg=AOvVaw1GxwHR1WZnDu0xsR-djCrv">Google Developer console</a> to create an API key. There is <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">documentation online</a> to help get all this set up. A word to the wise, you will have to set up billing with a credit card, so make sure to restrict your API key(s).</p><p>After we have our API key, we’re ready to jump into code. Assuming you already have the package installed and ready to go, you will need to set up two components before seeing anything on the screen. The @googlemaps/react-wrapper component really only handles the Javascript of downloading and making the Google Maps API available. You still need to load it. For now, let&#39;s assume the API is loaded and available, let&#39;s build a map.</p><p>There are a few things I want to go over before showing the code for this since there are a few “gotchas” with how all this works. Google Maps uses refs to grab onto elements and render the map, which means we&#39;ll need React&#39;s useRef. We will be passing the <a href="https://developers.google.com/maps/documentation/javascript/reference/map#Map.setOptions">Map&#39;s options</a> as a deeply nested object (as seen in the <a href="https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions">API docs</a>), so we will need to write a custom hook since React does not do deep comparisons. Lastly, event listeners function differently on Maps than how they would on normal elements, so we will need to manually clear and re-add those listeners if the props ever change while the Map is rendered.</p><p>Without further ado, here is a Map component.</p><pre>import React, { useEffect, useRef, useState } from &#39;react&#39;;<br>import PropTypes from &#39;prop-types&#39;;<br>import { createCustomEqual } from &#39;fast-equals&#39;;<br>import { isLatLngLiteral } from &#39;@googlemaps/typescript-guards&#39;;<br><br>const deepCompareEqualsForMaps = createCustomEqual((deepEqual) =&gt; (a, b) =&gt; {<br>  if (<br>    isLatLngLiteral(a)<br>    // eslint-disable-next-line no-undef<br>    || a instanceof google.maps.LatLng<br>    // eslint-disable-next-line no-undef<br>    || b instanceof google.maps.LatLng<br>  ) {<br>    // eslint-disable-next-line no-undef<br>    return new google.maps.LatLng(a).equals(new google.maps.LatLng(b));<br>  }<br>  // TODO extend to other types<br>  // use fast-equals for other objects<br>  return deepEqual(a, b);<br>});<br><br>function useDeepCompareMemoize(value) {<br>  const ref = useRef();<br><br>  if (!deepCompareEqualsForMaps(value, ref.current)) {<br>    ref.current = value;<br>  }<br>  return ref.current;<br>}<br><br>function useDeepCompareEffectForMaps(callback, dependencies) {<br>  useEffect(callback, dependencies.map(useDeepCompareMemoize));<br>}<br><br>function Map({<br>  bounds,<br>  onClick,<br>  onIdle,<br>  children,<br>  style,<br>  ...options<br>}) {<br>  const mapRef = useRef(null);<br>  const [map, setMap] = useState();<br><br>  // Setup map<br>  useEffect(() =&gt; {<br>    if (mapRef.current &amp;&amp; !map) {<br>      // eslint-disable-next-line no-undef<br>      const newMap = new window.google.maps.Map(mapRef.current, {});<br><br>      setMap(newMap);<br><br>      if (bounds) {<br>        newMap.fitBounds(bounds);<br>      }<br>    }<br>  }, [mapRef, map]);<br><br>  // Because React does not do deep comparisons, a custom hook is used<br>  // See discussion in https://github.com/googlemaps/js-samples/issues/946<br>  useDeepCompareEffectForMaps(() =&gt; {<br>    if (map) {<br>      map.setOptions(options);<br>    }<br>  }, [map, options]);<br><br>  useEffect(() =&gt; {<br>    if (map) {<br>      // Something similar can be done with any other listener that is added to the map<br>      // eslint-disable-next-line no-undef<br>      [&#39;click&#39;, &#39;idle&#39;].forEach((eventName) =&gt; google.maps.event.clearListeners(map, eventName));<br>      if (onClick) {<br>        map.addListener(&#39;click&#39;, onClick);<br>      }<br><br>      if (onIdle) {<br>        map.addListener(&#39;idle&#39;, () =&gt; onIdle(map));<br>      }<br>    }<br>  }, [map, onClick, onIdle]);<br><br>  useEffect(() =&gt; {<br>    if (map &amp;&amp; bounds) {<br>      map.fitBounds(bounds);<br>    }<br>  }, [map, bounds]);<br><br>  return (<br>    &lt;&gt;<br>      &lt;div ref={mapRef} style={style} /&gt;<br>      {React.Children.map(children, (child) =&gt; {<br>        if (React.isValidElement(child)) {<br>          // set the map prop on the child component<br>          // @ts-ignore<br>          return React.cloneElement(child, { map });<br>        }<br>        return null;<br>      })}<br>    &lt;/&gt;<br>  );<br>}<br><br>Map.propTypes = {<br>  // eslint-disable-next-line react/forbid-prop-types<br>  bounds: PropTypes.object,<br>  onClick: PropTypes.func,<br>  onIdle: PropTypes.func,<br>  children: PropTypes.oneOfType([<br>    PropTypes.arrayOf(PropTypes.node).isRequired,<br>    PropTypes.node.isRequired,<br>  ]),<br>  // eslint-disable-next-line react/forbid-prop-types<br>  style: PropTypes.object.isRequired,<br>};<br><br>Map.defaultProps = {<br>  bounds: null,<br>  onClick: () =&gt; {},<br>  onIdle: () =&gt; {},<br>  children: null,<br>};<br><br>export default Map;</pre><p><a href="https://github.com/googlemaps/js-samples/blob/c1036e60d2f50056fba1617a1be507b00b6cac5a/dist/samples/react-map/docs/index.jsx">Here</a> is another version of that code.</p><p>The next step before we can see the Map being rendered is to wrap it. This is the not-as-glamorous part, which is why I saved it until after the flashy component. You probably noticed the // eslint-disable-next-line no-undef comment littered throughout the component. That&#39;s because we are assuming that google is out there somewhere on the document and we can grab it out of the ether. If we don&#39;t wrap the Map component, then it won&#39;t be there and we get errors galore.</p><p>To wrap and render the Map component we need to do something like this.</p><pre>const loadingRender = (status) =&gt; {<br>  switch (status) {<br>    case Status.LOADING:<br>      return &lt;LoadingPage /&gt;;<br>    case Status.FAILURE:<br>      return &lt;LoadingPage /&gt;;<br>    case Status.SUCCESS:<br>      return &lt;LoadingPage /&gt;;<br>    default:<br>      return &lt;LoadingPage /&gt;;<br>  }<br>};<br><br>...<br><br>&lt;Wrapper<br>  apiKey={yourApiKey}<br>  render={loadingRender}<br>  libraries={[&#39;places&#39;]}<br>&gt;<br>  &lt;Map yourProps={goHere}/&gt;<br>&lt;/Wrapper&gt;</pre><p>The loadingRender function assumes you have a LoadingPage component, otherwise, you can exclude render={loadingRender}. You will need to read yourApiKey from somewhere...up to you. And libraries={[&#39;places&#39;]} also loads the additional <a href="https://developers.google.com/maps/documentation/javascript/places">Google Maps Places library</a>, so if you are not using that library feel free to exclude that prop.</p><p>Once that wrapped Map is rendered, you should see a map! Wow.</p><p>To the astute observers, you probably noticed something funky going on in the Map component related to the children. The reason is that a Google Map doesn&#39;t really accept children but we can add additional decoration to the map which one might believe are children. Particularly markers. Adding a simple map isn&#39;t that much fun, now we have to draw something on it.</p><p>Markers are easy to render compared to maps. No refs, but we still need to baby the listeners and options.</p><pre>import { useState, useEffect } from &#39;react&#39;;<br>import PropTypes from &#39;prop-types&#39;;<br><br>function Marker({<br>  onClick,<br>  onDragEnd,<br>  ...options<br>}) {<br>  const [marker, setMarker] = useState();<br>  const [clickListener, setClickListener] = useState();<br>  const [dragEndListener, setDragEndListener] = useState();<br><br>  useEffect(() =&gt; {<br>    if (!marker) {<br>      // eslint-disable-next-line no-undef<br>      const newMarker = new google.maps.Marker();<br>      const clk = newMarker.addListener(&#39;click&#39;, (e) =&gt; {<br>        onClick(e);<br>      });<br>      setClickListener(clk);<br>      const de = newMarker.addListener(&#39;dragend&#39;, (e) =&gt; {<br>        const lat = newMarker.position.lat();<br>        const lng = newMarker.position.lng();<br>        onDragEnd(e, lat, lng);<br>      });<br>      setDragEndListener(de);<br>      setMarker(newMarker);<br>    }<br><br>    // Remove marker from map on unmount<br>    return () =&gt; {<br>      if (marker) {<br>        marker.setMap(null);<br>        // eslint-disable-next-line no-undef<br>        google.maps.event.removeListener(clickListener);<br>        // eslint-disable-next-line no-undef<br>        google.maps.event.removeListener(dragEndListener);<br>      }<br>    };<br>  }, [marker]);<br><br>  useEffect(() =&gt; {<br>    if (marker) {<br>      marker.setOptions(options);<br>    }<br>  }, [marker, options]);<br><br>  // This effect updates click listeners by removing the old<br>  //  one and adding a new one<br>  useEffect(() =&gt; {<br>    if (marker &amp;&amp; clickListener) {<br>      // eslint-disable-next-line no-undef<br>      google.maps.event.removeListener(clickListener);<br>      const clk = marker.addListener(&#39;click&#39;, (e) =&gt; {<br>        onClick(e);<br>      });<br>      setClickListener(clk);<br>    }<br>  }, [marker, onClick]);<br>  return null;<br>}<br><br>Marker.propTypes = {<br>  onClick: PropTypes.func,<br>  onDragEnd: PropTypes.func,<br>};<br><br>Marker.defaultProps = {<br>  onClick: () =&gt; {},<br>  onDragEnd: () =&gt; {},<br>};<br><br>export default Marker;</pre><p>One additional piece to note, the onDragEnd function is one passed in if you are storing and updating the locations of the Markers being drawn. Otherwise, you can remove that piece. It took me an untrivial amount of time to get working which is why I left it. You will also need to add the draggable prop on the Marker to get passed into the options. It might look something like this.</p><pre>&lt;Wrapper<br>  apiKey={yourApiKey}<br>  render={loadingRender}<br>  libraries={[&#39;places&#39;]}<br>&gt;<br>  &lt;Map yourProps={goHere}&gt;<br>    &lt;Marker<br>      position=<br>      draggable<br>      onDragEnd={(e, lat, lng) =&gt; {<br>        // Do something with lat/lng<br>      }}<br>    /&gt;<br>  &lt;/Map&gt;<br>&lt;/Wrapper&gt;</pre><p>It’s also possible to add some level of customization to a Marker by changing the icon in the middle of the bubble. Google has something called advanced markers, but when I was looking into them they didn&#39;t seem well-featured. Maybe by the time you&#39;re reading this, they will be ready for production and you can style markers even further.</p><pre>&lt;Wrapper<br>  apiKey={yourApiKey}<br>  render={loadingRender}<br>  libraries={[&#39;places&#39;]}<br>&gt;<br>  &lt;Map yourProps={goHere}&gt;<br>    &lt;Marker<br>      position={{<br>        lat: 21.126227,<br>        lng: -11.404002,<br>      }}<br>      draggable<br>      onDragEnd={(e, lat, lng) =&gt; {<br>        // do something with lat/lng<br>      }}<br>      label={{<br>        text: &#39;\ue145&#39;,<br>        fontFamily: &#39;Material Icons&#39;,<br>        color: &#39;#ffffff&#39;,<br>        fontSize: &#39;18px&#39;,<br>      }}<br>    /&gt;<br>  &lt;/Map&gt;<br>&lt;/Wrapper&gt;</pre><p>Of course, doing this means that you will need to have the Material Icons font downloaded somewhere on your page, like in the &lt;head&gt; of your document. Something like this should do the trick.</p><pre>&lt;link<br>  rel=&quot;stylesheet&quot;<br>  href=&quot;https://fonts.googleapis.com/icon?family=Material+Icons&quot;<br>/&gt;</pre><p>The final piece that I wanted to mention is the Places API that I briefly mentioned earlier in the Wrapper. If you do load this API, then you can add searching to your map. You&#39;ll need some sort of input ref to attach the library to and then you can set the search context based on locations that the map is positioned over. For ease of example, I&#39;m going to add this into the Map component. In the Map component, you will need to add two useEffect hooks and add an &lt;input&gt; to the render.</p><pre>const inputRef = useRef(null);<br>  const autocompleteRef = useRef(null);<br>  const [autocompleteWidget, setAutocompleteWidget] = useState();<br><br>  // Setup autocomplete<br>  useEffect(() =&gt; {<br>    if (inputRef.current &amp;&amp; !autocompleteWidget) {<br>      // eslint-disable-next-line no-undef<br>      const acw = new google.maps.places.Autocomplete(inputRef.current);<br>      autocompleteRef.current = acw;<br>      setAutocompleteWidget(acw);<br>    }<br>  }, [inputRef, autocompleteWidget]);<br><br>  // Additional map-dependent autocomplete setup<br>  // This is where searches are clicked<br>  useEffect(() =&gt; {<br>    if (map &amp;&amp; autocompleteWidget) {<br>      autocompleteWidget.bindTo(&#39;bounds&#39;, map);<br>      autocompleteWidget.addListener(&#39;place_changed&#39;, () =&gt; {<br>        const place = autocompleteWidget.getPlace();<br><br>        if (!place.geometry || !place.geometry.location) {<br>          // User entered the name of a Place that was not suggested and<br>          // pressed the Enter key, or the Place Details request failed.<br>          // window.alert(&quot;No details available for input: &#39;&quot; + place.name + &quot;&#39;&quot;);<br>          return;<br>        }<br><br>        // If the place has a geometry, then present it on a map.<br>        if (place.geometry.viewport) {<br>          map.fitBounds(place.geometry.viewport);<br>        } else {<br>          map.setCenter(place.geometry.location);<br>          map.setZoom(17);<br>        }<br><br>        const latitude = place.geometry.location.lat();<br>        const longitude = place.geometry.location.lng();<br><br>        // What you do know is up to you<br>        // You could use state to draw another Marker at this location<br>        // Or anything else really. The beauty of programming I guess.<br>      });<br>    }<br>  }, [map, autocompleteWidget]);</pre><p>And just like that, all my knowledge on this subject has been transferred. We’ve rendered a map, drawn markers on the map, and added a search box. Pretty nifty. That’s hours of my life right there, so put it to good use, please.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/using-google-maps-and-search-with-react"><em>https://thomasstep.com</em></a><em> on April 6, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d6ea0bada03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Schedule Component]]></title>
            <link>https://thomasstep.medium.com/building-a-schedule-component-7dc33f33ca7e?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dc33f33ca7e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 00:00:20 GMT</pubDate>
            <atom:updated>2023-03-10T13:46:01.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rcM4O1B1YpoeRESU" /><figcaption>Photo by <a href="https://unsplash.com/@behy_studio?utm_source=medium&amp;utm_medium=referral">Behnam Norouzi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Since I built the <a href="https://thomasstep.com/blog/elsewhere-diary">first version of Elsewhere</a> I wanted to include scheduling. The original idea for Elsewhere was to have a single app that helped organize an itinerary, and for me and the people I plan trips with, a schedule is a core component of the itinerary. It did not have to be anything crazy or complex, even just a representation of the events laid over the hours in a day. When I decided to <a href="https://thomasstep.com/blog/remaking-elsewhere">remake Elsewhere</a>, adding a schedule was one of the main things I wanted to accomplish. Handling the back end side of things was not too difficult because I just saved ISO strings for the start and end times of events. The front end is where things started getting interesting, and by interesting I mean hard.</p><p>Schedule components are rare in the open source world. Originally, I did not want to build a schedule component myself. I hoped that I would search for packages, pick the one of many I found, and drop it in place. The only schedule/calendar component I found <a href="https://www.syncfusion.com/react-components/react-scheduler">was paid</a>. How strange…I still don’t completely understand how that model works. But I am a bootstrapper with time, not money, so I used the resources I had and decided to build my own. It can’t be that hard right? Spoiler: there is a reason that the only schedule/calendar that I found was paid.</p><blockquote><em>Quick side note: I have since learned that there is a good-looking open source calendar component called </em><a href="https://fullcalendar.io/"><em>Full Calendar</em></a><em>. It is a freemium model though.</em></blockquote><p>The trouble arose as soon as I sat down and started thinking about how I wanted to render the events. I was planning on completely leaning on the grid system to manage placement. Once I started actually thinking through what “placement” means, I realized that the grid system was not going to cut it. I wanted everything to look similar to Google Calendar. That meant each hour would be displayed with borders around each hour to make it easier to see what hours events started and stopped. Then I wanted little boxes to represent the events and I wanted to shrink them along the horizontal axis if there were multiple events at the same time. The grid system is powerful, but I did not think it would reliably handle all that at once.</p><p>I did decide to use the grid for more “standard” purposes. To build out the background (hours in the day), I used a set of grids that controlled elements in a column that spanned the full width of the column with a set height in pixels. (Remember the set height part because that is relevant later on.) The full-width elements are separated by dividers that implement the hour dividers that make it easier to see where an event’s boundaries are. Directly on top of that “standard schedule grid” I placed the events.</p><p>After much thought about only the CSS portion of this component, I decided to position each event as absolute and calculate placement based on the other events around it. For those who are not CSS wizards (like me), absolute placement means that the element does not follow normal rules that place it relative to the elements that come before it but places itself exactly where it is told with respect to its surrounding/parent element. An absolutely positioned element will start with an origin (think cartesian coordinates) at the top leftmost point of its parent element. The positioning of the absolutely positioned element&#39;s top left corner is then handled by the CSS attributes top and left (there are also bottom and right but I did not use those to avoid confusing myself too much). Buckle in because the calculations to get the positioning attributes got tricky.</p><p>To be fair, the vertical calculation was not too difficult. Given a set height in pixels to represent an hour (or any set period really, just need a conversion rate) (remember this from the standard schedule grid?), it is fairly easy to find how far down to push an event. The calculation is the start time of the event minus the start time of the schedule converted to hours divided by the number of pixels that represent an hour. We are effectively converting time to pixels and finding the delta between the first time shown in the schedule and the start time of an event. That pixel value becomes the top attribute.</p><p>Now comes the piece of the puzzle that occupied my head for multiple days: calculating the horizontal positioning. At first glance, the problem does not seem too difficult. Just find which events overlap, shrink their widths accordingly and push some of them further to the right. Easy? No. Those are the key calculations to find, but finding them is tricky, and I went through several different algorithm iterations before I finally settled on one.</p><p>I kept a running list of notes and approaches that I thought about. I went through 5 different iterations of attempts and algorithms before I finally found the one currently in use. I’ll exclude write-ups of the failures. The algorithm that I eventually settled on involved matrices and basically recreating a full schedule in that matrix to find conflicts.</p><p>The first step was sorting the list of events first by start time and then the latest end time if the start times were the same. This gave the effect of stacking the longest events of an overlapping sequence on the left, which will probably make more sense once we get to the positional calculation.</p><p>Next came creating and seeding the matrix. The matrix is size n x n where n is the number of events with all indexes at an initial value of 0. Iterating through events in the sorted list, the matrix is seeded with a 1 starting at index i x i where i is the index of the entry in the sorted list. We then look at the events following event i for overlaps until we reach an event that does not overlap with event i. For each overlapping event j, seed 1 at index j x i. This results in a matrix that looks similar to the schedule we are rendering on the horizontal axis but is squished vertically.</p><p>With our seeded matrix, we want to iterate through each row and find the number of collisions. This is effectively summing the row (since entries occupying space are a 1). Update each 1 to the collisions on the row.</p><p>Now that we have the collisions, we can find the max collisions for each entry. This, once again, requires us to iterate through the matrix. Whenever we encounter a new max collision amount for a row, we mark its max collisions and its position in the row compared to the other overlapping events.</p><p>Now that we have the max collisions and positions of all entries we can calculate the respective widths and left offsets. The width of an entry expressed as a percentage is 100 / maxCollisions. The left offset expressed as a percentage is width (in px) * position.</p><p>Putting together the top and left calculations gives us the correct top left corner of a box that will represent an entry. The height and width calculations fill out the box&#39;s dimensions.</p><p>The following is pseudocode to calculate the vertical pieces to the puzzle.</p><pre>secondHeightInPx = 1 // example only, would set 1 second to 1 px in height<br>for entry in entries {<br>  timeDeltaInSeconds = entry.endTime - entry.startTime<br>  height = timeDeltaInSeconds * secondHeightInPx<br>  timeFromStartInSeconds = entry.startTime - earliestTimeRepresented<br>  topOffset = timeFromStartInSeconds * secondHeightInPx<br>}</pre><p>The following is pseudocode to calculate the horizontal pieces to the puzzle.</p><pre>entryMetadata = {}<br>sortedEntries = entries.sort((a, b) =&gt; {<br>  if a.startTime == b.startTime {<br>    return b.endTime - a.endTime<br>  }<br><br>  return a.startTime - b.startTime<br>})<br><br>entryLength = entries.length<br>matrix = createMatrix(entryLength, entryLength) // create nxn matrix with 0 values<br>for entry, index in sortedEntries {<br>  matrix[index][index] = 1<br>  for j = index + 1; j &lt; entryLength; j++ {<br>    if entry.endTime &gt; sortedEntries[j].endTime {<br>      matrix[j][index] = 1<br>    } else {<br>      break<br>    }<br>  }<br>}<br><br>matrix = matrix.map((row) =&gt; {<br>  collisions = row.sum()<br>  return row.map((entry) =&gt; {<br>    if entry == 0 {<br>      return 0<br>    } else {<br>      return collisions<br>    }<br>  })<br>})<br><br>for row in matrix {<br>  position = 0<br>  for entryCollisions, index in row {<br>    entryId = sortedEntries[index].id<br>    if entryCollisions &gt; entryMetadata[entryId].collisions {<br>      // found the max collisions<br>      entryMetadata[entryId].collisions = entryCollisions)<br>      entryMetadata[entryId].position = position<br>    }<br><br>    if entryCollisions &gt; 0 {<br>      position++<br>    }<br>  }<br>}</pre><p>This is a difficult thing to put into sentences, so if this was confusing, please let me know and I will try to clarify however I can. Also, I’m bad at writing pseudocode…I know.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/building-a-schedule-component"><em>https://thomasstep.com</em></a><em> on March 2, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dc33f33ca7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elsewhere API Architecture]]></title>
            <link>https://thomasstep.medium.com/elsewhere-api-architecture-991082f38e0f?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/991082f38e0f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Mon, 20 Feb 2023 00:00:22 GMT</pubDate>
            <atom:updated>2023-03-05T13:46:46.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1gdecsdxODrAP1Pf" /><figcaption>Photo by <a href="https://unsplash.com/@riccardo__oliva?utm_source=medium&amp;utm_medium=referral">riccardo oliva</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I recently remade <a href="https://elsewhere.thomasstep.com/">Elsewhere</a> from the <a href="https://thomasstep.com/blog/remaking-elsewhere">ground up</a>. A huge part of that effort was to redesign and rearchitect the API. While there was nothing inherently surprising about this API, I want to cement what I did similar to my <a href="https://thomasstep.com/blog/calendar-api-architecture">calendar API</a> and <a href="https://thomasstep.com/blog/papyrus-architecture">Papyrus</a>.</p><h3>Data Model</h3><p>The data model for the Elsewhere API is fairly straightforward although I did add a slight bit of complexity around trip ownership, which I will cover last. At the start, there are two entities that the data model and API care about and they are trips and entries. Trips and entries both directly correspond to their attributes stored. A trip is identified by a primary key corresponding to its ID, which is a GUID generated on creation, and a simple string serving as the secondary key: “config”. An entry is identified by a primary key of the trip’s ID it belongs to and a secondary key which is also a GUID generated on creation. The trip and entry items each contain attributes that nearly directly correspond to the API schema.</p><p>As I said, the data model gets somewhat strange when it comes to ownership of the trips. Since trips can be shared amongst travel partners, there needed to be some way to identify the owner/creator of the trip and any collaborators. I also wanted a way to read all the trips that a user owns and collaborates on. The authentication uses the bearer token strategy so I would be relying on the sub claim in the token to identify users. (I wanted to have the option to switch authentication providers in the future and sub is a required claim in any JWT.) The data model contains an item for each trip and the collaborators (including the owner) on that trip with duplication across all of those items. Cumbersome, I know.</p><p>I debated how I was going to model this relationship in DynamoDB. There are existing patterns for many-to-many relationships and the one that was closest to what I wanted to do would be <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html#bp-adjacency-lists">using an adjacency list</a>. My minor gripe with using an adjacency list is that I wanted to be able to verify that a user had access to a trip and get the trip information in one call to DynamoDB. Verifying access is possible with my model and an adjacency list using a GSI because we would simply attempt to get an item with a given trip ID and user ID to check that it exists. To get trip information, my model would simply look at the attributes of the read request that checked user authorization on a trip, since the trip information is duplicated across all of those items. Using an adjacency list with a GSI would mean that I need to make an additional read request for the trip-specific attributes or make a bulk read originally and throw out the trip-specific result if the user was not a collaborator (in the example from the earlier link in this paragraph, the item would have a key similar to PK: trip ID, SK: trip ID). With the GSI, I would also have additional writes to the GSI for any entry that is created, and there should be multitudes more entries created than trip updates since the only updateable attribute of a trip is its name.</p><p>My model is not unlike the adjacency list example, I just have more duplication. In short, I made a bet that there would be fewer overall writes by duplicating trip-specific information across all adjacencies compared to using a GSI like what is shown in the linked example. I want to make a clear disclaimer that I am far from a NoSQL master like Rick Houlihan or Alex DeBrie. I have a decent amount of exposure to different data models and I chose to take on the risk of blazing my own trail here. Is what I did a bad idea? Probably. Time will tell.</p><h3>API Design</h3><p>I made an OpenAPI document for this API. I surprised myself with that. I didn’t think I had it in me to be that formal with a side project. The API for Elsewhere is nothing special. There are two main entities: trips and entries. A user can own multiple trips and collaborate on multiple trips. Entries belong to trips and contain information such as location and time. I wanted to make Elsewhere super flexible so none of the properties are required for either trips or entries, which means that an entry can show up on the map view, the schedule view, neither, or both in the UI depending on how a user wants to represent something.</p><p>The operations that can be enacted on the entities are controlled by their respective HTTP methods: POST to create, GET to read, PUT to update, and DELETE to delete. Trips are a &quot;top-level&quot; entity so the endpoints are /trip and /trip/{tripId}. Since entries belong to trips, the endpoints help provide context for which trip entries are being worked on. The entry endpoints are /trip/{tripId}/entry and /trip/{tripId}/entry/{entryId}. Simple and straightforward.</p><h3>Wrap Up</h3><p>As I mentioned in the beginning there is nothing inherently surprising about this API, which is fine by me. The API is self-explanatory, and the only slight complexity is around the data model and how I handle the many-to-many relationship of users and trip collaboration. Nonetheless, I am happy that I was able to come back to this project and improve the API so much. Cleaning the endpoints up and using a technology stack that I am now very familiar with helped a ton. Having a clean API also made thinking about the UI that much easier. I am not a frontend engineer, but I wanted the opportunity to try my hand at it. Knowing that the API was not fragile helped me when it came to making resilient components and designing how I wanted to display trip information.</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/elsewhere-api-architecture"><em>https://thomasstep.com</em></a><em> on February 20, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=991082f38e0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Remaking Elsewhere]]></title>
            <link>https://thomasstep.medium.com/remaking-elsewhere-3d1ef4320249?source=rss-8d6f2871c893------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1ef4320249</guid>
            <category><![CDATA[planning]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Thomas Step]]></dc:creator>
            <pubDate>Thu, 16 Feb 2023 00:00:52 GMT</pubDate>
            <atom:updated>2023-03-03T12:41:27.056Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ehkb2FAwKvfG7SCC" /><figcaption>Photo by <a href="https://unsplash.com/@anniespratt?utm_source=medium&amp;utm_medium=referral">Annie Spratt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I recently decided to swing back around to <a href="https://elsewhere.thomasstep.com/">Elsewhere</a>. Probably because post-COVID travel has picked back up, so I have been planning more trips and wanted to scratch that itch again. Elsewhere was the first web app that I ever made by myself. The first API, UI, idea, everything. I have since made plenty more <a href="https://thomasstep.com/projects">things</a> that are online.</p><p>When I started Elsewhere, the idea was to make an app that converged all the software that I used to plan a trip into one. Mostly that meant Google Maps and some form of a spreadsheet. The map was used to keep track of places that I wanted to go and the spreadsheet was for jotting down notes about those places and planning the timing, the actual itinerary. I didn’t need those technologies for all the wonderful things that they can be used for, I needed a very small subset, mostly revolving around being a data store for my ideas before they were fully fleshed out.</p><p>With my idea in place, next came the technology. I knew what AWS was, and I had also heard the tales of how expensive it could get. My frugal, bootstrapping self did not want to wake up to a surprise bill. (In hindsight the problem was that I did not fully understand AWS and how pricing worked.) So I decided to look around online at an ideally, free hosting solution. Something popped out. At the time it was called Now but it is now known as Vercel, and they hosted a framework that they made called Next.js. I could host a frontend React app and a backend for free? Sold. On top of that (or behind it?) I used MongoDB’s free database. (It is worth noting that this was my first exposure to NoSQL and I knew nothing about it.)</p><p>My original idea for Elsewhere still stands but the technology choices do not. I ended up completely rebuilding Elsewhere from the ground up. Gone are the days of a strangely cobbled together, Next.js-hosted, GraphQL backend. Gone is the free MongoDB instance (although I think it would probably still be a good choice). Gone is the poor state management in the front end. In comes the new and improved tech stack. The UI has also been completely rethought and I want to spend some time later discussing that aspect of the project.</p><p>The first major shift in the new version of Elsewhere was to move off of the native auth onto my <a href="https://github.com/thomasstep/authentication-service">authentication service</a>. That meant no more social login but also a faster and cleaner experience both for users and for me. I originally based my many iterations of the authentication service on Elsewhere’s auth so it only seemed fitting.</p><p>The next major shift was the backend. I moved to a fully serverless, AWS-powered backend with my usual stack of API Gateway, Lambda, DynamoDB, and SNS. Everything is defined with the CDK. At this point, I have so much CDK code that I have probably already written just about anything that I want. The Lambdas are written in Go to minimize cold start times and overall latency just like the authentication service. The data model is slightly wild and not exactly what I was hoping for, but what are you going to do 🤷. And SNS facilitates any of the background processing I need. The API itself was completely redesigned with different levels of entities in place. Having a well-thought-out API made hooking up the frontend so much easier. I don’t want to get too into the weeds with the backend right now because I am planning on writing a separate post about the API’s architecture. Edit: Linking <a href="https://thomasstep.com/blog/elsewhere-api-architecture">the architecture post</a> I wrote.</p><p>Moving up the stack, the frontend has been almost completely redone. I am still using Next.js hosted on Vercel, but I went from Next.js version 9 to version 13. Luckily, there were not too many changes involved with that version jump. I was also able to lose quite a few dependencies that I simply didn’t need anymore. I had originally used Material UI and heavily modified and styled it. I jumped from MUI version 3 to version 5 and scaled back a lot of my poor design choices in favor of MUI defaults. This package’s version change did involve code changes on my end, particularly around theming and styling. Most of the components were still available with the same props too, but I had to track down some tricky prop name changes.</p><p>Once I figured out the frontend technology, I moved on to the design of the UI. Overall, the design feels much less cramped and easier to interact with. I used to walk on eggshells when I used the old app because I was worried about breaking something. Now, I feel much more confident in how the state is managed and how everything interacts with each other. I also added a view for a schedule, which was probably the single hardest piece of software I had to write for all of this. I had wanted to add a scheduling view since I last stopped developing Elsewhere and never got back around to doing it until now. I knew I wanted to completely remake the API before attempting anything in the UI, which is what slowed me down. The most difficult part of the schedule was planning out how to place events with overlapping times. I am planning on writing a dedicated post about the scheduling view and how I wrote the algorithm to accomplish it, so I won’t get too technical here. Edit: Linking <a href="https://thomasstep.com/blog/building-a-schedule-component">the schedule component post</a> I wrote.</p><p>The latest and greatest iteration of Elsewhere is <a href="https://elsewhere.thomasstep.com/">now live</a>! I am pleased with the outcome of my work and I am much keener to show this iteration off than the last one. There is still improvement to be made. I will be testing and improving as I go, and if anyone else uses it and wants to suggest improvements or features, please do. I can be reached at thomas@thomasstep.com or tstep916@gmail.com. I would be happy to hear any feedback!</p><p><em>Originally published at </em><a href="https://thomasstep.com/blog/remaking-elsewhere"><em>https://thomasstep.com</em></a><em> on February 16, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1ef4320249" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>