Skip to content

Commit

Permalink
Merge pull request #12 from guildso/feature/home-feed
Browse files Browse the repository at this point in the history
Moved feed to dashboard
  • Loading branch information
bobbyiliev authored Jan 4, 2021
2 parents 5ce0aa7 + 8544ea0 commit f4064d2
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 170 deletions.
34 changes: 34 additions & 0 deletions app/Http/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,52 @@
namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Post;
use App\Events\NotificationSent;
use App\Models\Notification;
use App\Traits\WithShift;

class Dashboard extends Component
{
use WithShift;

public $body;

protected $listeners = [
Shifts::SHIFT_CHANGED // calls shiftChanged()
];

protected $rules = [
'body' => 'required|max:500',
];

public function render()
{
return view('livewire.dashboard');
}

public function store()
{
if (auth()->user()->hasTeamPermission(auth()->user()->currentTeam, 'create')) {
$this->validate();
$post = new Post;
$post->team_id = auth()->user()->currentTeam->id;
$post->user_id = auth()->user()->id;
$post->body = $this->body;
$post->save();

$this->dispatchBrowserEvent('notification', ['type' => 'success', 'message' => 'Post Created Successfully!']);

$this->resetInputFields();

$this->emit('feed-update');
event(new NotificationSent(new Notification, ['title' => 'New Post Added', 'description' => $post->body]));
} else {
$this->dispatchBrowserEvent('notification', ['type' => 'error', 'message' => 'You do not have permissions to add posts to this team!']);
}
}

private function resetInputFields(){
$this->body = '';
}
}
31 changes: 2 additions & 29 deletions app/Http/Livewire/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ class Posts extends Component

public $numResults = 20;
protected $listeners = [
'load-more' => 'loadMore'
];

protected $rules = [
'body' => 'required|max:500',
'load-more' => 'loadMore',
'feed-update' => 'render',
];

public function render()
Expand All @@ -34,30 +31,6 @@ public function loadMore(){
$this->numResults += 20;
}

public function store()
{
if (auth()->user()->hasTeamPermission(auth()->user()->currentTeam, 'create')) {
$this->validate();
$post = new Post;
$post->team_id = auth()->user()->currentTeam->id;
$post->user_id = auth()->user()->id;
$post->body = $this->body;
$post->save();

$this->dispatchBrowserEvent('notification', ['type' => 'success', 'message' => 'Post Created Successfully!']);

$this->resetInputFields();

event(new NotificationSent(new Notification, ['title' => 'New Post Added', 'description' => $post->body]));
} else {
$this->dispatchBrowserEvent('notification', ['type' => 'error', 'message' => 'You do not have permissions to add posts to this team!']);
}
}

private function resetInputFields(){
$this->body = '';
}

