Implement post categories

This commit is contained in:
2025-10-02 15:45:31 +02:00
parent 278f51ce2e
commit ead239c061
9 changed files with 145 additions and 24 deletions

View File

@@ -4,9 +4,8 @@ Class {
#instVars : [ #instVars : [
'main' 'main'
], ],
#category : 'TinyBlog-Components-Components', #category : 'TinyBlog-Components',
#package : 'TinyBlog-Components', #package : 'TinyBlog-Components'
#tag : 'Components'
} }
{ #category : 'testing' } { #category : 'testing' }

View File

@@ -0,0 +1,61 @@
Class {
#name : 'TBCategoriesComponent',
#superclass : 'TBScreenComponent',
#instVars : [
'categories',
'postsList'
],
#category : 'TinyBlog-Components',
#package : 'TinyBlog-Components'
}
{ #category : 'instance creation' }
TBCategoriesComponent class >> categories: categories postsList: aTBScreen [
^ self new categories: categories; postsList: aTBScreen
]
{ #category : 'accessing' }
TBCategoriesComponent >> categories [
^ categories
]
{ #category : 'accessing' }
TBCategoriesComponent >> categories: anObject [
categories := anObject
]
{ #category : 'accessing' }
TBCategoriesComponent >> postsList [
^ postsList
]
{ #category : 'accessing' }
TBCategoriesComponent >> postsList: anObject [
postsList := anObject
]
{ #category : 'actions' }
TBCategoriesComponent >> renderCategoryLinkOn: html with: aCategory [
html listGroupLinkedItem
class: 'active' if: aCategory = self postsList currentCategory;
callback: [ self selectCategory: aCategory ];
with: aCategory
]
{ #category : 'actions' }
TBCategoriesComponent >> renderContentOn: html [
html listGroup: [
html listGroupItem
with: [ html strong: 'Categories' ].
categories do: [ :cat |
self renderCategoryLinkOn: html with: cat ] ]
]
{ #category : 'actions' }
TBCategoriesComponent >> selectCategory: aCategory [
postsList currentCategory: aCategory
]

View File

@@ -1,9 +1,8 @@
Class { Class {
#name : 'TBHeaderComponent', #name : 'TBHeaderComponent',
#superclass : 'SBSComponent', #superclass : 'SBSComponent',
#category : 'TinyBlog-Components-Components', #category : 'TinyBlog-Components',
#package : 'TinyBlog-Components', #package : 'TinyBlog-Components'
#tag : 'Components'
} }
{ #category : 'rendering' } { #category : 'rendering' }

View File

@@ -4,9 +4,8 @@ Class {
#instVars : [ #instVars : [
'post' 'post'
], ],
#category : 'TinyBlog-Components-Components', #category : 'TinyBlog-Components',
#package : 'TinyBlog-Components', #package : 'TinyBlog-Components'
#tag : 'Components'
} }
{ #category : 'initialization' } { #category : 'initialization' }

View File

@@ -2,24 +2,58 @@ Class {
#name : 'TBPostsListComponent', #name : 'TBPostsListComponent',
#superclass : 'TBScreenComponent', #superclass : 'TBScreenComponent',
#instVars : [ #instVars : [
'postComponents' 'postComponents',
'currentCategory'
], ],
#category : 'TinyBlog-Components-Components', #category : 'TinyBlog-Components',
#package : 'TinyBlog-Components', #package : 'TinyBlog-Components'
#tag : 'Components'
} }
{ #category : 'rendering' }
TBPostsListComponent >> basicRenderCategoriesOn: html [
html render: self categoriesComponent
]
{ #category : 'rendering' }
TBPostsListComponent >> basicRenderPostsOn: html [
self readSelectedPosts do: [ :p | html render: (self postComponentFor: p) ]
]
{ #category : 'rendering' }
TBPostsListComponent >> categoriesComponent [
^ TBCategoriesComponent
categories: self blog allCategories
postsList: self
]
{ #category : 'initialization' } { #category : 'initialization' }
TBPostsListComponent >> children [ TBPostsListComponent >> children [
^ self postComponents, super children ^ self postComponents, super children
] ]
{ #category : 'accessing' }
TBPostsListComponent >> currentCategory [
^ currentCategory
]
{ #category : 'accessing' }
TBPostsListComponent >> currentCategory: anObject [
currentCategory := anObject
]
{ #category : 'initialization' } { #category : 'initialization' }
TBPostsListComponent >> initialize [ TBPostsListComponent >> initialize [
super initialize. super initialize.
postComponents := OrderedCollection new postComponents := OrderedCollection new
] ]
{ #category : 'rendering' }
TBPostsListComponent >> postComponentFor: aPost [
^ TBPostComponent new post: aPost
]
{ #category : 'initialization' } { #category : 'initialization' }
TBPostsListComponent >> postComponents [ TBPostsListComponent >> postComponents [
postComponents := self readSelectedPosts postComponents := self readSelectedPosts
@@ -29,13 +63,44 @@ TBPostsListComponent >> postComponents [
{ #category : 'initialization' } { #category : 'initialization' }
TBPostsListComponent >> readSelectedPosts [ TBPostsListComponent >> readSelectedPosts [
^ self blog allVisibleBlogPosts ^ self currentCategory
ifNil: [ self blog allVisibleBlogPosts ]
ifNotNil: [ self blog allVisibleBlogPostsFromCategory: self currentCategory ]
]
{ #category : 'rendering' }
TBPostsListComponent >> renderCategoryColumnOn: html [
html column
extraSmallSize: 12;
smallSize: 2;
mediumSize: 4;
with: [ self basicRenderCategoriesOn: html ]
] ]
{ #category : 'rendering' } { #category : 'rendering' }
TBPostsListComponent >> renderContentOn: html [ TBPostsListComponent >> renderContentOn: html [
super renderContentOn: html. super renderContentOn: html.
html container: [ html container: [
self postComponents do: [ :p | html row
html render: p ] ] with: [
html column
extraSmallSize: 12;
smallSize: 2;
mediumSize: 4;
with: [ html render: self categoriesComponent ].
html column
extraSmallSize: 12;
smallSize: 10;
mediumSize: 8;
with: [
self postComponents do: [ :p | html render: (self postComponentFor: p) ] ] ] ]
]
{ #category : 'rendering' }
TBPostsListComponent >> renderPostColumnOn: html [
html column
extraSmallSize: 12;
smallSize: 2;
mediumSize: 4;
with: [ self basicRenderPostsOn: html ]
] ]

View File

@@ -4,9 +4,8 @@ Class {
#instVars : [ #instVars : [
'header' 'header'
], ],
#category : 'TinyBlog-Components-Components', #category : 'TinyBlog-Components',
#package : 'TinyBlog-Components', #package : 'TinyBlog-Components'
#tag : 'Components'
} }
{ #category : 'acccessing' } { #category : 'acccessing' }

View File

@@ -8,8 +8,7 @@ Class {
'previousRepository' 'previousRepository'
], ],
#category : 'TinyBlog-Tests', #category : 'TinyBlog-Tests',
#package : 'TinyBlog', #package : 'TinyBlog-Tests'
#tag : 'Tests'
} }
{ #category : 'running' } { #category : 'running' }

View File

@@ -2,8 +2,7 @@ Class {
#name : 'TBPostTest', #name : 'TBPostTest',
#superclass : 'TestCase', #superclass : 'TestCase',
#category : 'TinyBlog-Tests', #category : 'TinyBlog-Tests',
#package : 'TinyBlog', #package : 'TinyBlog-Tests'
#tag : 'Tests'
} }
{ #category : 'tests' } { #category : 'tests' }

View File

@@ -0,0 +1 @@
Package { #name : 'TinyBlog-Tests' }