Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Remove media types #31

Merged
merged 2 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions app/Enums/MediaType.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Http/Controllers/ApiControllers/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\ApiControllers;

use App\Enums\MediaType;
use App\Helpers\WebpageData;
use App\Http\Controllers\Controller;
use App\Models\Link;
Expand All @@ -19,7 +18,6 @@ protected function rules(): array
return [
'title' => 'string|min:2|nullable',
'link' => 'url|required',
'mediaType' => [new Enum(MediaType::class), 'nullable'],
'groups' => 'array',
];
}
Expand Down
12 changes: 0 additions & 12 deletions app/Http/Controllers/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Enums\MediaType;
use App\Helpers\WebpageData;
use App\Models\Group;
use App\Models\Link;
Expand All @@ -22,7 +21,6 @@ protected function rules(): array
return [
'title' => 'string|min:2|nullable',
'link' => 'url|required',
'mediaType' => [new Enum(MediaType::class), 'nullable'],
'groups' => 'array',
];
}
Expand All @@ -47,10 +45,6 @@ public function index(array $filteredTags = []): Response
'title' => $link->title,
'link' => $link->link,
'id' => $link->id,
'media_type' => $link->media_type !== null ? (object)[
'value' => $link->media_type->value,
'label' => $link->media_type->getLabel(),
] : null,
'tags' => TagController::getTagsOfLink($link),
'groups' => $link->groups
->sortBy('title')
Expand Down Expand Up @@ -88,7 +82,6 @@ public function store(Request $request): RedirectResponse

$link->link = Request::get('link');
$link->title = Request::get('title');
$link->media_type = Request::get('mediaType');
$link->user_id = Auth::id();

if (empty($link->title)) {
Expand Down Expand Up @@ -128,10 +121,6 @@ public function show(int $link): Response|RedirectResponse
'title' => $link->title,
'link' => $link->link,
'id' => $link->id,
'media_type' => $link->media_type !== null ? (object)[
'value' => $link->media_type->value,
'label' => $link->media_type->getLabel(),
] : null,
'tags' => TagController::getTagsOfLink($link),
'linkGroups' => $link->groups
->sortBy('title')
Expand Down Expand Up @@ -170,7 +159,6 @@ public function update(Request $request, Link $link)

$link->link = Request::get('link');
$link->title = Request::get('title');
$link->media_type = Request::get('mediaType');

if (empty($link->title)) {
$link->title = WebpageData::getWebPageTitle($link->link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public static function getData(): object
'title' => $link->title,
'link' => $link->link,
'id' => $link->id,
'mediaType' => $link->media_type,
'createdAt' => DateHelper::convertToDateString($link->created_at),
]),
];
Expand Down
3 changes: 0 additions & 3 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace App\Http\Middleware;

use App\Enums\MediaType;
use App\Models\Link;
use Illuminate\Http\Request;
use Inertia\Middleware;
use Spatie\Tags\Tag;

