public inbox for [email protected]
 help / color / mirror / Atom feed
From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>,
	Arthur Lapz <[email protected]>, Memet Zx <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: Re: [PATCH v2 11/11] feat(page): implement chat bubble message rendering
Date: Sun, 24 Sep 2023 16:37:19 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 24/09/2023 02.26, Ammar Faizi wrote:
> On Sat, Sep 23, 2023 at 04:15:14PM +0700, Muhammad Rizki wrote:
>> +      function hashCode(name) {
>> +        var hash = 0;
>> +        for (var i = 0; i < name.length; i++) {
>> +            var character = name.charCodeAt(i);
>> +            hash = ((hash<<5)-hash)+character;
>> +            hash = hash & hash;
> 
> This is useless. `hash & hash` is always equal to `hash`. What are you even doing?

Yeah, didn't focus on that thing, I was copy & paste from the reference.

> 
>> +        }
>> +        return Math.abs(hash);
>> +      }
>> +
>> +      function getFixedRandomColor(name) {
>> +        const textColors = [
>> +          "text-red-400",      "text-yellow-400",
>> +          "text-blue-400",     "text-sky-400",
>> +          "text-purple-400",   "text-orange-400",
>> +          "text-amber-400",    "text-lime-400",
>> +          "text-green-400",    "text-emerald-400",
>> +          "text-teal-400",     "text-cyan-400",
>> +          "text-indigo-400",   "text-violet-400",
>> +          "text-fuchsia-400",  "text-pink-400",
>> +          "text-rose-400"
>> +        ];
>> +        const borderColors = [
>> +          "border-red-400",      "border-yellow-400",
>> +          "border-blue-400",     "border-sky-400",
>> +          "border-purple-400",   "border-orange-400",
>> +          "border-amber-400",    "border-lime-400",
>> +          "border-green-400",    "border-emerald-400",
>> +          "border-teal-400",     "border-cyan-400",
>> +          "border-indigo-400",   "border-violet-400",
>> +          "border-fuchsia-400",  "border-pink-400",
>> +          "border-rose-400"
>> +        ];
>> +
>> +        const indexColor = hashCode(name) % textColors.length;
>> +        return [ textColors[indexColor], borderColors[indexColor] ];
>> +      }
> 
> Don't repeat yourself (DRY). Simplify it like:
> ```
>    function getFixedRandomColor(name) {
>        const colors = [
>            "red", "yellow", "blue", "sky", "purple", "orange",
>            "amber", "lime", "green", "emerald", "teal", "cyan",
>            "indigo", "violet", "fuchsia", "pink", "rose"
>        ];
> 
>        const c = colors[hashCode(name) % colors.length];
>        return [
>           "text-" + c + "-400",
>           "border-" + c + "-400",
>        ];
>    }
> ```
> 
>    [ Untested, may contain a mistake, but you get the idea. ]
> 

Yeah, it worked. I tought this doesn't work because tailwind doesn't 
support dynamic class names, but this is worked so I will use this.

  reply	other threads:[~2023-09-24  9:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23  9:15 [PATCH v2 00/11] Refactoring and Add New Features Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 01/11] style: remove extra newline at end of file Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 02/11] feat(static/img): add `profile-cover.jpg` Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 03/11] refactor(page): improve page design and add profile image cover Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 04/11] feat(page): improve UX for copying text Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 05/11] chore(page): add newlines to enhance Developer Experience Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 06/11] feat(page): add GNUWeeb member list UI Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 07/11] feat(page): add `getOrgMembers()` function Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 08/11] feat(page): add `renderMemberList()` function Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 09/11] feat(page): add initial UI for displaying recent group messages Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 10/11] feat(css): add initial CSS class styles for chat bubbles Muhammad Rizki
2023-09-23  9:15 ` [PATCH v2 11/11] feat(page): implement chat bubble message rendering Muhammad Rizki
2023-09-23 19:26   ` Ammar Faizi
2023-09-24  9:37     ` Muhammad Rizki [this message]
2023-09-23 19:35   ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox