Skip to content

Commit

Permalink
uhhh what
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkatty committed Jan 3, 2025
1 parent 70d50c0 commit a0e0e0d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 99 deletions.
79 changes: 0 additions & 79 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class SpotifyAPI {
document.querySelector('.spotify-modal').classList.remove('show');
}

<<<<<<< HEAD
async checkUserSession() {
try {
const response = await fetch('get_prefrences.php', {
Expand All @@ -62,30 +61,18 @@ class SpotifyAPI {
}
}

=======
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
// Initialize the API by handling authentication
async init() {
try {
const params = new URLSearchParams(window.location.search);
const code = params.get('code');
<<<<<<< HEAD

// Check if we have valid tokens
const hasValidTokens = this.accessToken &&
this.refreshToken &&
this.tokenExpiry &&
new Date().getTime() < this.tokenExpiry;

=======

// Check if we have valid tokens
const hasValidTokens = this.accessToken &&
this.refreshToken &&
this.tokenExpiry &&
new Date().getTime() < this.tokenExpiry;

>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
if (code) {
await this.getAccessToken(code);
window.history.replaceState({}, document.title, REDIRECT_URI);
Expand All @@ -100,7 +87,6 @@ class SpotifyAPI {
localStorage.clear(); // Clear any stale tokens
this.showModal();
}
<<<<<<< HEAD

const isSignedIn = await this.checkUserSession();
this.updateProfileIcon(isSignedIn);
Expand All @@ -116,11 +102,6 @@ class SpotifyAPI {
profileIcon.style.backgroundImage = 'url("https://via.placeholder.com/150")';
} else {
profileIcon.innerHTML = '<a href="login.html">Sign In</a>';
=======
} catch (error) {
console.error('Init error:', error);
this.showModal();
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
}
}

Expand All @@ -129,11 +110,7 @@ class SpotifyAPI {
try {
// Clear any existing tokens
localStorage.clear();
<<<<<<< HEAD

=======

>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
const state = Math.random().toString(36).substring(7);
localStorage.setItem('spotify_auth_state', state);

Expand All @@ -143,11 +120,7 @@ class SpotifyAPI {
url.searchParams.append('redirect_uri', REDIRECT_URI);
url.searchParams.append('state', state);
url.searchParams.append('scope', SCOPES);
<<<<<<< HEAD

=======

>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
console.log('Redirecting to Spotify auth...');
window.location.href = url.toString();
} catch (error) {
Expand Down Expand Up @@ -277,7 +250,6 @@ class SpotifyAPI {
this.showModal();
throw error;
}
<<<<<<< HEAD
}

async getUserPreferences() {
Expand All @@ -291,13 +263,10 @@ class SpotifyAPI {
console.error('Error fetching preferences:', error);
return [];
}
=======
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
}

// Load recommended & popular tracks by user preferences
async loadDefaultView() {
<<<<<<< HEAD
try {
const userPreferences = await this.getUserPreferences();
let seedGenres = userPreferences.length > 0 ?
Expand All @@ -307,13 +276,6 @@ class SpotifyAPI {
this.toggleSectionVisibility(false);

// First load recommended tracks
=======
let seedGenres = 'pop,rock'; // Default genres
this.toggleSectionVisibility(false);

try {
// Load recommended tracks
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
const recommendedResponse = await this.fetchWithTokenRefresh(
`https://api.spotify.com/v1/search?q=genre:${encodeURIComponent(seedGenres)}&type=track&limit=15`,
{ method: "GET" }
Expand All @@ -324,7 +286,6 @@ class SpotifyAPI {
}

const recommendedData = await recommendedResponse.json();
<<<<<<< HEAD
console.log('Recommended tracks:', recommendedData.tracks?.items?.length);

// If no recommended tracks, search by genres
Expand Down Expand Up @@ -365,14 +326,6 @@ class SpotifyAPI {

const discoverResponse = await this.fetchWithTokenRefresh(
`https://api.spotify.com/v1/search?q=genre:${encodeURIComponent(randomGenre)}&type=track&limit=15`,
=======
this.displaySearchResults(recommendedData.tracks?.items || [], 'recommended-grid');
// Load discover tracks with random genre
const randomGenre = DISCOVER_GENRES[Math.floor(Math.random() * DISCOVER_GENRES.length)];
const discoverResponse = await this.fetchWithTokenRefresh(
`https://api.spotify.com/v1/search?q=genre:${randomGenre}&type=track&limit=15`,
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
{ method: "GET" }
);

Expand All @@ -381,7 +334,6 @@ class SpotifyAPI {
}

const discoverData = await discoverResponse.json();
<<<<<<< HEAD
console.log('Discover tracks:', discoverData.tracks?.items?.length);

const discoverGrid = document.getElementById('discover-new-grid');
Expand All @@ -393,9 +345,6 @@ class SpotifyAPI {
discoverGrid.style.display = 'grid';
await this.displaySearchResults(discoverData.tracks?.items || [], 'discover-new-grid');

=======
this.displaySearchResults(discoverData.tracks?.items || [], 'discover-new-grid');
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
} catch (error) {
console.error("Error loading default view:", error);
}
Expand All @@ -411,20 +360,14 @@ class SpotifyAPI {
return;
}

<<<<<<< HEAD
for (const track of tracks) {
if (!track) continue;
=======
tracks.forEach(async (track) => {
if (!track) return;
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
const artUrl = track.album?.images?.[0]?.url || DEFAULT_ALBUM_ART;

// Fetch artist information to get genre
const artistId = track.artists[0]?.id;
let genre = 'unknown';
if (artistId) {
<<<<<<< HEAD
try {
const artistResponse = await this.fetchWithTokenRefresh(
`https://api.spotify.com/v1/artists/${artistId}`,
Expand All @@ -436,15 +379,6 @@ class SpotifyAPI {
}
} catch (error) {
console.error(`Error fetching artist data for ID ${artistId}:`, error);
=======
const artistResponse = await this.fetchWithTokenRefresh(
`https://api.spotify.com/v1/artists/${artistId}`,
{ method: "GET" }
);
if (artistResponse.ok) {
const artistData = await artistResponse.json();
genre = artistData.genres[0] || 'unknown';
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
}
}

Expand Down Expand Up @@ -479,13 +413,8 @@ class SpotifyAPI {
heartButtons.forEach(button => {
button.addEventListener('click', async (e) => {
const genre = e.target.dataset.genre;
<<<<<<< HEAD
console.log('Heart button clicked:', genre); // Debug log
await this.heartTrack(genre);
=======
await this.heartTrack(genre);
console.log(genre);
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
});
});
}
Expand All @@ -503,10 +432,6 @@ class SpotifyAPI {
const data = await response.json();
if (data.success) {
console.log('Genre preference updated successfully');
<<<<<<< HEAD
=======
this.loadDefaultView(); // Reload view with updated preferences
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
} else {
console.error('Error updating genre preference:', data.message);
}
Expand Down Expand Up @@ -544,11 +469,7 @@ class SpotifyAPI {
const recommendedTitle = document.querySelector('h2:first-of-type');
const discoverTitle = document.querySelector('h2:last-of-type');
const discoverGrid = document.getElementById('discover-new-grid');
<<<<<<< HEAD

=======

>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
if (isSearching) {
recommendedTitle.textContent = 'Search Results';
discoverTitle.style.display = 'none';
Expand Down
20 changes: 0 additions & 20 deletions signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
}

.form-group input {
<<<<<<< HEAD
width: 90%;
=======
width: 100%;
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
padding: 12px;
border: none;
border-radius: 8px;
Expand Down Expand Up @@ -117,7 +113,6 @@
color: white;
font-family: 'Inter', sans-serif;
}
<<<<<<< HEAD

.error-message {
color: #ff4444;
Expand All @@ -128,8 +123,6 @@
font-family: 'Inter', sans-serif;
display: none;
}
=======
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
</style>
</head>
<body>
Expand All @@ -147,23 +140,13 @@

<div class="signup-container">
<h2>Create Account</h2>
<<<<<<< HEAD
<div id="errorMessage" class="error-message">You don't have an account yet. Please sign up.</div>
=======
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
<form action="signup.php" method="POST" id="signupForm">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<<<<<<< HEAD
=======
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
Expand Down Expand Up @@ -238,16 +221,13 @@ <h3>Music Preferences</h3>
return;
}
});
<<<<<<< HEAD

// Add at the end of the script
const urlParams = new URLSearchParams(window.location.search);
const errorMsg = document.getElementById('errorMessage');
if (urlParams.get('error') === '1') {
errorMsg.style.display = 'block';
}
=======
>>>>>>> e229d951b9406629859f95d5053aa6f16049af2f
</script>
</body>
</html>

0 comments on commit a0e0e0d

Please sign in to comment.