class HandleInertiaRequests extends Middleware
{
Expand Down
6 changes: 0 additions & 6 deletions app/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Models;

use App\Enums\MediaType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
Expand All @@ -16,11 +15,6 @@ class Link extends Model
protected $fillable = [
'title',
'link',
'media_type'
];

protected $casts = [
'media_type' => MediaType::class,
];

/**
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"pestphp/pest": "^1.16",
"pestphp/pest-plugin-laravel": "^1.1",
"tightenco/ziggy": "^1.0",
"spatie/laravel-tags": "^4.3.0"
"spatie/laravel-tags": "^4.3.0",
"doctrine/dbal": "^3.5.1"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('links', function (Blueprint $table) {
$table->dropColumn('media_type');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

}
};
6 changes: 0 additions & 6 deletions resources/js/Pages/SingleLink/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
</a>
</div>
<div class="mt-4 md:mt-0">
{#if link.media_type !== null}
<div
class="mb-1.5 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800">
{link.media_type.label}
</div>
{/if}
<h2 class="text-lg leading-6 font-medium text-gray-900">{link.title}</h2>
<p class="mt-1 text-sm text-gray-600 leading-snug break-all">
<a href={link.link} target="_blank" rel="noreferrer noopener nofollow">{link.link}</a>
Expand Down
125 changes: 0 additions & 125 deletions resources/js/Partials/LinkModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,23 @@
let showModal = false;
let isEditing = false;
let linkId = null;
let showMediaTypeDropdown = false;
let tags = [];
let allMediaTypes = [];
let refreshMediaTypes = true;
let groupSelectMenu;
let selectedGroups = [];

// Reactive statements
$: selectedMediaType = allMediaTypes.find((e) => {
if (e.value === null) {
return null
}

return e.value === $linkForm.mediaType;
});

$: $linkForm.groups = selectedGroups;

// Forms
let linkForm = useForm({
link: null,
title: null,
mediaType: null,
tags: [],
groups: [],
});

// External functions
export function prepareCreateNewLink() {
showMediaTypeDropdown = false;
getAllTags();
getMediaTypes();

if (isEditing) {
isEditing = false;
Expand All @@ -69,19 +54,15 @@

let link = e.detail;

showMediaTypeDropdown = false;

$linkForm.link = link.link;
$linkForm.title = link.title;
$linkForm.mediaType = link.media_type?.value ?? null;
selectedGroups = link.groups;

link.tags.forEach(tag => $linkForm.tags = [...$linkForm.tags, tag.id]);

linkId = link.id;

getAllTags();
getMediaTypes();

isEditing = true;

Expand Down Expand Up @@ -135,17 +116,6 @@
}
}

function getMediaTypes() {
if (refreshMediaTypes) {
axios.get('/media-types')
.then(response => {
allMediaTypes = response.data;
});

refreshMediaTypes = false;
}
}

async function openGroupSelectMenu() {
groupSelectMenu.enableMultiSelectMode();
await groupSelectMenu.setSelectedGroups(selectedGroups);
Expand Down Expand Up @@ -180,101 +150,6 @@
</div>
</div>

<div class="sm:grid sm:grid-cols-5 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5">
<span class="block text-sm text-left font-medium text-gray-700 sm:mt-px sm:pt-2">
Media type
</span>
<div class="max-w-xl mt-1 relative sm:mt-0 sm:col-span-2">
<button on:click={() => showMediaTypeDropdown = !showMediaTypeDropdown}
type="button"
class="bg-white relative w-full border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
aria-haspopup="listbox" aria-expanded="true" aria-labelledby="media-type-label">
<span class="block truncate" id="media-type-dropdown-label">
{selectedMediaType?.label ?? 'Select media type'}
</span>
<span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
<!-- Heroicon name: solid/selector -->
<svg class="h-5 w-5 text-gray-400" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z"
clip-rule="evenodd"/>
</svg>
</span>
</button>

{#if $linkForm.errors.mediaType}
<div class="text-yellow-800">{$linkForm.errors.mediaType}</div>
{/if}

{#if showMediaTypeDropdown}
<ul use:clickOutside on:click_outside={() => showMediaTypeDropdown = false}
class="absolute bottom-12 z-10 mt-1 w-full bg-white shadow-lg max-h-32 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
tabindex="-1" role="listbox" aria-labelledby="listbox-label"
aria-activedescendant="listbox-option-3">
<!--
Select option, manage highlight styles based on mouseenter/mouseleave and keyboard navigation.

Highlighted: "text-white bg-indigo-600", Not Highlighted: "text-gray-900"
-->

<li on:click|preventDefault={() => {$linkForm.mediaType = null; showMediaTypeDropdown = false}}
class="text-gray-900 cursor-default select-none relative py-2 pl-3 pr-9" role="option">
<!-- Selected: "font-semibold", Not Selected: "font-normal" -->
<span class="font-normal block truncate">
No specific media type
</span>

<!--
Checkmark, only display for selected option.

Highlighted: "text-white", Not Highlighted: "text-indigo-600"
-->
<span class:hidden={$linkForm.mediaType !== null}
class="text-indigo-600 absolute inset-y-0 right-0 flex items-center pr-4">
<!-- Heroicon name: solid/check -->
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clip-rule="evenodd"/>
</svg>
</span>
</li>

{#each allMediaTypes as mediaType (mediaType.value)}
<li on:click|preventDefault={() => {$linkForm.mediaType = mediaType.value; showMediaTypeDropdown = false}}
class="text-gray-900 cursor-default select-none relative py-2 pl-3 pr-9" role="option">
<!-- Selected: "font-semibold", Not Selected: "font-normal" -->
<span class="font-normal block truncate">
{mediaType.label}
</span>

<!--
Checkmark, only display for selected option.

Highlighted: "text-white", Not Highlighted: "text-indigo-600"
-->
<span class:hidden={mediaType.value !== $linkForm.mediaType}
class="text-indigo-600 absolute inset-y-0 right-0 flex items-center pr-4">
<!-- Heroicon name: solid/check -->
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
clip-rule="evenodd"/>
</svg>
</span>
</li>
{/each}
</ul>
{/if}
</div>
</div>

<!-- Tags -->
<div class="space-y-3 sm:border-t sm:border-gray-200 sm:pt-2">
{#each tags as tag (tag.id)}
Expand Down
Loading