Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackathon-1 #5

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_CLIENT_ID=""
VITE_CLIENT_SECRET=""
VITE_CALLBACK_URL="http://localhost:5173/"
VITE_CALLBACK_URL="http://localhost:5173/callback"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Make sure you go through this checklist before submitting your project to Moodle
- [Animate.css](https://animate.style/) - Just-add-water CSS animations
- [Spotify-web-api-js](https://www.npmjs.com/package/spotify-web-api-js)

## Tutorials & Reading material

- [storing tokens](https://blog.ropnop.com/storing-tokens-in-browser/)

## Authors

- Ali Nough (@AliNough)
Expand Down
31 changes: 31 additions & 0 deletions callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bragi Mix</title>
<script type="module" src="/js/callback.js"></script>
<link rel="stylesheet" href="/style.css" />
</head>
<body>
<header class="l-header">
<section class="l-container l-content">
<h1>Login</h1>
</section>
</header>

<main class="l-main">
<article class="l-container">
<p>You should be automatically redirect to the home page</p>
<p>If not please click the button below</p>

<a class="button" href="/index.html">Go Back</a>
</article>
</main>

<footer class="l-footer">
<section class="l-container">Made by Alex, Ali & Mo</section>
</footer>
</body>
</html>
41 changes: 41 additions & 0 deletions components/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Header extends HTMLElement {
constructor() {
super();

this.attachShadow({ mode: "open" });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
}
.is-active {
color: green;
}
</style>
<div class="u-row c-nav-controls">
<h1><slot></slot></h1>
<div class="u-row">
<nav>
<a href="/">Home</a>
<a href="/randomizer">Randomizer</a>
</nav>

<button id="js-logout-btn" data-is-protected="true">Log out</button>
</div>
</div>
`;

const currentUrl = window.location.pathname;

const links = this.shadowRoot.querySelectorAll("a");

links.forEach((link) => {
if (currentUrl.includes(link.pathname) && link.pathname !== "/") {
link.classList.add("is-active");
return;
}
});
}
}

customElements.define("custom-header", Header);
9 changes: 0 additions & 9 deletions counter.js

This file was deleted.

14 changes: 14 additions & 0 deletions css/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@
box-shadow: var(--shadow-3);
margin: var(--size-2) 0;
}

.c-nav-controls {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
}

.c-song-preview-window {
width: 80%;
height: 80%;
min-height: 20vh;
margin-top: 3em;
}
5 changes: 5 additions & 0 deletions css/utilities.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
.is-visible {
opacity: 1;
}

.u-row {
display: flex;
flex-direction: row;
}
32 changes: 17 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script type="module" src="/main.js"></script>
<title>Bragi Mix</title>
<script type="module" src="/components/Header.js"></script>
<script type="module" defer src="/main.js"></script>
<script type="module" defer src="/js/index.js"></script>
<link rel="stylesheet" href="/style.css" />
</head>
<body>
<header class="l-header">
<section class="l-container">
<h1>Home</h1>
<div class="c-nav-controls">
<h1>Home</h1>

<nav>
<a href="/">Home</a>
<a href="/about">About</a>
<!-- <a href="/randSong.html">Randomizer</a> -->
</nav>
<div class="u-row">
<nav>
<a href="/">Home</a>
<a href="/randomizer.html">Randomizer</a>
</nav>

<button id="js-login-btn">Sign In</button>
<button id="js-logout-btn" data-is-protected="true">Log out</button>
</div>
</div>
</section>
</header>

<main class="l-main l-content">
<section id="js-rand-nav-holder" class="l-container"></section>
<section id="js-login-holder" class="l-container">
<div class="">
<h2>Login into your Spotify</h2>
<button id="js-login-btn">login</button>
</div>
</section>

<section class="l-container">
<section class="l-container" data-is-protected="true">
<form id="js-seach-form" class="c-form">
<div>
<label for="genre">genre</label>
Expand Down
53 changes: 0 additions & 53 deletions js/app.js

This file was deleted.

10 changes: 10 additions & 0 deletions js/callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { manageUserSessssion } from "./session.js";

/*
============================================
Callback page specfic code
============================================
*/

manageUserSessssion();
window.location.replace("/index.html");
31 changes: 31 additions & 0 deletions js/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
============================================
Helper functions
https://github.com/S3ak/fed-javascript1-api-calls/blob/main/examples/games.html#L154
============================================
*/

// TODO: Create a function that renders the playlists
export function renderPlaylist({ title = "No title" }) {
return `
<div class="c-card">
<h3>${title}</h3>
</div>
`;
}

export function hideProtectedContent(isLoggedIn) {
const protectedContent = document.querySelectorAll("[data-is-protected]");

if (isLoggedIn) {
protectedContent.forEach((content) => {
content.classList.remove("is-hidden");
});

return;
}

protectedContent.forEach((content) => {
content.classList.add("is-hidden");
});
}
27 changes: 27 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { renderPlaylist } from "./helpers.js";

import s from "../main.js";

const playlistContainerEl = document.querySelector("#js-playlist-list");

document.querySelector("#js-seach-form").addEventListener("submit", (event) => {
event.preventDefault();

const genre = event.target.querySelector("#genre").value;
s.searchPlaylists(genre)
.then((data) => {
const playlists = data.playlists.items;
console.log(playlists);

playlistContainerEl.innerHTML = "";

playlists.forEach((playlist) => {
playlistContainerEl.innerHTML += renderPlaylist({
title: playlist.name,
});
});
})
.catch((error) => {
console.log(error);
});
});
11 changes: 11 additions & 0 deletions js/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { loginSpotifyUser } from "./session.js";

/*
============================================
Login page specfic code
============================================
*/

const loginBtnEl = document.querySelector("#js-login-btn");

loginBtnEl.addEventListener("click", loginSpotifyUser);
20 changes: 11 additions & 9 deletions js/randomize.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import Spotify from "spotify-web-api-js";
// import Spotify from "../node_modules/spotify-web-api-js/src/typings/spotify-web-api";
import s from "../main.js";

const generateBtn = document.querySelector("#js-gnrt-btn");
const resultHolder = document.querySelector("#js-res-holder");
const yearInput = document.querySelector("#js-yr-input");
console.log(resultHolder);
const songPreview = document.querySelector("#js-iframe");
// const yearInput = document.querySelector("#js-yr-input");

generateBtn.addEventListener("click", () => {
randomizer(yearInput.value);
getSong();
});

const accessToken = localStorage.getItem("access_token");
console.log(accessToken);
function getSong() {
s.searchTracks("chill", { market: "NO" }).then((data) => {
console.log(data);
const song = data.tracks.items[0].preview_url;
songPreview.src = song;
});
}

const dataBase = new Spotify();
console.log(dataBase);
// const accessToken = new URLSearchParams(
// window.location.hash.replace("#", "")
// ).get("access_token");
Expand Down
Loading