mirror of https://github.com/pixelfed/pixelfed
Merge pull request #1209 from pixelfed/frontend-ui-refactor
Labs + Profile Suggestions Experimentpull/1238/head
commit
ccef4d0939
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Cookie, Redis;
|
||||
use App\Services\SuggestionService;
|
||||
|
||||
trait LabsSettings {
|
||||
|
||||
public function __constructor()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function labs(Request $request)
|
||||
{
|
||||
$profile = $request->user()->profile;
|
||||
return view('settings.labs', compact('profile'));
|
||||
}
|
||||
|
||||
public function labsStore(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'profile_layout' => 'nullable',
|
||||
'dark_mode' => 'nullable',
|
||||
'profile_suggestions' => 'nullable'
|
||||
]);
|
||||
|
||||
$changes = false;
|
||||
|
||||
$profile = $request->user()->profile;
|
||||
|
||||
$cookie = Cookie::forget('dark-mode');
|
||||
if($request->has('dark_mode') && $profile->profile_layout != 'moment') {
|
||||
if($request->dark_mode == 'on') {
|
||||
$cookie = Cookie::make('dark-mode', true, 43800);
|
||||
}
|
||||
}
|
||||
|
||||
if($request->has('profile_layout')) {
|
||||
if($profile->profile_layout != 'moment') {
|
||||
$profile->profile_layout = 'moment';
|
||||
$changes = true;
|
||||
} else {
|
||||
$profile->profile_layout = null;
|
||||
$changes = true;
|
||||
}
|
||||
} else {
|
||||
if($profile->profile_layout == 'moment') {
|
||||
$profile->profile_layout = null;
|
||||
$changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($request->has('profile_suggestions')) {
|
||||
if($profile->is_suggestable == false) {
|
||||
$profile->is_suggestable = true;
|
||||
$changes = true;
|
||||
SuggestionService::set($profile->id);
|
||||
} else {
|
||||
$profile->is_suggestable = false;
|
||||
$changes = true;
|
||||
SuggestionService::del($profile->id);
|
||||
}
|
||||
} else {
|
||||
if($profile->is_suggestable == true) {
|
||||
$profile->is_suggestable = false;
|
||||
$changes = true;
|
||||
SuggestionService::del($profile->id);
|
||||
}
|
||||
}
|
||||
|
||||
if($changes == true) {
|
||||
$profile->save();
|
||||
}
|
||||
|
||||
return redirect(route('settings.labs'))
|
||||
->with('status', 'Labs preferences successfully updated!')
|
||||
->cookie($cookie);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Redis;
|
||||
use App\Profile;
|
||||
|
||||
class SuggestionService {
|
||||
|
||||
const CACHE_KEY = 'pf:services:suggestion:ids';
|
||||
|
||||
public static function get($start = 0, $stop = -1)
|
||||
{
|
||||
return Redis::zrange(self::CACHE_KEY, $start, $stop);
|
||||
}
|
||||
|
||||
public static function set($val)
|
||||
{
|
||||
return Redis::zadd(self::CACHE_KEY, 1, $val);
|
||||
}
|
||||
|
||||
public static function del($val)
|
||||
{
|
||||
return Redis::zrem(self::CACHE_KEY, $val);
|
||||
}
|
||||
|
||||
public static function add($val)
|
||||
{
|
||||
return self::set($val);
|
||||
}
|
||||
|
||||
public static function rem($val)
|
||||
{
|
||||
return self::del($val);
|
||||
}
|
||||
|
||||
public static function warmCache($force = false)
|
||||
{
|
||||
if(Redis::zcount(self::CACHE_KEY, '-inf', '+inf') == 0 || $force == true) {
|
||||
$ids = Profile::whereNull('domain')
|
||||
->whereIsSuggestable(true)
|
||||
->whereIsPrivate(false)
|
||||
->pluck('id');
|
||||
foreach($ids as $id) {
|
||||
self::set($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddSuggestionsToProfilesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('profiles', function (Blueprint $table) {
|
||||
$table->boolean('is_suggestable')->default(false)->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('profiles', function (Blueprint $table) {
|
||||
$table->dropColumn('is_suggestable');
|
||||
});
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,63 @@
|
||||
@extends('settings.template')
|
||||
|
||||
@section('section')
|
||||
<div class="title">
|
||||
<h3 class="font-weight-bold">Labs</h3>
|
||||
<p class="lead">Experimental features</p>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="alert alert-primary px-3 h6 text-center">
|
||||
<strong>Warning:</strong> Some experimental features may contain bugs or missing functionality
|
||||
</div>
|
||||
<div class="py-3">
|
||||
<p class="font-weight-bold text-muted text-center">UI</p>
|
||||
<hr>
|
||||
</div>
|
||||
<form method="post">
|
||||
@csrf
|
||||
@if(config('exp.lc') == true)
|
||||
<div class="form-check pb-3">
|
||||
<input class="form-check-input" type="checkbox" checked disabled>
|
||||
<label class="form-check-label font-weight-bold">
|
||||
{{__('Hidden like counts on Timelines')}}
|
||||
</label>
|
||||
<p class="text-muted small help-text">Like counts are hidden on timelines. This experiment was enabled for all users and can only be changed by the instance administrator.</p>
|
||||
</div>
|
||||
@endif
|
||||
<div class="form-check pb-3">
|
||||
<input class="form-check-input" type="checkbox" name="profile_layout" id="profile_layout" {{$profile->profile_layout == 'moment' ? 'checked':''}} value="{{$profile->profile_layout}}">
|
||||
<label class="form-check-label font-weight-bold" for="profile_layout">
|
||||
{{__('Use MomentUI for posts and your profile')}}
|
||||
</label>
|
||||
<p class="text-muted small help-text">MomentUI offers an alternative layout for posts and your profile.</p>
|
||||
</div>
|
||||
@if($profile->profile_layout != 'moment')
|
||||
<div class="form-check pb-3">
|
||||
<input class="form-check-input" type="checkbox" name="dark_mode" id="dark_mode" {{request()->hasCookie('dark-mode') ? 'checked':''}}>
|
||||
<label class="form-check-label font-weight-bold" for="dark_mode">
|
||||
{{__('MetroUI Dark Mode')}}
|
||||
</label>
|
||||
<p class="text-muted small help-text">Use dark mode theme.</p>
|
||||
</div>
|
||||
@endif
|
||||
<div class="py-3">
|
||||
<p class="font-weight-bold text-muted text-center">Discovery</p>
|
||||
<hr>
|
||||
</div>
|
||||
@if(config('exp.rec') == true)
|
||||
<div class="form-check pb-3">
|
||||
<input class="form-check-input" type="checkbox" name="profile_suggestions" id="profile_suggestions" {{$profile->is_suggestable ? 'checked' : ''}}>
|
||||
<label class="form-check-label font-weight-bold" for="profile_suggestions">
|
||||
{{__('Visible on Profile Suggestions')}}
|
||||
</label>
|
||||
<p class="text-muted small help-text">Allow your profile to be listed in Profile Suggestions.</p>
|
||||
</div>
|
||||
@endif
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<hr>
|
||||
<button type="submit" class="btn btn-primary font-weight-bold py-1 btn-block">Save Changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
Loading…
Reference in New Issue