public function delete($id)
{
$post = Post::find($id);
Expand Down
1 change: 0 additions & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

<livewire:dashboard />


</x-app-layout>
27 changes: 0 additions & 27 deletions resources/views/livewire/addPost.blade.php

This file was deleted.

65 changes: 47 additions & 18 deletions resources/views/livewire/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<!-- Main Start Shift Top Bar -->
<div class="w-1/2 mx-0 mb-5 overflow-hidden bg-white border border-gray-100 rounded-lg shadow-sm">
<div class="flex flex-col">
<div class="relative flex items-center p-5 space-x-4 lg:space-x-2">
<form wire:submit.prevent="store()" class="relative flex items-center p-5 space-x-4 lg:space-x-2">
<a href="#_" class="relative flex-shrink-0 w-10 h-10 lg:w-12 lg:h-12">
<img class="w-10 h-10 rounded-full lg:w-12 lg:h-12" src="{{ auth()->user()->profile_photo_url }}" alt="">
<span class="absolute bottom-0 right-0 w-4 h-4 mb-0 mr-0 @if($shift) bg-green-400 @else bg-gray-300 @endif border-2 border-white rounded-full"></span>
</a>
<input type="text" class="w-full h-12 px-3 text-xl border-0 focus:outline-none focus:border-0 focus:ring-0" placeholder="What are you doing?">
<button class="inline-flex items-center justify-center flex-shrink-0 w-auto px-4 py-2 text-xs font-semibold tracking-wide text-center text-white transition duration-150 ease-in-out bg-gray-800 border border-transparent rounded-md hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray disabled:opacity-25">Update Status</button>
</div>
<input wire:model="body" type="text" class="w-full h-12 px-3 text-xl border-0 focus:outline-none focus:border-0 focus:ring-0" placeholder="What are you doing?">
<button wire:submit.prevent="store()" class="inline-flex items-center justify-center flex-shrink-0 w-auto px-4 py-2 text-xs font-semibold tracking-wide text-center text-white transition duration-150 ease-in-out bg-gray-800 border border-transparent rounded-md hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray disabled:opacity-25">Update Status</button>
</form>

<div class="flex justify-between items-center p-5 space-x-4 @if($shift){{ 'bg-green-400' }}@else{{ 'bg-gray-200' }}@endif">
@if($shift)
Expand All @@ -33,20 +33,49 @@

</div>

<div class="relative">
<ul class="space-y-12 sm:grid sm:grid-cols-3 sm:gap-5 sm:space-y-0">

<!-- Show the authenticated user first -->
@include('partials.member-card', ['member' => auth()->user()])

@foreach (auth()->user()->currentTeam->teamShifts() as $member)
@if( auth()->user()->id != $member->id)
@include('partials.member-card', ['member' => $member])
@endif
@endforeach

</ul>

<div class="mx-auto max-w-7xl sm:px-1 lg:px-1">
<div class="py-2">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
<div class="flex flex-col mt-10">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<div class="px-6 py-8">
<div class="container flex justify-between mx-auto">
<div class="w-full lg:w-8/12">
<div class="flex items-center justify-between">
<h1 class="text-xl font-bold text-gray-700 md:text-2xl">Feed</h1>
</div>
<div>
@livewire('posts')
</div>
</div>
<div class="hidden w-4/12 -mx-8 lg:block">
<div class="px-1">
<h1 class="mb-4 text-xl font-bold text-gray-700">Guild members</h1>
<div class="relative">
<ul class="space-y-12">
@include('partials.member-card', ['member' => auth()->user()])
@foreach (auth()->user()->currentTeam->teamShifts() as $member)
@if( auth()->user()->id != $member->id)
@include('partials.member-card', ['member' => $member])
@endif
@endforeach
</ul>
</div>
</div>
</div>
</div>
</div>
{{-- @if( count($shifts) > 0 )
<div wire:click="loadMore()" class="flex items-center justify-start w-full py-2 pl-8 text-xs font-medium text-gray-500 duration-200 ease-out bg-gray-200 cursor-pointer hover:text-gray-600 hover:bg-gray-300 transition-color md:pl-0 md:justify-center">Load More</div>
@else
<div class="flex items-center justify-start w-full py-2 pl-8 text-xs font-medium text-gray-500 duration-200 ease-out bg-gray-100 transition-color md:pl-0 md:justify-center">No more entries</div>
@endif --}}
</div>
</div>
</div>
</div>
</div>
</div>

</div>
113 changes: 25 additions & 88 deletions resources/views/livewire/posts.blade.php
Original file line number Diff line number Diff line change
@@ -1,98 +1,35 @@
<div>
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
<div class="mt-10 sm:mt-0">
<div class="md:grid md:grid-cols-3 md:gap-6">
<div class="md:col-span-1">
<div class="px-4 sm:px-0">
<h3 class="text-lg font-medium text-gray-900">Share what's on your mind!</h3>

<p class="mt-1 text-sm text-gray-600">
<p>Current guild: <strong>{{ auth()->user()->currentTeam->name }}</strong></p>
</p>
</div>
@foreach($posts as $post)
<div class="mt-6">
<div class="max-w-4xl px-10 py-6 bg-white rounded-lg shadow-md">
<div class="flex items-center justify-between"><span
class="font-light text-gray-600">{{ $post->created_at->format('h:m - d/ M/Y') }}</span>
</div>
<div class="mt-5 md:mt-0 md:col-span-2">
@include('livewire.addPost')
<div class="mt-2">
<p class="mt-2 text-gray-600">
{!! Markdown::convertToHtml($post->body) !!}
</p>
</div>
</div>
</div>
<div class="py-12">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
<div class="flex flex-col mt-10">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<div class="px-6 py-8">
<div class="container flex justify-between mx-auto">
<div class="w-full lg:w-8/12">
<div class="flex items-center justify-between">
<h1 class="text-xl font-bold text-gray-700 md:text-2xl">Post</h1>
{{-- <div>
<select class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
<option>Latest</option>
<option>Last Week</option>
</select>
</div> --}}
</div>
@foreach($posts as $post)
<div class="mt-6">
<div class="max-w-4xl px-10 py-6 bg-white rounded-lg shadow-md">
<div class="flex items-center justify-between"><span
class="font-light text-gray-600">{{ $post->created_at->format('h:m - d/ M/Y') }}</span>
</div>
<div class="mt-2">
<p class="mt-2 text-gray-600">
{!! Markdown::convertToHtml($post->body) !!}
</p>
</div>
<div class="flex items-center justify-between mt-4">
<div>
@if(auth()->user()->id === $post->user_id)
<a wire:click.prevent="delete({{ $post->id }})" role="button" href="#"
class="text-red-500 hover:underline">Delete
</a>
@endif
</div>
<div>
<a class="flex items-center"><img
src="{{ $post->user->profile_photo_url }}"
alt="avatar"
class="hidden object-cover w-10 h-10 mx-4 rounded-full sm:block">
<h1 class="font-bold text-gray-700 hover:underline">{{ $post->user->name }}</h1>
</a>
</div>
</div>
</div>
</div>
@endforeach
</div>
<div class="hidden w-4/12 -mx-8 lg:block">
<div class="px-8">
<h1 class="mb-4 text-xl font-bold text-gray-700">Guild members</h1>
<div class="relative">
<ul class="space-y-12">
@foreach (auth()->user()->currentTeam->teamShifts() as $member)
@if( auth()->user()->id != $member->id)
@include('partials.member-card', ['member' => $member])
@endif
@endforeach
</ul>
</div>
</div>

</div>
</div>
</div>
{{-- @if( count($shifts) > 0 )
<div wire:click="loadMore()" class="flex items-center justify-start w-full py-2 pl-8 text-xs font-medium text-gray-500 duration-200 ease-out bg-gray-200 cursor-pointer hover:text-gray-600 hover:bg-gray-300 transition-color md:pl-0 md:justify-center">Load More</div>
@else
<div class="flex items-center justify-start w-full py-2 pl-8 text-xs font-medium text-gray-500 duration-200 ease-out bg-gray-100 transition-color md:pl-0 md:justify-center">No more entries</div>
@endif --}}
</div>
<div class="flex items-center justify-between mt-4">
<div>
@if(auth()->user()->id === $post->user_id)
<a wire:click.prevent="delete({{ $post->id }})" role="button" href="#"
class="text-red-500 hover:underline">Delete
</a>
@endif
</div>
<div>
<a class="flex items-center"><img
src="{{ $post->user->profile_photo_url }}"
alt="avatar"
class="hidden object-cover w-10 h-10 mx-4 rounded-full sm:block">
<h1 class="font-bold text-gray-700 hover:underline">{{ $post->user->name }}</h1>
</a>
</div>
</div>
</div>
</div>
</div>
@endforeach
</div>

<script type="text/javascript">
Expand Down
4 changes: 0 additions & 4 deletions resources/views/navigation-dropdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
🥇 <span class="pl-2 text-sm">Badges</span>
</a>

<a href="{{ route('feed') }}" class="@if(request()->routeIs('feed')){{ 'text-gray-800' }}@else{{ 'text-gray-400' }}@endif flex items-center pl-1 text-base font-semibold">
📖 <span class="pl-2 text-sm">Feed</span>
</a>

</div>
</div>

Expand Down
3 changes: 0 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,5 @@
Route::get('/badges/', [BadgesController::class, 'index'])
->name('badges');

// Feed routes
Route::get('/feed/', [PostsController::class, 'index'])
->name('feed');
});
});

0 comments on commit f4064d2

Please sign in to comment.