Skip to content

Commit a1d71dd

Browse files
list cards
1 parent 3c60981 commit a1d71dd

File tree

8 files changed

+109
-109
lines changed

8 files changed

+109
-109
lines changed

app/Http/Controllers/Memory/FlashCardController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ public function store(Request $request)
2626

2727
return to_route('dashboard');
2828
}
29+
30+
public function index(Request $request)
31+
{
32+
$cards = Card::query()
33+
->where('user_id', $request->user()->id)
34+
->latest()
35+
->get();
36+
37+
return inertia('flashcard/Card', [
38+
'cards' => $cards,
39+
]);
40+
}
2941
}

resources/js/components/AppSidebar.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NavUser from '@/components/NavUser.vue';
55
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from '@/components/ui/sidebar';
66
import { type NavItem } from '@/types';
77
import { Link } from '@inertiajs/vue3';
8-
import { BookOpen, Folder, LayoutGrid } from 'lucide-vue-next';
8+
import { BookOpen, Folder, LayoutGrid, Drama } from 'lucide-vue-next';
99
import AppLogo from './AppLogo.vue';
1010
1111
const mainNavItems: NavItem[] = [
@@ -14,6 +14,11 @@ const mainNavItems: NavItem[] = [
1414
href: '/dashboard',
1515
icon: LayoutGrid,
1616
},
17+
{
18+
title: 'FlashCards',
19+
href: '/flashcards',
20+
icon: Drama,
21+
}
1722
];
1823
1924
const footerNavItems: NavItem[] = [

resources/js/components/flashcards/ListMemoriesCard.vue

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script setup lang="ts">
2+
import type { Card as CardType } from '@/types'
3+
defineProps<{ card: CardType }>()
4+
5+
import {
6+
Card, CardHeader, CardTitle, CardContent, CardFooter
7+
} from '@/components/ui/card'
8+
import {
9+
Accordion, AccordionContent, AccordionItem, AccordionTrigger
10+
} from '@/components/ui/accordion'
11+
</script>
12+
13+
<template>
14+
<Card class="w-full mx-auto p-6 rounded-xl my-3">
15+
<CardHeader>
16+
<CardTitle class="text-lg font-medium tracking-tight">
17+
{{ card.created_at }}
18+
</CardTitle>
19+
20+
<div class="space-y-4 mt-4">
21+
<div v-if="card.type === 'FlashCards'">
22+
<h4 class="font-medium">Pergunta</h4>
23+
<p class="text-sm text-muted-foreground">{{ card.question }}</p>
24+
25+
<h4 class="font-medium mt-4">Resposta</h4>
26+
<p class="text-sm text-muted-foreground">{{ card.answer }}</p>
27+
</div>
28+
29+
<div v-else>
30+
<h4 class="font-medium">Texto</h4>
31+
<p class="text-sm text-muted-foreground whitespace-pre-wrap">
32+
{{ card.answer }}
33+
</p>
34+
</div>
35+
</div>
36+
</CardHeader>
37+
38+
<CardContent>
39+
<Accordion type="single" collapsible>
40+
<AccordionItem value="extra">
41+
<AccordionTrigger>Visualizar mais</AccordionTrigger>
42+
<AccordionContent>
43+
{{ card.explanation }}
44+
</AccordionContent>
45+
</AccordionItem>
46+
</Accordion>
47+
</CardContent>
48+
</Card>
49+
</template>

resources/js/components/flashcards/NewFlashCard.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ watch(() => form.cardType, (val) => {
3030
3131
/* 4. Envio --------------------------------------------------------------- */
3232
function handleSubmit() {
33-
form.post(route('memory.flashcards.store'), {
33+
form.post(route('flashcards.store'), {
3434
onSuccess: () => form.reset('question', 'answer'),
3535
})
3636
}
@@ -39,7 +39,7 @@ function handleSubmit() {
3939
async function generateAIAnswer() {
4040
if (!form.question.trim()) return
4141
// supondo que exista essa rota
42-
const { data } = await router.post(route('memory.ai'), { question: form.question })
42+
const { data } = await router.post(route('flashcards.ai'), { question: form.question })
4343
form.answer = data.answer
4444
}
4545
</script>

resources/js/pages/Dashboard.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const breadcrumbs: BreadcrumbItem[] = [
2020

2121
<AppLayout :breadcrumbs="breadcrumbs">
2222
<div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4">
23-
<!-- <div class="grid auto-rows-min gap-4 md:grid-cols-3">
23+
<div class="grid auto-rows-min gap-4 md:grid-cols-3">
2424
<div
2525
class="relative aspect-video overflow-hidden rounded-xl border border-sidebar-border/70 dark:border-sidebar-border">
2626
<PlaceholderPattern />
@@ -33,11 +33,7 @@ const breadcrumbs: BreadcrumbItem[] = [
3333
class="relative aspect-video overflow-hidden rounded-xl border border-sidebar-border/70 dark:border-sidebar-border">
3434
<PlaceholderPattern />
3535
</div>
36-
</div> -->
37-
38-
<NewFlashCard />
39-
40-
<ListMemoriesCard />
36+
</div>
4137
</div>
4238
</AppLayout>
4339
</template>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script setup lang="ts">
2+
import AppLayout from '@/layouts/AppLayout.vue';
3+
import { type BreadcrumbItem } from '@/types';
4+
import { Head } from '@inertiajs/vue3';
5+
import PlaceholderPattern from '../components/PlaceholderPattern.vue';
6+
7+
import NewFlashCard from '@/components/flashcards/NewFlashCard.vue';
8+
import MemoryCard from '@/components/flashcards/MemoryCard.vue';
9+
10+
/* props vindas do back-end -------------------------------------------- */
11+
const props = defineProps<{ cards: Array<any> }>()
12+
13+
const breadcrumbs: BreadcrumbItem[] = [
14+
{
15+
title: 'FlashCards',
16+
href: '/flashcards',
17+
},
18+
];
19+
</script>
20+
21+
<template>
22+
23+
<Head title="FlashCards" />
24+
25+
<AppLayout :breadcrumbs="breadcrumbs">
26+
<div class="flex h-full flex-1 flex-col gap-4 rounded-xl p-4">
27+
28+
<NewFlashCard />
29+
30+
<!-- lista recebe o array de cards -->
31+
<div v-if="props.cards.length">
32+
<MemoryCard v-for="card in props.cards" :key="card.id" :card="card" />
33+
</div>
34+
</div>
35+
</AppLayout>
36+
</template>

routes/web.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
return Inertia::render('Dashboard');
1515
})->name('dashboard');
1616

17-
Route::prefix('memory')->as('memory.')->group(function () {
18-
Route::resource('flashcards', FlashCardController::class)->only(['store']);
17+
Route::as('memory.')->group(function () {
18+
Route::resource('flashcards', FlashCardController::class)->only(['store', 'index']);
1919
});
2020
});
2121

0 commit comments

Comments
 (0)