Glimesh / glimesh.tv

Glimesh is a next generation live streaming platform built by the community, for the community.
https://glimesh.tv
Other
465 stars 77 forks source link

Charity Code for Homepage #854

Closed clone1018 closed 2 years ago

clone1018 commented 2 years ago

In case we need it, here's the code we used for The Trevor Project during our Glimesh Community Pride event.

<!-- Donation HTML Template -->

<div class="pride_bg">
    <div class="mt-4 text-center" style="font-family: Roboto;">
        <br>
        <br>
        <div class="font-weight-bold pride_font">
          Glimesh Community Pride
        </div>
        <div class="font-weight-bold pride_font_sub">
          Raising funds and awareness for The Trevor Project this June
        </div>
      </div>

      <br>
      <div class="text-center">
        <a
          href="https://donate.tiltify.com/+glimesh/glimpride"
          target="_blank"
          class="btn btn-lg font-weight-bold shadow-lg text-light bg-success"
        >
          Donate Here
        </a>
        <a
          href="https://www.thetrevorproject.org/"
          target="_blank"
          class="btn btn-lg font-weight-bold shadow-lg text-light bg-TrevorProject"
        >
          About the Trevor Project
        </a>
        <a
          href="https://docs.google.com/forms/d/e/1FAIpQLSfCKGswVF8OptjwTz1DR0ithA3wwcARivMH9Dr3UOdfHdM70A/viewform"
          target="_blank"
          class="btn btn-lg font-weight-bold shadow-lg text-light bg-info"
        >
          Host An Event
        </a>
      </div>

      <div class="container my-4" style="max-width: 600px">
        <p class="text-center font-weight-bold pride_font_raised">
          Amount Raised: ${format_price(@total_raised)} of
          {#if @start_goal_amount !== @final_goal_amount}
            <span class="crossthrough">${format_price(@start_goal_amount)}</span> <span style="font-size: 30px;">${format_price(@final_goal_amount)}!</span>
          {#else}
            <span style="font-size: 30px;">${format_price(@final_goal_amount)}!</span>
          {/if}
        </p>
        <div class="progress shadow" style="height: 32px;">
          <div
            class="progress-bar bg-warning lead text-dark progress-bar-striped progress-bar-animated"
            role="progressbar"
            aria-valuenow={@total_raised}
            aria-valuemin="0"
            aria-valuemax={@final_goal_amount}
            style={"width: #{@total_raised / @final_goal_amount * 100}%;"}
          >
            ${format_price(@total_raised)} of ${format_price(@final_goal_amount)}
          </div>
        </div>
    </div>
</div>
<!-- elixir -->

    [total_raised, start_goal_amount, final_goal_amount] = get_tiltify_donation_total()

     |> assign(:total_raised, total_raised)
     |> assign(:start_goal_amount, start_goal_amount)
     |> assign(:final_goal_amount, final_goal_amount)

  def get_tiltify_donation_total do
    access_token = Application.get_env(:glimesh, :tiltify_access_token)

    QueryCache.get_and_store!(
      "GlimeshWeb.HomepageLive.get_tiltify_donation_total()",
      fn ->
        with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
               HTTPoison.get(
                 "https://tiltify.com/api/v3/campaigns/171961",
                 [
                   {"Authorization", "Bearer #{access_token}"},
                   {"Content-Type", "application/json"}
                 ]
               ),
             {:ok, response} <- Jason.decode(body),
             %{
               "data" => %{
                 "totalAmountRaised" => amount_raised,
                 "fundraiserGoalAmount" => final_goal,
                 "originalFundraiserGoal" => original_goal
               }
             } <- response do
          {:ok, [amount_raised * 100, original_goal * 100, final_goal * 100]}
        else
          _ ->
            {:ok, [0, 500, 1000]}
        end
      end
    )
  end