浏览代码

Update account settings, add hashtags to relationships

Daniel Supernault 6 年之前
父节点
当前提交
506208f545

+ 2 - 2
app/Hashtag.php

@@ -20,8 +20,8 @@ class Hashtag extends Model
       );
     }
 
-    public function url()
+    public function url($suffix = '')
     {
-        return config('routes.hashtag.base').$this->slug;
+        return config('routes.hashtag.base').$this->slug.$suffix;
     }
 }

+ 21 - 7
app/Http/Controllers/Settings/RelationshipSettings.php

@@ -18,15 +18,29 @@ trait RelationshipSettings
 
 	public function relationshipsHome(Request $request)
 	{
-		$mode = $request->input('mode') == 'following' ? 'following' : 'followers';
-		$profile = Auth::user()->profile;
+		$this->validate($request, [
+			'mode' => 'nullable|string|in:following,followers,hashtags'
+		]);
 
-		$following = $followers = [];
+		$mode = $request->input('mode');
+		$profile = Auth::user()->profile;
 
-		if($mode == 'following') {
-			$data = $profile->following()->simplePaginate(10);
-		} else {
-			$data = $profile->followers()->simplePaginate(10);
+		switch ($mode) {
+			case 'following':
+				$data = $profile->following()->simplePaginate(10);
+				break;
+
+			case 'followers':
+				$data = $profile->followers()->simplePaginate(10);
+				break;
+
+			case 'hashtags':
+				$data = $profile->hashtagFollowing()->with('hashtag')->simplePaginate(10);
+				break;
+			
+			default:
+				$data = [];
+				break;
 		}
 
 		return view('settings.relationships.home', compact('profile', 'mode', 'data'));

+ 5 - 0
app/Profile.php

@@ -278,4 +278,9 @@ class Profile extends Model
             'hashtag_id'
         );
     }
+
+    public function hashtagFollowing()
+    {
+        return $this->hasMany(HashtagFollow::class);
+    }
 }

+ 3 - 3
resources/views/settings/partial/sidebar.blade.php

@@ -9,9 +9,6 @@
       <li class="nav-item pl-3 {{request()->is('settings/email')?'active':''}}">
         <a class="nav-link font-weight-light text-muted" href="{{route('settings.email')}}">Email</a>
       </li>
-      <li class="nav-item pl-3 {{request()->is('settings/relationships*')?'active':''}}">
-        <a class="nav-link font-weight-light text-muted" href="{{route('settings.relationships')}}">Followers</a>
-      </li>
       @if(config('pixelfed.user_invites.enabled'))
       <li class="nav-item pl-3 {{request()->is('settings/invites*')?'active':''}}">
         <a class="nav-link font-weight-light text-muted" href="{{route('settings.invites')}}">Invites</a>
@@ -26,6 +23,9 @@
       <li class="nav-item pl-3 {{request()->is('settings/privacy*')?'active':''}}">
         <a class="nav-link font-weight-light text-muted" href="{{route('settings.privacy')}}">Privacy</a>
       </li>
+      <li class="nav-item pl-3 {{request()->is('settings/relationships*')?'active':''}}">
+        <a class="nav-link font-weight-light text-muted" href="{{route('settings.relationships')}}">Relationships</a>
+      </li>
       <li class="nav-item pl-3 {{request()->is('settings/reports*')?'active':''}}">
         <a class="nav-link font-weight-light text-muted" href="{{route('settings.reports')}}">Reports</a>
       </li>

+ 44 - 5
resources/views/settings/relationships/home.blade.php

@@ -3,23 +3,50 @@
 @section('section')
 
 <div class="title">
-	<h3 class="font-weight-bold">Followers & Following</h3>
+	<h3 class="font-weight-bold">Relationships</h3>
 </div>
 <hr>
-@if(empty($data))
-<p class="text-center lead pt-5 mt-5">You are not {{$mode == 'following' ? 'following anyone.' : 'followed by anyone.'}}</p>
-@else
 <ul class="nav nav-pills">
 	<li class="nav-item">
-		<a class="nav-link font-weight-bold {{$mode == 'followers' ? 'active' : ''}}" href="?mode=followers&page=1">Followers</a>
+		<a class="nav-link font-weight-bold {{!request()->has('mode') || $mode == 'followers' ? 'active' : ''}}" href="?mode=followers&page=1">Followers</a>
 	</li>
 	<li class="nav-item">
 		<a class="nav-link font-weight-bold {{$mode == 'following' ? 'active' : ''}}" href="?mode=following&page=1">Following</a>
 	</li>
+	<li class="nav-item">
+		<a class="nav-link font-weight-bold {{$mode == 'hashtags' ? 'active' : ''}}" href="?mode=hashtags&page=1">Hashtags</a>
+	</li>
 </ul>
 <hr>
+@if(empty($data))
+<p class="text-center lead pt-5 mt-5">You are not {{$mode == 'hashtags' ? 'following any hashtags.' : ($mode == 'following' ? 'following anyone.' : 'followed by anyone.')}}</p>
+@else
 <div class="table-responsive">
 <table class="table table-bordered table-hover">
+		@if($mode == 'hashtags')
+	<thead>
+		<tr>
+			{{-- <th scope="col" class="pt-0 pb-1 mt-0">
+				<input type="checkbox" name="check" class="form-control check-all">
+			</th> --}}
+			<th scope="col">Hashtag</th>
+			<th scope="col">Action</th>
+		</tr>
+	</thead>
+	<tbody>
+		@foreach($data as $hashtag)
+		<tr>
+			<td class="font-weight-bold">
+				<a href="{{$hashtag->hashtag->url('?src=relset')}}" class="text-decoration-none text-dark">
+					<p class="mb-0 pb-0">#{{$hashtag->hashtag->name}}</p>
+				</a>
+			</td>
+			<td class="text-center">
+				<a class="btn btn-outline-danger btn-sm py-0 action-btn" href="#" data-id="{{$hashtag->hashtag->name}}" data-action="unfollowhashtag">Unfollow</a>
+			</td>
+		</tr>
+		@endforeach
+		@else
 	<thead>
 		<tr>
 			{{-- <th scope="col" class="pt-0 pb-1 mt-0">
@@ -52,6 +79,7 @@
 			@endif
 		</tr>
 		@endforeach
+		@endif
 	</tbody>
 </table>
 </div>
@@ -113,6 +141,17 @@
 						);
 				});
 				break;
+
+				case 'unfollowhashtag':
+				axios.post('/api/local/discover/tag/subscribe', {
+					name: id
+				}).then(res => {
+					swal(
+						'Unfollow Successful',
+						'You have successfully unfollowed that hashtag',
+						'success'
+						);
+				});
 			}
 			setTimeout(function() {
 				window.location.href = window.location.href;