summaryrefslogtreecommitdiff
path: root/src/routes/team/index.svelte
blob: d3c4549584b78d543adf54da6f05a8cac024c10a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script>
  import PersonCard from './PersonCard.svelte';  

  import { onMount } from 'svelte';
  import { supabase } from '$lib/supabase';

  const getPeople = async () => {
    const { data, error } = await supabase.from('people').select();
    if (!error) {
      return data;
    }
    return [];
  }

  const mapImages = (people) => {
    return people.map((x) => {
      const { publicURL, error } = supabase
        .storage
        .from('mistymountains')
        .getPublicUrl(x.image);
      if (!error) {
        return { ...x, image: publicURL };
      }
      return x;
    });
  }

  let people = [];
  onMount(async () => {
    people = await getPeople().then(mapImages);
  });
</script>

<main>
  {#if people.length}
    {#each people as person, i}
      <div class="row">
        <PersonCard person={person} direction={i % 2 ? 'left' : 'right'} />
      </div>
    {/each}
  {/if}
</main>