-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fc3673
commit 9ad743f
Showing
9 changed files
with
356 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.