Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank Infyom committed Oct 20, 2023
1 parent b676d40 commit 5b595b0
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 1 deletion.
51 changes: 51 additions & 0 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Http\Controllers;

use App\Models\Task;
use Illuminate\Http\Request;
use Inertia\Inertia;

class TaskController extends Controller
{

public function index(){


$tasks = Task::select(['id', 'title', 'description', 'order', 'completed', 'section']);
$allTasks = $tasks->get();
$currentTasks = $allTasks->where('completed',false)->groupBy('section')->toArray();
$completedTasks = $tasks->where('completed',1)->get()->toArray();

return Inertia::render('Todo/Todo', [
'tasks' => $currentTasks,
'completedTasks' => $completedTasks
]);
}

public function store(Request $request)
{
$request->validate([
'title' => 'required',
]);

Task::create($request->all());

return to_route('todo.index');
}

public function update(Request $request, $id)
{

Task::find($id)->update($request->all());

return to_route('todo.index');
}

public function destroy($id)
{
Task::find($id)->delete();

return to_route('todo.index');
}
}
19 changes: 19 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Models;

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

class Task extends Model
{
use HasFactory;

protected $fillable=[
'title',
'description',
'order',
'completed',
'section',
];
}
32 changes: 32 additions & 0 deletions database/migrations/2023_10_19_092147_create_tasks_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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('tasks', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('description')->nullable();
$table->integer('order')->nullable();
$table->boolean('completed')->default(false);
$table->integer('section')->default(0);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tasks');
}
};
143 changes: 142 additions & 1 deletion package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"vite": "^4.0.0"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@inertiajs/react": "^1.0.11",
"@vitejs/plugin-react": "^4.0.4",
"@vitejs/plugin-react-refresh": "^1.3.6",
Expand Down
5 changes: 5 additions & 0 deletions resources/js/Pages/Keys.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const AllSection = {
"backlog" : 0,
'inProgress' : 1,
'done' : 2
};
27 changes: 27 additions & 0 deletions resources/js/Pages/Todo/AddTask.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { router } from "@inertiajs/react";
import React, { useState } from "react";
import {AllSection} from "../Keys.jsx"

export default function AddTask(props) {
const { section,hideNewTaskCard } = props;
const [ task , setTask ] = useState('');
const addNewTask = () => {
hideNewTaskCard();
router.post('/todo', {
title:task,
section : AllSection[section]
});
}

return (
<div className="card my-2">
<div className="d-flex justify-content-between align-items-center bg-light ">
<input className="mb-0 form-control" value={task} onChange={(e) => setTask(e.target.value)}/>
<div className="d-flex align-items-center">
<button className="btn text-danger" onClick={addNewTask}>Add</button>
</div>
</div>
</div>
);

}
Loading

0 comments on commit 5b595b0

Please sign in to comment.