Skip to content

Commit

Permalink
added list user functionality, SvelteButton component
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Rebs committed Nov 24, 2022
1 parent 35637bd commit 949194a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/lib/SvelteButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang="ts">
export let buttonItem, action;
</script>

<button on:click={action}
class="transition ease-in-out delay-10 hover:-translate-y-1 hover:scale-110 duration-300 bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow shadow-lg shadow-cyan-500/50"
>{buttonItem}</button>
15 changes: 0 additions & 15 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
<script>
import { onMount } from "svelte";
import axios from "axios";
let quotes = [];
let error = null;
onMount(async () => {
try {
const res = await axios.get(
"https://music-tonic.herokuapp.com/client1-rest/listUsers"
);
quotes = res.data;
} catch (e) {
error = e;
}
});
</script>

<div class="bg-lime-300 px-6 py-6 opacity-80 hover:opacity-100 transition-opacity">
Expand Down
54 changes: 50 additions & 4 deletions src/routes/admin/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
<h1>Admin</h1>
<script>
import axios from "axios";
import SvelteButton from "../../lib/SvelteButton.svelte";
let listUsersCallCount = 0;
let userList = [];
async function listUsers() {
let error = null;
try {
const res = await axios.get(
"https://music-tonic.herokuapp.com/client1-rest/listUsers"
);
userList = res.data;
listUsersCallCount += 1;
console.log("user list retrieved as:", userList);
return userList;
} catch (e) {
error = e;
listUsersCallCount += 1;
return ["Bad request"];
}
}
</script>

<button>list users</button>
<button>add user</button>
<button>delete user</button>
<h1 class="text-lg w-screen text-center mx-auto font-bold">Admin</h1>
<div class="px-4 py-4 auto-cols-auto">
<div class="px-4 py-4">
<SvelteButton buttonItem="list users" action={listUsers} />
<div class="px-4 py-4">
{#key listUsersCallCount}
<ul>
{#each userList as { userId, realName, userType, mainGenre, age }}
<li>
userId: {userId} Name: {realName} userType: {userType} mainGenre: {mainGenre}
age:{age}
</li>
{/each}
</ul>
{/key}
</div>
</div>
<div class="px-4 py-4">
<SvelteButton buttonItem="add user" action={listUsers} />
<div class="px-4 py-4">
</div>
</div>
<div class="px-4 py-4">
<SvelteButton buttonItem="delete user" action={listUsers} />
<div class="px-4 py-4">
</div>
</div>
</div>

1 comment on commit 949194a

@vercel
Copy link

@vercel vercel bot commented on 949194a Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mean-rice – ./

mean-rice.vercel.app
mean-rice-j-rebs.vercel.app
mean-rice-git-main-j-rebs.vercel.app

Please sign in to comment.