Skip to content

Commit

Permalink
setup ui
Browse files Browse the repository at this point in the history
  • Loading branch information
diegogit03 committed Jan 13, 2024
1 parent e2abe1c commit 7a749dc
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ yarn-error.log
/.fleet
/.idea
/.vscode

storage/repositories
36 changes: 36 additions & 0 deletions app/Livewire/CreateRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Livewire;

use App\Models\Repository;
use CzProject\GitPhp\Git;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate;
use Livewire\Component;

class CreateRepository extends Component
{
#[Validate('required')]
public $title = '';

public function render()
{
return view('livewire.create-repository')->extends('layouts.app');
}

public function create()
{
$this->validate();

$repository = new Repository();
$repository->title = $this->title;
$repository->user_id = Auth::id();
$repository->save();

$git = new Git();

$git->init(storage_path('repositories/' . $this->title));

$this->redirect(route('home'), navigate: true);
}
}
26 changes: 26 additions & 0 deletions app/Livewire/Repositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Livewire;

use App\Models\Repository;
use Livewire\Attributes\Computed;
use Livewire\Component;

class Repositories extends Component
{
public function render()
{
return view('livewire.repositories')->extends('layouts.app');;
}

#[Computed()]
public function repositories()
{
return Repository::all();
}

public function create()
{
return $this->redirect(route('repositories.create'), navigate: true);
}
}
16 changes: 16 additions & 0 deletions app/Models/Repository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Repository extends Model
{
use HasFactory;

protected $fillable = [
'title',
'user_id',
];
}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"license": "MIT",
"require": {
"php": "^8.1",
"blade-ui-kit/blade-icons": "^1.5",
"czproject/git-php": "^4.2",
"guzzlehttp/guzzle": "^7.2",
"laravel-frontend-presets/tall": "^7.0",
"laravel/framework": "^10.10",
Expand Down
135 changes: 134 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('repositories', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->foreignId('user_id')->constrained();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('repositories');
}
};
12 changes: 7 additions & 5 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
@extends('layouts.base')

@section('body')
@yield('content')

@isset($slot)
{{ $slot }}
@endisset
<div class="flex flex-col min-h-screen py-12 bg-gray-100 sm:px-6 lg:px-8">
@yield('content')

@isset($slot)
{{ $slot }}
@endisset
</div>
@endsection
23 changes: 23 additions & 0 deletions resources/views/livewire/create-repository.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="bg-white w-full p-5">
<form wire:submit='create'>
<h1 class="mb-2">Criar novo repositório</h1>
<div class="mb-2">
<label for="title" class="block text-sm font-medium text-gray-700 leading-5">
Titulo do repositório
</label>

<div class="mt-1 rounded-md shadow-sm">
<input wire:model="title" id="title" name="title" type="text" required autofocus class="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md placeholder-gray-400 focus:outline-none focus:ring-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5 @error('email') border-red-300 text-red-900 placeholder-red-300 focus:border-red-300 focus:ring-red @enderror" />
</div>

@error('title')
<p class="mt-2 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<div class="flex justify-end">
<button type="submit" class="flex justify-center px-4 py-2 text-sm font-medium text-white bg-indigo-600 border border-transparent rounded-md hover:bg-indigo-500 focus:outline-none focus:border-indigo-700 focus:ring-indigo active:bg-indigo-700 transition duration-150 ease-in-out">
Criar
</button>
</div>
</form>
</div>
15 changes: 15 additions & 0 deletions resources/views/livewire/repositories.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="bg-white w-full p-5">
<div class="flex justify-between items-center mb-5">
<h1>Repositorios</h1>
<button wire:click='create' type="button" class="flex justify-center px-4 py-2 text-sm font-medium text-white bg-indigo-600 border border-transparent rounded-md hover:bg-indigo-500 focus:outline-none focus:border-indigo-700 focus:ring-indigo active:bg-indigo-700 transition duration-150 ease-in-out">
Criar novo repositorio
</button>
</div>
@foreach ($this->repositories as $repository)
<div class="flex justify-between bg-gray-100 mb-3 p-3">
<span>
{{ $repository->title }}
</span>
</div>
@endforeach
</div>
7 changes: 5 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use App\Livewire\Auth\Passwords\Reset;
use App\Livewire\Auth\Register;
use App\Livewire\Auth\Verify;
use App\Livewire\CreateRepository;
use App\Livewire\Repositories;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -21,8 +23,6 @@
|
*/

Route::view('/', 'welcome')->name('home');

Route::middleware('guest')->group(function () {
Route::get('login', Login::class)
->name('login');
Expand Down Expand Up @@ -53,4 +53,7 @@

Route::post('logout', LogoutController::class)
->name('logout');

Route::get('/', Repositories::class)->name('home');
Route::get('/create', CreateRepository::class)->name('repositories.create');
});

0 comments on commit 7a749dc

Please sign in to comment.