File tree Expand file tree Collapse file tree 4 files changed +27
-15
lines changed
Expand file tree Collapse file tree 4 files changed +27
-15
lines changed Original file line number Diff line number Diff line change 11class TopicsController < ApplicationController
2+ before_action :verify_user , except : [ :index , :show ]
3+
24 def index
35 topics = Topic . all
46 . includes ( :user , :category , messages : :user )
@@ -45,4 +47,8 @@ def create
4547 def topic_params
4648 params . require ( :topic ) . permit ( :title , :category_id , messages_attributes : [ :body ] )
4749 end
50+
51+ def verify_user
52+ redirect_to topics_path unless current_user
53+ end
4854end
Original file line number Diff line number Diff line change 11import { Link } from "@inertiajs/react" ;
22import TopicsTable from "../../components/TopicsTable"
33import AppLayout from "../../layouts/AppLayout"
4- import { Category } from "../../types"
4+ import { Category , User } from "../../types"
55
6- function CategoriesShow ( { category } : { category : Category } ) {
6+ function CategoriesShow ( { category, current_user : currentUser } : { category : Category , current_user : User } ) {
77 const { topics } = category ;
88
99 return (
1010 < AppLayout >
1111 < div className = "flex items-center justify-between mb-6" >
1212 < h1 className = "text-2xl font-bold text-gray-900" > Category: { category . name } </ h1 >
13- < Link
13+ { currentUser && (
14+ < Link
1415 href = { '/topics/new' }
1516 data = { { topic : { category_id : category . id } } }
1617 className = "bg-sky-600 hover:bg-sky-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors shadow inline-block text-center"
1718 >
18- New Topic
19- </ Link >
19+ New Topic
20+ </ Link >
21+ ) }
2022 </ div >
2123
2224 < div className = "max-w-7xl mx-auto" >
Original file line number Diff line number Diff line change 11import { Head , Link } from '@inertiajs/react'
22import AppLayout from '../../layouts/AppLayout'
3- import { Topic } from '../../types'
3+ import { Topic , User } from '../../types'
44import TopicsTable from '../../components/TopicsTable'
55
6- function MyTopicsIndex ( { topics } : { topics : Topic [ ] } ) {
6+ function MyTopicsIndex ( { topics, current_user : currentUser } : { topics : Topic [ ] , current_user : User } ) {
77 return (
88 < AppLayout >
99 < Head title = "My Topics - Pups & Pourovers" />
1010
1111 < div className = "flex items-center justify-between mb-6" >
1212 < h1 className = "text-2xl font-bold text-gray-900" > My Topics</ h1 >
13- < Link
13+ { currentUser && (
14+ < Link
1415 href = "/topics/new"
1516 className = "bg-sky-600 hover:bg-sky-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors shadow inline-block text-center"
1617 >
17- New Topic
18- </ Link >
18+ New Topic
19+ </ Link >
20+ ) }
1921 </ div >
2022
2123 < div className = "max-w-7xl mx-auto" >
Original file line number Diff line number Diff line change 11import { Head , Link } from '@inertiajs/react'
22import AppLayout from '../../layouts/AppLayout'
3- import { Topic } from '../../types'
3+ import { Topic , User } from '../../types'
44import TopicsTable from '../../components/TopicsTable'
55
6- function TopicsIndex ( { topics } : { topics : Topic [ ] } ) {
6+ function TopicsIndex ( { topics, current_user : currentUser } : { topics : Topic [ ] , current_user : User } ) {
77 return (
88 < AppLayout >
99 < Head title = "Topics - Pups & Pourovers" />
1010
1111 < div className = "max-w-7xl mx-auto" >
1212 < div className = "flex justify-end mb-6" >
13- < Link
13+ { currentUser && (
14+ < Link
1415 href = "/topics/new"
1516 className = "bg-sky-600 hover:bg-sky-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors shadow inline-block text-center"
1617 >
17- New Topic
18- </ Link >
18+ New Topic
19+ </ Link >
20+ ) }
1921 </ div >
2022 < div className = "bg-white shadow-sm rounded-lg overflow-hidden" >
2123 < TopicsTable topics = { topics } />
You can’t perform that action at this time.
0 commit comments