Skip to content

Commit

Permalink
fixed spa
Browse files Browse the repository at this point in the history
  • Loading branch information
muratkaanmesum committed Mar 25, 2024
1 parent 9fc3673 commit 9ad743f
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Backend/Apps/SocialMedia/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from django.urls import path

from . import views

urlpatterns = [
path('',views.index, name='socialmedia'),
]
3 changes: 2 additions & 1 deletion Backend/Backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
'django.contrib.staticfiles',
"Apps.Auth.apps.AuthConfig",
'Apps.Home.apps.HomeConfig',
"Apps.Profile.apps.ProfileConfig"
"Apps.Profile.apps.ProfileConfig",
"Apps.SocialMedia.apps.SocialMediaConfig"
]

MIDDLEWARE = [
Expand Down
1 change: 1 addition & 0 deletions Backend/Backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
path('auth/', include('Apps.Auth.urls')),
path('', include('Apps.Home.urls')),
path('profile/', include('Apps.Profile.urls')),
path('socialmedia/', include('Apps.SocialMedia.urls')),
]
File renamed without changes
2 changes: 2 additions & 0 deletions Backend/static/scripts/login.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {loadPage, API_URL,getCookie, setCookie} from "./spa.js";
import {notify} from "../components/Notification.js";

async function loginForm(event)
{
Expand Down Expand Up @@ -39,6 +40,7 @@ const App = async () => {
{
console.log('tokens exist')
loadPage('home');
notify('Already logged in', 3, 'success')
}
const form = document.getElementById('login-form');
form.addEventListener('submit', loginForm);
Expand Down
82 changes: 82 additions & 0 deletions Backend/static/scripts/social.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {API_URL, getCookie, loadPage} from "./spa.js";
import {notify} from "../components/Notification.js";
import BaseComponent from "../components/Component.js";
import {request} from "./Request.js";
class ChatFriendsComponent extends BaseComponent{
constructor(state,parentElement = null) {
super(state,parentElement);
this.html = this.handleHTML()
}
handleHTML()
{
return `
${this.state.friends.map(friend => `
<div class="user-wrapper">
<div class="user-pic-wrapper">
<img
src="https://picsum.photos/seed/picsum/200/300"
alt=""
/>
</div>
<div class="user-info-wrapper">
<div
class="d-flex align-items-center justify-content-center gap-2"
>
<h6>${friend.nickname.length <=0 ? friend.user.username: friend.nickname}</h6>
<div class="online-icon"></div>
</div>
<span>Active Now</span>
</div>
</div>
`).join('')}
`
}
render() {
super.render();
}
setState(newState)
{
this.state = {...this.state, ...newState};
this.html = this.handleHTML();
this.render();
}
}
const fetchChatFriends = async () => {
const endpoint = `${API_URL}/profile/friends`;
try {
let response = await request(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${JSON.parse(getCookie('tokens')).access}`
}
});
let parentElement = document.getElementById('user-data-wrapper');
let chatFriendsComponent = new ChatFriendsComponent({friends: response},parentElement);
let input = document.getElementById('friend-search-input');
input.addEventListener('keyup', async (event) => {
let value = event.target.value;
let filteredFriends = response.filter(friend => {
let nameToCheck = friend.nickname.length > 0 ? friend.nickname : friend.user.username;
return nameToCheck.toLowerCase().includes(value.toLowerCase());
});
chatFriendsComponent.setState({friends: filteredFriends});
});
chatFriendsComponent.render();

}
catch (error) {
console.error('Error:', error);
}

}
const App = async () => {
if(!getCookie("tokens"))
{
loadPage('login');
notify('Please login to continue', 3, 'error')
}
await fetchChatFriends();
}

document.addEventListener('DOMContentLoaded', App);
2 changes: 1 addition & 1 deletion Backend/static/styles/social.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.social-background {
background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
url("/public/inside.jpg") !important;
url("/static/public/inside.jpg") !important;
}
.users-wrapper {
height: 100%;
Expand Down
4 changes: 3 additions & 1 deletion Backend/templates/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ <h1>WELCOME TO PONG</h1>
MULTIPLAYER
</button>
<button class="play-button">SINGLEPLAYER</button>
<button class="play-button">SOCIAL</button>
<pong-redirect href="social">
<button class="play-button">SOCIAL</button>
</pong-redirect>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 9ad743f

Please sign in to comment.