fix: more user profile fixes

This commit is contained in:
Floorb 2023-05-20 10:23:22 -04:00
parent 0b6f54b0d6
commit dfa22dbde1
7 changed files with 28 additions and 18 deletions

View file

@ -35,7 +35,7 @@ class Paste extends Model {
return $this->hasMany(Report::class); return $this->hasMany(Report::class);
} }
public function replaceTags(array $tags) { public function replaceTags(array $tags) : void {
$this->tags()->detach(); $this->tags()->detach();
foreach ($tags as $tagName) { foreach ($tags as $tagName) {

View file

@ -38,8 +38,8 @@ whenReady(() => {
rowCallback: (rowData) => { rowCallback: (rowData) => {
console.log('rowData', rowData); console.log('rowData', rowData);
const userData = getUserInfo(); const userData = getUserInfo();
const ownedByUser = (parseInt(rowData.user_id) === parseInt(userData.userId)); const ownedByUser = (parseInt(rowData.author_id) === parseInt(userData.userId));
console.log(ownedByUser);
const deleteElem = ownedByUser ? `<td class="td-center"> const deleteElem = ownedByUser ? `<td class="td-center">
<form action="/${rowData.id}" method="POST"> <form action="/${rowData.id}" method="POST">
<input type="hidden" name="delete" value="delete" /> <input type="hidden" name="delete" value="delete" />
@ -48,7 +48,7 @@ whenReady(() => {
</form> </form>
</td>` : ''; </td>` : '';
const pasteCreatedAt = new Date(rowData.created_at).toLocaleString(); const pasteCreatedAt = new Date(rowData.created_at).toLocaleString();
const pasteVisibility = ownedByUser ? `<td class="td-center">${rowData.visibility}</td>` : ''; const pasteVisibility = ownedByUser ? `<td class="td-center">${['Public', 'Unlisted', 'Private'][rowData.visibility]}</td>` : '';
return `<tr> return `<tr>
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td> <td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>

View file

@ -23,7 +23,7 @@ $pastes = Paste::with([
'tags' => function($query) { 'tags' => function($query) {
$query->select('tags.id', 'name', 'slug'); $query->select('tags.id', 'name', 'slug');
} }
])->select(['id', 'user_id', 'title', 'expiry', 'created_at', 'views']) ])->select(['id', 'user_id', 'title', 'expiry', 'created_at', 'views', 'visible'])
->where('hidden', false) ->where('hidden', false)
->where('user_id', $user_id) ->where('user_id', $user_id)
->whereRaw("((expiry IS NULL) OR ((expiry != 'SELF') AND (expiry > NOW())))"); ->whereRaw("((expiry IS NULL) OR ((expiry != 'SELF') AND (expiry > NOW())))");
@ -42,6 +42,7 @@ $pastes_json = json_encode(['data' => $pastes->map(function($paste) {
'author' => $paste->user->username, 'author' => $paste->user->username,
'author_id' => $paste->user->id, 'author_id' => $paste->user->id,
'views' => $paste->views, 'views' => $paste->views,
'visibility' => $paste->visible,
'tags' => $paste->tags->map(function($tag) { 'tags' => $paste->tags->map(function($tag) {
return ['slug' => $tag->slug, 'name' => $tag->name]; return ['slug' => $tag->slug, 'name' => $tag->name];
}) })

View file

@ -567,8 +567,8 @@ whenReady(() => {
rowCallback: (rowData) => { rowCallback: (rowData) => {
console.log('rowData', rowData); console.log('rowData', rowData);
const userData = getUserInfo(); const userData = getUserInfo();
const ownedByUser = (parseInt(rowData.user_id) === parseInt(userData.userId)); const ownedByUser = (parseInt(rowData.author_id) === parseInt(userData.userId));
console.log(ownedByUser);
const deleteElem = ownedByUser ? `<td class="td-center"> const deleteElem = ownedByUser ? `<td class="td-center">
<form action="/${rowData.id}" method="POST"> <form action="/${rowData.id}" method="POST">
<input type="hidden" name="delete" value="delete" /> <input type="hidden" name="delete" value="delete" />
@ -577,7 +577,7 @@ whenReady(() => {
</form> </form>
</td>` : ''; </td>` : '';
const pasteCreatedAt = new Date(rowData.created_at).toLocaleString(); const pasteCreatedAt = new Date(rowData.created_at).toLocaleString();
const pasteVisibility = ownedByUser ? `<td class="td-center">${rowData.visibility}</td>` : ''; const pasteVisibility = ownedByUser ? `<td class="td-center">${['Public', 'Unlisted', 'Private'][rowData.visibility]}</td>` : '';
return `<tr> return `<tr>
<td><a href="/${rowData.id}">${escape(rowData.title)}</a></td> <td><a href="/${rowData.id}">${escape(rowData.title)}</a></td>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -31,6 +31,10 @@
} }
} }
$tab = 'pastes';
if ($is_current_user && isset($_GET['tab']) && $_GET['tab'] === 'favourites') {
$tab = 'favourites';
}
?> ?>
<main class="bd-main"> <main class="bd-main">
<div class="bd-side-background"></div> <div class="bd-side-background"></div>
@ -101,12 +105,12 @@
<br /> <br />
<div class="tabs"> <div class="tabs">
<ul class="tabs-menu"> <ul class="tabs-menu">
<li class="is-active" data-target="first-tab"><a>My Pastes</a></li> <li class="<?= $tab === 'pastes' ? 'is-active' : '' ?>" data-target="first-tab"><a href="?tab=pastes">My Pastes</a></li>
<li data-target="second-tab"><a>Favorites</a></li> <li class="<?= $tab === 'favourites' ? 'is-active' : '' ?>" data-target="second-tab"><a href="?tab=favourites">Favorites</a></li>
</ul> </ul>
</div> </div>
<?php endif;?> <?php endif;?>
<div class="tab-content" id="first-tab"> <div class="tab-content<?= $tab === 'favourites' ? ' is-hidden' : '' ?>" id="first-tab">
<form class="table_filterer" method="GET"> <form class="table_filterer" method="GET">
<label><i class="fa fa-search"></i> <label><i class="fa fa-search"></i>
<input class="search" type="search" name="q" placeholder="Filter..." value="<?= pp_html_escape($filter_value); ?>" /> <input class="search" type="search" name="q" placeholder="Filter..." value="<?= pp_html_escape($filter_value); ?>" />
@ -128,12 +132,12 @@
<tr class="paginator__sort"> <tr class="paginator__sort">
<th data-sort-field="title" class="td-right">Title</th> <th data-sort-field="title" class="td-right">Title</th>
<th data-sort-field="created_at" class="td-center">Paste Time</th> <th data-sort-field="created_at" class="td-center">Paste Time</th>
<?php if ($is_current_user) { <?php if ($is_current_user || $can_administrate) {
echo "<th class='td-center'>Visibility</th>"; echo "<th class='td-center'>Visibility</th>";
} ?> } ?>
<th data-sort-field="views" class="td-center">Views</th> <th data-sort-field="views" class="td-center">Views</th>
<th class="td-center">Tags</th> <th class="td-center">Tags</th>
<?php if ($is_current_user) { <?php if ($is_current_user || $can_administrate) {
echo "<th class='td-center'>Delete</th>"; echo "<th class='td-center'>Delete</th>";
} ?> } ?>
</tr> </tr>
@ -195,8 +199,8 @@
</div> </div>
</div> </div>
<?php if ($is_current_user) { ?> <?php if ($is_current_user) { ?>
<div class="tab-content" id="second-tab"> <div class="tab-content<?= $tab === 'pastes' ? ' is-hidden' : '' ?>" id="second-tab">
<table id="favs" class="table is-fullwidth is-hoverable"> <table id="favs" class="table is-fullwidth is-hoverable<?= $current_page === 'favourites' ? 'is-active' : '' ?>">
<thead> <thead>
<tr> <tr>
<th class="td-right">Title</th> <th class="td-right">Title</th>
@ -254,6 +258,7 @@
init() { init() {
document.querySelectorAll('.tabs-menu').forEach(tabMenu => { document.querySelectorAll('.tabs-menu').forEach(tabMenu => {
Array.from(tabMenu.children).forEach((child, ind) => { Array.from(tabMenu.children).forEach((child, ind) => {
child.querySelector('a').href = 'javascript:void(0);';
child.addEventListener('click', () => { child.addEventListener('click', () => {
tabSystem.toggle(child.dataset.target); tabSystem.toggle(child.dataset.target);
}); });
@ -265,7 +270,11 @@
}, },
toggle(targetId) { toggle(targetId) {
document.querySelectorAll('.tab-content').forEach(contentElement => { document.querySelectorAll('.tab-content').forEach(contentElement => {
contentElement.style.display = contentElement.id === targetId ? 'block' : 'none'; if (contentElement.id === targetId) {
contentElement.classList.remove('is-hidden');
} else {
contentElement.classList.add('is-hidden');
}
document.querySelector(`[data-target="${contentElement.id}"]`).classList[contentElement.id === targetId ? 'add' : 'remove']('is-active'); document.querySelector(`[data-target="${contentElement.id}"]`).classList[contentElement.id === targetId ? 'add' : 'remove']('is-active');
}) })
}, },