PenguinMod / PenguinMod-Home

A main dashboard page featuring community projects and featured content.
https://penguinmod.com
21 stars 45 forks source link

Refractored code for the admin force view profile button (use if possible) (refractored with chatgpt) #83

Closed Rubiidev-18 closed 4 months ago

Rubiidev-18 commented 4 months ago
{#if (($projects.length > 0 && $fetchedFullProfile) || $isForceView) && 
    ((!($projects[0] !== "none" && $wasNotFound)) &&
    (($projects[0] !== "none" || $isDonator || $fullProfile.bio || $isFollowingUser || $fullProfile.rank > 0) || ($loggedIn && $user === $loggedInUser)) || $isForceView)}
    <div class="background">
        {#if $user}
            <div class="section-user">
                <!-- Your UI elements here -->
                <Button on:click={() => $isForceView = true}>
                    (Admin) Force view profile
                </Button>
            </div>
        {/if}
    </div>
{/if}

Edit: better version:

{#if ($fetchedFullProfile || $isForceView) && (!$wasNotFound || $projects[0] !== "none" || $isDonator || $fullProfile.bio || $isFollowingUser || $fullProfile.rank > 0 || ($loggedIn && $user === $loggedInUser))}
    <div class="background">
        {#if $user}
            <div class="section-user">
                <Button on:click={() => $isForceView = true}>(Admin) Force view profile</Button>
            </div>
        {/if}
    </div>
{/if}

<script>
    // Memoization
    let shouldRenderProfile = false;
    $: shouldRenderProfile = computeShouldRenderProfile();
    function computeShouldRenderProfile() {
        // Expensive computations
    }
</script>

<style>
    /* CSS styles */
</style>
Ianyourgod commented 4 months ago

maybe don’t use chatgpt

Ianyourgod commented 4 months ago

this isn’t even refactored, there’s just a “// expensive computations” if you want to make changes, please do so yourself, not with an ai

RedMan13 commented 4 months ago

yeah I don't see any reason to memoize a single if statement also the actual better way would probably be to make none of the if statements compare anything and jus have a single variable that controls if it's showing or not so that there's less info to recheck and less of the same check repeated everywhere