Skip to content

Commit

Permalink
display games and shirts in my/create fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
singharaj-usai committed Oct 18, 2024
1 parent 326ccff commit cd892a1
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 152 deletions.
24 changes: 21 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
MONGODB_URI=mongodb+srv://usais:[email protected]/
JWT_SECRET=your_very_long_and_secure_random_string_here

MAINTENANCE_MODE=false
MAINTENANCE_MODE=true

MAINTENANCE_SECRET_KEY=mrbobbillyssecretkey
ENCRYPTION_KEY=BTFXRj0jrxSbaTKOj+aUVw3wPBIFKCx2/qveUxaIErJuVNDEXz9wvXmPuYAInkUS

UPLOAD_ACCESS_KEY=518484

MAILCHIMP_API_KEY=8bdf84c00e127f26802a94474aa96bdf-us17
MAILCHIMP_SERVER_PREFIX=https://us17.admin.mailchimp.com/
MAILCHIMP_LIST_ID=bee92a5a1e

EMAIL_USERNAME=support@valk.fun
EMAIL_FROM_NAME=Valkyrie Support
EMAIL_USERNAME=support@alphablox.net
EMAIL_FROM_NAME=Alphablox Support
GOOGLE_CLIENT_ID=914198737416-ib8t5ejpv3kidadqlmi0q3dap9g10eih.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=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
GOOGLE_REFRESH_TOKEN=1//04SMY1UGhY3HMCgYIARAAGAQSNwF-L9IrAavadS_tNXtDaHhBQhTcOuD0fo38j-jJ4AzWx7MsoOdc9fXoApn5VTeTc559W0PN7Zw
GOOGLE_REDIRECT_URI=https://developers.google.com/oauthplayground

AWS_ACCESS_KEY_ID=AKIAQ4J5YFDU7HIC2XMC
AWS_SECRET_ACCESS_KEY=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
AWS_REGION=us-east-2
AWS_S3_BUCKET_NAME=c2.rblx18.com

BASE_URL=www.valk.fun

EMAIL_USER=[email protected]
EMAIL_PASS=iazx mivw xuhi ixcq


CLOUDFLARE_SECRET_KEY=0x4AAAAAAAw6-naWF42EyvhyITGX4NRuBqc
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ web_modules/
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

.cursorrules
# Next.js build output
.next
out
Expand Down
1 change: 1 addition & 0 deletions client/html/pages/my/create/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

