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

Frontend ui refactor
pull/614/head
daniel 7 years ago committed by GitHub
commit ff535072a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,7 @@
namespace App; namespace App;
use Auth; use Auth, Cache;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Storage; use Storage;
@ -37,26 +37,29 @@ class Status extends Model
public function viewType() public function viewType()
{ {
$media = $this->firstMedia(); return Cache::remember('status:view-type:'.$this->id, 40320, function() {
$mime = explode('/', $media->mime)[0]; $media = $this->firstMedia();
$count = $this->media()->count(); $mime = explode('/', $media->mime)[0];
$type = ($mime == 'image') ? 'image' : 'video'; $count = $this->media()->count();
if($count > 1) { $type = ($mime == 'image') ? 'image' : 'video';
$type = ($type == 'image') ? 'album' : 'video-album'; if($count > 1) {
} $type = ($type == 'image') ? 'album' : 'video-album';
}
return $type; return $type;
});
} }
public function thumb($showNsfw = false) public function thumb($showNsfw = false)
{ {
$type = $this->viewType(); return Cache::remember('status:thumb:'.$this->id, 40320, function() use ($showNsfw) {
$is_nsfw = !$showNsfw ? $this->is_nsfw : false; $type = $this->viewType();
if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['image', 'album', 'video'])) { $is_nsfw = !$showNsfw ? $this->is_nsfw : false;
return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['image', 'album', 'video'])) {
} return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
}
return url(Storage::url($this->firstMedia()->thumbnail_path));
return url(Storage::url($this->firstMedia()->thumbnail_path));
});
} }
public function url() public function url()

@ -72,7 +72,32 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
$(document).on('click', '.modal-update', function(e) {
$(document).on('click', '.modal-close', function(e) {
swal.close();
});
$('#bio').on('change keyup paste', function(e) {
let el = $(this);
let len = el.val().length;
let limit = el.data('max-length');
if(len > 100) {
el.attr('rows', '4');
}
let val = len + ' / ' + limit;
if(len > limit) {
let diff = len - limit;
val = '<span class="text-danger">-' + diff + '</span> / ' + limit;
}
$('.bio-counter').html(val);
});
$(document).on('click', '.change-profile-photo', function(e) {
e.preventDefault();
swal({ swal({
title: 'Upload Photo', title: 'Upload Photo',
content: { content: {
@ -90,6 +115,9 @@
} }
} }
}).then((res) => { }).then((res) => {
if(!res) {
return;
}
const input = $('#photoUploadInput')[0]; const input = $('#photoUploadInput')[0];
const photo = input.files[0]; const photo = input.files[0];
const form = new FormData(); const form = new FormData();
@ -107,53 +135,5 @@
}); });
}); });
}); });
$(document).on('click', '.modal-close', function(e) {
swal.close();
});
$('#bio').on('change keyup paste', function(e) {
let el = $(this);
let len = el.val().length;
let limit = el.data('max-length');
if(len > 100) {
el.attr('rows', '4');
}
let val = len + ' / ' + limit;
if(len > limit) {
let diff = len - limit;
val = '<span class="text-danger">-' + diff + '</span> / ' + limit;
}
$('.bio-counter').html(val);
});
$(document).on('click', '.change-profile-photo', function(e) {
e.preventDefault();
var content = $('<ul>').addClass('list-group');
var upload = $('<li>').text('Upload photo').addClass('list-group-item');
content.append(upload);
const list = document.createElement('ul');
list.className = 'list-group';
const uploadPhoto = document.createElement('li');
uploadPhoto.innerHTML = 'Upload Photo';
uploadPhoto.className = 'list-group-item font-weight-bold text-primary modal-update';
list.appendChild(uploadPhoto);
const cancel = document.createElement('li');
cancel.innerHTML = 'Cancel';
cancel.className = 'list-group-item modal-close';
list.appendChild(cancel);
swal({
title: 'Change Profile Photo',
content: list,
buttons: false
});
});
</script> </script>
@endpush @endpush

Loading…
Cancel
Save