parent
5bac9bfead
commit
62d33c6737
|
|
@ -32,7 +32,7 @@ class Controller extends BaseController
|
|||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function fetchCategoriesFP() {
|
||||
public function fetchCategoriesFP(Request $request) {
|
||||
|
||||
$user = AuthHelper::GetCurrentUser($request);
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class Controller extends BaseController
|
|||
|
||||
}
|
||||
|
||||
public function fetchCategoriesCatalog() {
|
||||
public function fetchCategoriesCatalog(Request $request) {
|
||||
|
||||
$categories = CatalogCategory::get();
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ class Controller extends BaseController
|
|||
|
||||
}
|
||||
|
||||
public function fetchCategoryCatalog($id) {
|
||||
public function fetchCategoryCatalog(Request $request, $id) {
|
||||
|
||||
$category = CatalogCategory::where('id', $id)->first();
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ class Controller extends BaseController
|
|||
return Response()->json(["data"=>$category, "items"=>$items]);
|
||||
}
|
||||
|
||||
public function fetchCategory($id) {
|
||||
public function fetchCategory(Request $request, $id) {
|
||||
|
||||
$category = Category::where('id', $id)->first();
|
||||
|
||||
|
|
@ -119,7 +119,24 @@ class Controller extends BaseController
|
|||
return Response()->json(["data"=>$category, "posts"=>$posts]);
|
||||
}
|
||||
|
||||
public function fetchPost($id) {
|
||||
public function fetchUser(Request $request, $id) {
|
||||
|
||||
$meta = AuthHelper::GetCurrentUser($request);
|
||||
|
||||
$user = User::where('id', $id)->first();
|
||||
|
||||
if (!$user) {return Response()->json('Error');}
|
||||
|
||||
$array = $user->toArray();
|
||||
|
||||
if ($meta && $meta->id == $array['id']) $array['isMeta'] = true; else $array['isMeta'] = false;
|
||||
|
||||
if ($meta && $meta->getFriends('pending', 'checkSent', $array['id'])) $array['isFriend'] = 'needToAccept'; elseif ($meta && array_intersect($meta->getFriends('pending', 'id', null), [$array['id']])) $array['isFriend'] = 'pending'; elseif ($meta && array_intersect($meta->getFriends('id', null, null), [$array['id']])) $array['isFriend'] = true; else $array['isFriend'] = false;
|
||||
|
||||
return Response()->json(["data"=>$array]);
|
||||
}
|
||||
|
||||
public function fetchPost(Request $request, $id) {
|
||||
|
||||
$post = Post::where('id', $id)->first();
|
||||
|
||||
|
|
|
|||
|
|
@ -155,6 +155,57 @@ class HomeController extends Controller
|
|||
|
||||
}
|
||||
|
||||
public function addFriend(Request $request, $id) {
|
||||
|
||||
$user = User::where('id', $id)->first();
|
||||
|
||||
if (!$user) {return Response()->json(['message'=>'No user.', 'badInputs'=>['title']]);}
|
||||
|
||||
$meta = AuthHelper::GetCurrentUser($request);
|
||||
|
||||
if (!$meta) {return Response()->json(['message'=>'System error.', 'badInputs'=>['title']]);}
|
||||
|
||||
if (!isset($_POST['decision'])) {return Response()->json(['message'=>'System error.', 'badInputs'=>['title']]);}
|
||||
|
||||
switch($_POST['decision']) {
|
||||
case 'remove':
|
||||
if ($meta && !array_intersect($meta->getFriends('id', null, null), [$user->id]))
|
||||
return Response()->json(['message'=>'Not Friends.', 'badInputs'=>['title']]);
|
||||
elseif ($meta && array_intersect($meta->getFriends('pending', 'id', null), [$user->id]))
|
||||
return Response()->json(['message'=>'Already Pending.', 'badInputs'=>['title']]);
|
||||
|
||||
$friend = $meta->getFriends('remove', null, $user->id);
|
||||
|
||||
return Response()->json(['message'=>'Success!', 'badInputs'=>[], "data"=>false]);
|
||||
break;
|
||||
case 'accept':
|
||||
if ($meta && array_intersect($meta->getFriends('id', null, null), [$user->id]))
|
||||
return Response()->json(['message'=>'Already Friends.', 'badInputs'=>['title']]);
|
||||
|
||||
$friend = $meta->getFriends('accept', null, $user->id);
|
||||
|
||||
return Response()->json(['message'=>'Success!', 'badInputs'=>[], "data"=>true]);
|
||||
break;
|
||||
case 'add':
|
||||
if ($meta && array_intersect($meta->getFriends('id', null, null), [$user->id]))
|
||||
return Response()->json(['message'=>'Already Friends.', 'badInputs'=>['title']]);
|
||||
elseif ($meta && array_intersect($meta->getFriends('pending', 'id', null), [$user->id]))
|
||||
return Response()->json(['message'=>'Already Pending.', 'badInputs'=>['title']]);
|
||||
|
||||
$friend = new Friend;
|
||||
$friend->sent_id = $meta->id;
|
||||
$friend->recieved_id = $user->id;
|
||||
$friend->status = 0;
|
||||
$friend->save();
|
||||
|
||||
return Response()->json(['message'=>'Success!', 'badInputs'=>[], "data"=>'pending']);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function createReply($id) {
|
||||
|
||||
$data = $request->all();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,133 @@ class User extends Model
|
|||
'password',
|
||||
'remember_token',
|
||||
'email',
|
||||
'email_verified_at',
|
||||
'email_verified_at'
|
||||
];
|
||||
|
||||
public function getFriends($decision, $pending, $id) {
|
||||
|
||||
switch($decision) {
|
||||
case 'id':
|
||||
$friends = Friend::where('status', 1)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id) {
|
||||
array_push($actualFriends, $friend['sent_id']);
|
||||
}else{
|
||||
array_push($actualFriends, $friend['recieved_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $actualFriends;
|
||||
|
||||
break;
|
||||
case 'account':
|
||||
$friends = Friend::where('status', 1)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id) {
|
||||
$friendUser = User::where('id', $friend['sent_id'])->first();
|
||||
array_push($actualFriends, $friendUser);
|
||||
}else{
|
||||
$friendUser = User::where('id', $friend['recieved_id'])->first();
|
||||
array_push($actualFriends, $friendUser);
|
||||
}
|
||||
}
|
||||
|
||||
return $actualFriends;
|
||||
|
||||
break;
|
||||
case 'remove':
|
||||
$friends = Friend::where('status', 1)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id) {
|
||||
$friendUserMeta = Friend::where('sent_id', $id)->delete();
|
||||
}else{
|
||||
$friendUserMeta = Friend::where('recieved_id', $id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
break;
|
||||
case 'accept':
|
||||
$friends = Friend::where('status', 0)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id) {
|
||||
$friendUserMeta = Friend::where('sent_id', $id)->first();
|
||||
$friendUserMeta->status = 1;
|
||||
$friendUserMeta->save();
|
||||
}else{
|
||||
$friendUserMeta = Friend::where('recieved_id', $id)->first();
|
||||
$friendUserMeta->status = 1;
|
||||
$friendUserMeta->save();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
break;
|
||||
case 'pending':
|
||||
switch($pending) {
|
||||
case 'id':
|
||||
$friends = Friend::where('status', 0)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id) {
|
||||
array_push($actualFriends, $friend['sent_id']);
|
||||
}else{
|
||||
array_push($actualFriends, $friend['recieved_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $actualFriends;
|
||||
|
||||
break;
|
||||
case 'account':
|
||||
$friends = Friend::where('status', 0)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id) {
|
||||
$friendUser = User::where('id', $friend['sent_id'])->first();
|
||||
array_push($actualFriends, $friendUser);
|
||||
}else{
|
||||
$friendUser = User::where('id', $friend['recieved_id'])->first();
|
||||
array_push($actualFriends, $friendUser);
|
||||
}
|
||||
}
|
||||
|
||||
return $actualFriends;
|
||||
|
||||
break;
|
||||
|
||||
case 'checkSent':
|
||||
$friends = Friend::where('status', 0)->where('recieved_id', $this->id)->orWhere('sent_id', $this->id)->get()->toArray();
|
||||
$actualFriends = [];
|
||||
|
||||
foreach ($friends as $friend) {
|
||||
if ($friend['recieved_id'] == $this->id && $friend['sent_id'] == $id) {
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,8 +119,7 @@ const App = () => {
|
|||
}
|
||||
|
||||
useEffect(async ()=>{
|
||||
if (!getCookie('gtok')) {setCookie('gtok', null);}
|
||||
fetchUser();
|
||||
await fetchUser();
|
||||
updateBanners();
|
||||
updateOfflineStatus();
|
||||
setInterval(updateBanners, 2*60*1000 /* 2 mins */);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ const CreatePost = (props) => {
|
|||
}
|
||||
|
||||
return (
|
||||
waitingForSubmission || !categories.categories? <Loader/> :
|
||||
waitingForSubmission || categories.categories.length <= 0 ? <Loader/> :
|
||||
<Card>
|
||||
<CardTitle>Create a new Post</CardTitle>
|
||||
<div className="p-2 row">
|
||||
|
|
|
|||
|
|
@ -130,9 +130,10 @@ const Dashboard = (props) => {
|
|||
</div>
|
||||
:
|
||||
<>
|
||||
<div className='card flex-column pt-3 px-3 align-content-center'>
|
||||
{feedState.posts.posts.map(feed=>(
|
||||
<>
|
||||
<div className='card flex-row pt-3 px-3 align-content-center'>
|
||||
<Link className={`flex flex-row align-items-center a`} to={`/user/${feed.user_id}`}>
|
||||
<div className={`flex flex-column justify-content-center text-center w-fit-content`}>
|
||||
<p className='mr-10'>{feed.creatorName}</p>
|
||||
<img src='/images/testing/headshot.png' className='img-fluid graphic-thumb' />
|
||||
|
|
@ -140,10 +141,11 @@ const Dashboard = (props) => {
|
|||
<div className={`flex align-items-center col`}>
|
||||
<p className='mr-10'><i>"{feed.body}"</i></p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="graphictoria-nav-splitter"></div>
|
||||
</Link>
|
||||
<hr/>
|
||||
</>
|
||||
))}
|
||||
</div>
|
||||
{feedState.posts.posts.length <= 0? <p>There isn't any posts right now!</p> : null}
|
||||
{feedState.posts.posts.length >= 1?
|
||||
<div className={`w-100 jcc alc row mt-15`}>
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@ var protocol = Config.Protocol;
|
|||
|
||||
const User = (props) => {
|
||||
|
||||
const [validity, setValidity] = useState({error: false, message: ``, inputs: []});
|
||||
const [state, setState] = useState(true);
|
||||
const [user, setUser] = useState();
|
||||
const [isFriend, setFriend] = useState(false);
|
||||
const metaUser = props.user;
|
||||
const userId = useParams().id;
|
||||
const history = useHistory();
|
||||
|
|
@ -29,34 +31,78 @@ const User = (props) => {
|
|||
const body = new FormData();
|
||||
body.append('userId', userId);
|
||||
body.append('decision', `fetchedUser`);
|
||||
axios.post(`${protocol}apis.${url}/fetch/user`, body).then(async(data)=>{
|
||||
axios.get(`${protocol}apis.${url}/fetch/user/${userId}`, body).then(async(data)=>{
|
||||
const res = data.data;
|
||||
if (!res) {history.push(`/`);}
|
||||
SetTitle(`${res.data.username}`);
|
||||
setFriend(res.data.isFriend);
|
||||
await setUser(res.data);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
const addFriend = async (decision) => {
|
||||
const body = new FormData();
|
||||
body.append('decision', decision);
|
||||
setState(true);
|
||||
axios.post(`${protocol}apis.${url}/api/add/user/${userId}`, body).then(async(data)=>{
|
||||
const res = data.data;
|
||||
if (res.badInputs.length >= 1) {
|
||||
setValidity({error: true, message:res.message, inputs: res.badInputs});
|
||||
setTimeout(()=>{setValidity({...validity, error: false, inputs: res.badInputs});}, 4000);
|
||||
setFeedState({...feedState, loading: false});
|
||||
setState(false);
|
||||
return;
|
||||
}
|
||||
await setFriend(res.data);
|
||||
setState(false);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(async()=>{
|
||||
await fetchUser();
|
||||
setState(false);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
!user
|
||||
!user || state
|
||||
?
|
||||
<Loader />
|
||||
:
|
||||
<div className={`row`}>
|
||||
{validity.error?
|
||||
<div className={`px-5 mb-10`}>
|
||||
<div className={`error-dialog`}>
|
||||
<p className={`mb-0`}>{validity.message}</p>
|
||||
</div>
|
||||
</div>
|
||||
: null}
|
||||
<div className={`col`}>
|
||||
<Card className={`justify-content-center`} padding={true}>
|
||||
<CardTitle>{user.username}</CardTitle>
|
||||
<p>[Avatar.]</p>
|
||||
<img src='/images/testing/avatar.png' className='img-fluid gt-charimg' />
|
||||
<hr/>
|
||||
<div className={`flex flex-column justify-content-center align-items-center`}>
|
||||
{
|
||||
!metaUser? null :
|
||||
userId == metaUser.id? <p>This is you!</p> :
|
||||
isFriend && isFriend == `pending`?
|
||||
<button className={`btn btn-dark disabled w-fit-content`}>Pending...</button>
|
||||
: isFriend && isFriend == `needToAccept`?
|
||||
<button className={`btn btn-success w-fit-content`} onClick={(e)=>{addFriend(`accept`);}}>Accept Friend Request</button>
|
||||
: isFriend?
|
||||
<button className={`btn btn-danger w-fit-content`} onClick={(e)=>{addFriend(`remove`);}}>Remove Friend</button>
|
||||
:
|
||||
<button className={`btn btn-success w-fit-content`} onClick={(e)=>{addFriend(`add`);}}>Add Friend</button>
|
||||
}
|
||||
</div>
|
||||
<hr/>
|
||||
<p>"{user.about? user.about : `${user.username} doesn't have an about section!`}" - {user.username}</p>
|
||||
</Card>
|
||||
</div>
|
||||
<div className={`col justify-content-center`}>
|
||||
<p>"{user.about? user.about : `${user.username} doesn't have an about section!`}" - {user.username}</p>
|
||||
<p>Something else idk.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ $web-font-path: "https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,w
|
|||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.a {
|
||||
color: inherit !important;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
.a:hover {
|
||||
color: inherit !important;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
// Loader
|
||||
|
||||
.gtoria-loader-center {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ Route::post('/v1/user/login', 'AuthController@Login');
|
|||
Route::post('/v1/user/logout', 'AuthController@Logout');
|
||||
Route::get('/v1/user/settings', 'UserController@GetSettings');
|
||||
|
||||
Route::get('/fetch/user/{id}', 'Controller@fetchUser');
|
||||
|
||||
Route::get('/banners/data', 'BannerController@getBanners');
|
||||
|
||||
Route::get('/games/metadata', 'GamesController@isAvailable');
|
||||
|
|
@ -56,6 +58,8 @@ Route::get('/fetch/posts/{id}', 'Controller@fetchPosts');
|
|||
|
||||
Route::get('/fetch/post/{id}', 'Controller@fetchPost');
|
||||
|
||||
Route::post('/api/add/user/{id}', 'HomeController@addFriend');
|
||||
|
||||
Route::post('/api/create/forum', 'HomeController@createPost');
|
||||
|
||||
Route::post('/api/create/reply/{id}', 'HomeController@createReply');
|
||||
|
|
|
|||
Loading…
Reference in New Issue