<!-- Main Content -->
<div class="container" style="margin-top: 70px">
<div id="error-container"></div>
<div class="row">
<div class="col-md-2">
<!-- Sidebar -->
Expand Down
98 changes: 41 additions & 57 deletions client/js/components/user-games.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ function displayPlacesPanel(user) {
`;

$('#user-places-panel').html(placesHtml);
fetchUserPlaces(user.username);
fetchUserPlaces(user.userId);
}

function fetchUserPlaces(username) {
function fetchUserPlaces(userId) {
const token = localStorage.getItem('token');
$.ajax({
url: `/api/games/user/${username}`,
url: `/api/games/user/${userId}`,
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -64,66 +64,50 @@ function displayPlaces(places, category) {

places.forEach((place, index) => {
const placeHtml = `
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#user-places-${category}" href="#collapse-${category}-${index}">
${escapeHtml(place.title)}
</a>
</h4>
</div>
<div id="collapse-${category}-${index}" class="panel-collapse collapse ${
index === 0 ? 'in' : ''
}">
<div class="panel-body">
<div class="row">
<div class="col-xs-12 col-sm-6">
<a href="/game?id=${place._id}">
<img src="${
place.thumbnailUrl
? place.thumbnailUrl.startsWith('http')
? place.thumbnailUrl
: '/' + place.thumbnailUrl.replace(/^\//, '')
: '/images/placeholder-image.jpg'
}" alt="${escapeHtml(
place.title
)}" class="img-responsive" style="width: 100%; aspect-ratio: 16/9; object-fit: cover;">
</a>
<a href="/game?id=${
place._id
}" class="btn btn-success btn-block" style="margin-top: 10px;">Play</a>
</div>
<div class="col-xs-12 col-sm-6">
<p><strong>Genre:</strong> ${escapeHtml(
place.genre || 'Not specified'
)}</p>
<p><strong>Max Players:</strong> ${
place.maxPlayers || 'Not specified'
}</p>
<p>
<strong>Year:</strong>
${
place.year
? `<span class="badge" style="background-color: #337ab7;">${place.year}</span>`
: '<span class="badge" style="background-color: #d9534f;">No Year</span>'
}
</p>
<p><strong>Last Updated:</strong> ${new Date(
place.updatedAt
).toLocaleDateString()}</p>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#user-places-${category}" href="#collapse-${category}-${index}">
${escapeHtml(place.title)}
</a>
</h4>
</div>
<div id="collapse-${category}-${index}" class="panel-collapse collapse ${index === 0 ? 'in' : ''}">
<div class="panel-body">
<div class="row">
<div class="col-xs-12 col-sm-6">
<a href="/game?id=${place._id}">
<img src="${place.thumbnailUrl ? place.thumbnailUrl.startsWith('http') ? place.thumbnailUrl : '/' + place.thumbnailUrl.replace(/^\//, '') : '/images/placeholder-image.jpg'}"
alt="${escapeHtml(place.title)}"
class="img-responsive"
style="width: 100%; aspect-ratio: 16/9; object-fit: cover;">
</a>
<a href="/game?id=${place._id}" class="btn btn-success btn-block" style="margin-top: 10px;">Play</a>
</div>
<div class="col-xs-12 col-sm-6">
<p><strong>Genre:</strong> ${escapeHtml(place.genre || 'Not specified')}</p>
<p><strong>Max Players:</strong> ${place.maxPlayers || 'Not specified'}</p>
<p>
<strong>Year:</strong>
${place.year
? `<span class="badge" style="background-color: #337ab7;">${place.year}</span>`
: '<span class="badge" style="background-color: #d9534f;">No Year</span>'
}
</p>
<p><strong>Last Updated:</strong> ${new Date(place.updatedAt).toLocaleDateString()}</p>
</div>
<div class="row" style="margin-top: 15px;">
<div class="col-xs-12">
<div class="well well-sm">
<p>${escapeHtml(place.description)}</p>
</div>
</div>
<div class="row" style="margin-top: 15px;">
<div class="col-xs-12">
<div class="well well-sm">
<p>${escapeHtml(place.description)}</p>
</div>
</div>
</div>
</div>
</div>
`;
</div>
`;
placesContainer.append(placeHtml);
});
}
Expand Down
10 changes: 8 additions & 2 deletions client/js/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ $(document).ready(function () {

function fetchUserGames() {
const token = localStorage.getItem('token');
const userId = localStorage.getItem('userId');

$.ajax({
url: '/api/games/user',
url: `/api/games/user/${userId}`,
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -239,7 +241,11 @@ $(document).ready(function () {
},
success: function (response) {
$('#editGameModal').modal('hide');
fetchUserGames(); // Refresh the games list
showSuccess('Game updated successfully');
setTimeout(() => {
fetchUserGames(); // Refresh the games list
}, 1000);

},
error: function (xhr, status, error) {
let errorMessage = 'Error updating game: ';
Expand Down
75 changes: 45 additions & 30 deletions client/js/shirts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ function loadShirts() {
headers: {
Authorization: `Bearer ${token}`,
},
success: function (shirts) {
displayShirts(shirts);
success: function (response) {
if (response.shirts && Array.isArray(response.shirts)) {
displayShirts(response.shirts);
} else {
console.error('Invalid response format:', response);
showError('Error: Invalid response format from the server.');
}
},
error: function (xhr, status, error) {
console.error('Error fetching shirts:', error);
showError('Error fetching shirts. Please try again later.');
},
});
}
Expand All @@ -31,43 +37,48 @@ function displayShirts(shirts) {
}

const table = $(`
<table class="table table-striped">
<thead>
<tr>
<th>Thumbnail</th>
<th>Title</th>
<th>Description</th>
<th>Asset ID</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
`);
<table class="table table-striped">
<thead>
<tr>
<th>Thumbnail</th>
<th>Title</th>
<th>Description</th>
<th>Asset ID</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
`);

const tableBody = table.find('tbody');

shirts.forEach((shirt) => {
const row = $(`
<tr>
<td><img src="${shirt.ThumbnailLocation}" alt="${shirt.Name}" style="max-width: 50px; max-height: 50px;"></td>
<td>${shirt.Name}</td>
<td>${shirt.Description.substring(0, 50)}${shirt.Description.length > 50 ? '...' : ''}</td>
<td>${shirt.assetId}</td>
<td>${shirt.Price}</td>
<td>
<button class="btn btn-primary btn-sm edit-shirt" data-shirt-id="${shirt._id}">Edit</button>
</td>
</tr>
`);
<tr>
<td><img src="${shirt.ThumbnailLocation}" alt="${shirt.Name}" style="max-width: 50px; max-height: 50px;"></td>
<td>${shirt.Name}</td>
<td>${shirt.Description.substring(0, 50)}${shirt.Description.length > 50 ? '...' : ''}</td>
<td>${shirt.assetId}</td>
<td>${shirt.Price}</td>
<td>
<button class="btn btn-primary btn-sm edit-shirt" data-shirt-id="${shirt._id}">Edit</button>
</td>
</tr>
`);
tableBody.append(row);
});

shirtsContainer.append(table);
}

function showError(message) {
const errorContainer = $('#error-container');
errorContainer.html(`<div class="alert alert-danger">${message}</div>`);
}

function setupShirtToggler() {
$('#list-tab a').on('click', function (e) {
e.preventDefault();
Expand Down Expand Up @@ -122,7 +133,7 @@ function saveShirtChanges() {
const shirtData = {
title: title,
description: description,
price: price,
price: parseInt(price, 10)
};

$.ajax({
Expand All @@ -139,8 +150,12 @@ function saveShirtChanges() {
},
error: function (xhr, status, error) {
console.error('Error updating shirt:', error);
let errorMessage = 'Error updating shirt';
if (xhr.responseJSON && xhr.responseJSON.error) {
errorMessage += ': ' + xhr.responseJSON.error;
}
$('#shirt-error-message')
.text('Error updating shirt: ' + xhr.responseJSON.error)
.text(errorMessage)
.removeClass('hidden');
},
});
Expand Down
2 changes: 1 addition & 1 deletion client/js/user-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ $(document).ready(function () {
const shirtHtml = generateItemHtml(
shirt.Name,
shirt.ThumbnailLocation,
shirt.creator.username,
shirt.creator ? shirt.creator.username : 'Unknown',
shirt.Price
);
shirtsContainer.append(shirtHtml);
Expand Down
1 change: 1 addition & 0 deletions server/functions/api/routes/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const authenticateToken = require('../middleware/authenticateToken');
const User = require('../models/User');
const mongoose = require('mongoose');

// Get current avatar
router.get('/', authenticateToken, async (req, res) => {
Expand Down
Loading

0 comments on commit cd892a1

Please sign in to comment.