Merge pull request #488 from pixelfed/frontend-ui-refactor

Frontend ui refactor
This commit is contained in:
daniel 2018-09-26 23:04:00 -06:00 committed by GitHub
commit af5cc6e557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 136 additions and 36 deletions

View file

@ -2,43 +2,86 @@
namespace App\Http\Controllers;
use Auth;
use App\Hashtag;
use App\Profile;
use App\Status;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class SearchController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function searchAPI(Request $request, $tag)
{
$res = Cache::remember('api:search:tag:'.$tag, 1440, function () use ($tag) {
$res = Hashtag::where('slug', 'like', '%'.$tag.'%')->get();
$tags = $res->map(function ($item, $key) {
return [
'count' => $item->posts()->count(),
'url' => $item->url(),
'type' => 'hashtag',
'value' => $item->name,
'tokens' => explode('-', $item->name),
'name' => null,
];
});
$res = Profile::where('username', 'like', '%'.$tag.'%')->get();
$profiles = $res->map(function ($item, $key) {
return [
'count' => 0,
'url' => $item->url(),
'type' => 'profile',
'value' => $item->username,
'tokens' => [$item->username],
'name' => $item->name,
];
});
$tags = $tags->push($profiles[0]);
if(mb_strlen($tag) < 3) {
return;
}
$hash = hash('sha256', $tag);
$tokens = Cache::remember('api:search:tag:'.$hash, 60, function () use ($tag) {
$tokens = collect([]);
$hashtags = Hashtag::select('id', 'name', 'slug')->where('slug', 'like', '%'.$tag.'%')->limit(20)->get();
if($hashtags->count() > 0) {
$tags = $hashtags->map(function ($item, $key) {
return [
'count' => $item->posts()->count(),
'url' => $item->url(),
'type' => 'hashtag',
'value' => $item->name,
'tokens' => explode('-', $item->name),
'name' => null,
];
});
$tokens->push($tags);
}
$users = Profile::select('username', 'name', 'id')->where('username', 'like', '%'.$tag.'%')->limit(20)->get();
return $tags;
if($users->count() > 0) {
$profiles = $users->map(function ($item, $key) {
return [
'count' => 0,
'url' => $item->url(),
'type' => 'profile',
'value' => $item->username,
'tokens' => [$item->username],
'name' => $item->name,
];
});
$tokens->push($profiles);
}
return $tokens;
});
$posts = Status::select('id', 'profile_id', 'caption', 'created_at')
->whereHas('media')
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereProfileId(Auth::user()->profile->id)
->where('caption', 'like', '%'.$tag.'%')
->orderBy('created_at', 'desc')
->get();
return response()->json($res);
if($posts->count() > 0) {
$posts = $posts->map(function($item, $key) {
return [
'count' => 0,
'url' => $item->url(),
'type' => 'status',
'value' => 'Posted '.$item->created_at->diffForHumans(),
'tokens' => [$item->caption],
'name' => $item->caption,
'thumb' => $item->thumb(),
];
});
$tokens = $tokens->push($posts);
}
if($tokens->count() > 0) {
$tokens = $tokens[0];
}
return response()->json($tokens);
}
}

View file

@ -85,7 +85,13 @@ class StatusController extends Controller
}
$this->validate($request, [
'photo.*' => 'required|mimes:jpeg,png,gif|max:'.config('pixelfed.max_photo_size'),
'photo.*' => function() {
return [
'required',
'mimes:' . config('pixelfed.media_types'),
'max:' . config('pixelfed.max_photo_size'),
];
},
'caption' => 'string|max:'.config('pixelfed.max_caption_length'),
'cw' => 'nullable|string',
'filter_class' => 'nullable|string',

View file

@ -196,6 +196,30 @@ class Profile extends Model
->pluck('filterable_id');
}
public function blockedIds()
{
return UserFilter::whereUserId($this->id)
->whereFilterableType('App\Profile')
->whereFilterType('block')
->pluck('filterable_id');
}
public function mutedProfileUrls()
{
$ids = $this->mutedIds();
return $this->whereIn('id', $ids)->get()->map(function($i) {
return $i->url();
});
}
public function blockedProfileUrls()
{
$ids = $this->blockedIds();
return $this->whereIn('id', $ids)->get()->map(function($i) {
return $i->url();
});
}
public function reports()
{
return $this->hasMany(Report::class, 'profile_id');

BIN
public/css/app.css vendored

Binary file not shown.

BIN
public/js/app.js vendored

Binary file not shown.

BIN
public/js/timeline.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -13,21 +13,21 @@ $(document).ready(function() {
name: 'search',
display: 'value',
source: queryEngine,
limit: 20,
limit: 40,
templates: {
empty: [
'<div class="alert alert-danger mb-0">',
'unable to find any matches',
'<div class="alert alert-info mb-0 font-weight-bold">',
'No Results Found',
'</div>'
].join('\n'),
suggestion: function(data) {
let type = data.type;
let res = null;
let res = false;
switch(type) {
case 'hashtag':
res = '<a href="'+data.url+'">' +
'<div class="media d-flex align-items-center">' +
'<div class="mr-3 h4 text-muted">#</div>' +
'<div class="mr-3 h4 text-muted"><span class="fas fa-hashtag"></span></div>' +
'<div class="media-body text-truncate">' +
'<p class="mt-0 mb-0 font-weight-bold">'+data.value+'</p>' +
'<p class="text-muted mb-0">'+data.count+' posts</p>' +
@ -38,7 +38,7 @@ $(document).ready(function() {
case 'profile':
res = '<a href="'+data.url+'">' +
'<div class="media d-flex align-items-center">' +
'<div class="mr-3 h4 text-muted"><span class="icon-user"></span></div>' +
'<div class="mr-3 h4 text-muted"><span class="far fa-user"></span></div>' +
'<div class="media-body text-truncate">' +
'<p class="mt-0 mb-0 font-weight-bold">'+data.name+'</p>' +
'<p class="text-muted mb-0">'+data.value+'</p>' +
@ -46,8 +46,24 @@ $(document).ready(function() {
'</div>' +
'</a>';
break;
case 'status':
res = '<a href="'+data.url+'">' +
'<div class="media d-flex align-items-center">' +
'<div class="mr-3 h4 text-muted"><img src="'+data.thumb+'" width="32px"></div>' +
'<div class="media-body text-truncate">' +
'<p class="mt-0 mb-0 font-weight-bold">'+data.name+'</p>' +
'<p class="text-muted mb-0">'+data.value+'</p>' +
'</div>' +
'</div>' +
'</a>';
break;
default:
res = false;
break;
}
if(res !== false) {
return res;
}
return res;
}
}
});

View file

@ -3,7 +3,12 @@ $(document).ready(function() {
$('.container.timeline-container').removeClass('d-none');
let elem = document.querySelector('.timeline-feed');
pixelfed.fetchLikes();
$('video').on('play', function() {
activated = this;
$('video').each(function() {
if(this != activated) this.pause();
});
});
let infScroll = new InfiniteScroll( elem, {
path: '.pagination__next',
append: '.timeline-feed',
@ -19,6 +24,12 @@ $(document).ready(function() {
$(this).addClass('d-none');
}
});
$('video').on('play', function() {
activated = this;
$('video').each(function() {
if(this != activated) this.pause();
});
});
});

View file

@ -16,7 +16,7 @@
<div class="form-group row">
<div class="col-md-12">
<input id="code" type="code" class="form-control{{ $errors->has('code') ? ' is-invalid' : '' }}" name="code" placeholder="{{__('Two-Factor Authentication Code')}}" required autocomplete="off">
<input id="code" type="text" class="form-control{{ $errors->has('code') ? ' is-invalid' : '' }}" name="code" placeholder="{{__('Two-Factor Authentication Code')}}" required autocomplete="off" autofocus="">
@if ($errors->has('code'))
<span class="invalid-feedback">