fix(project): save the last 6 projects in history, show only 5 on desktop
continuous-integration/drone/push Build is failing Details

The project grid on the home page with the recently visited projects now contains an even number of projects which makes for a much nicer grid (because it's now uniform).
This commit is contained in:
kolaente 2024-04-07 14:34:18 +02:00
parent 5892622676
commit 6641cbebc2
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 10 additions and 3 deletions

View File

@ -63,6 +63,10 @@ const filteredProjects = computed(() => {
@media screen and (min-width: $widescreen) {
--project-grid-columns: 5;
.project-grid-item:nth-child(6) {
display: none;
}
}
}

View File

@ -26,7 +26,7 @@ test('store project in history', () => {
expect(saved).toBe('[{"id":1}]')
})
test('store only the last 5 projects in history', () => {
test('store only the last 6 projects in history', () => {
let saved: string | null = null
vi.spyOn(localStorage, 'getItem').mockImplementation(() => saved)
vi.spyOn(localStorage, 'setItem').mockImplementation((key: string, projects: string) => {
@ -39,7 +39,8 @@ test('store only the last 5 projects in history', () => {
saveProjectToHistory({id: 4})
saveProjectToHistory({id: 5})
saveProjectToHistory({id: 6})
expect(saved).toBe('[{"id":6},{"id":5},{"id":4},{"id":3},{"id":2}]')
saveProjectToHistory({id: 7})
expect(saved).toBe('[{"id":7},{"id":6},{"id":5},{"id":4},{"id":3},{"id":2}]')
})
test('don\'t store the same project twice', () => {

View File

@ -20,6 +20,8 @@ function saveHistory(history: ProjectHistory[]) {
localStorage.setItem('projectHistory', JSON.stringify(history))
}
const MAX_SAVED_PROJECTS = 6
export function saveProjectToHistory(project: ProjectHistory) {
const history: ProjectHistory[] = getHistory()
@ -33,7 +35,7 @@ export function saveProjectToHistory(project: ProjectHistory) {
// Add the new project to the beginning of the project
history.unshift(project)
if (history.length > 5) {
if (history.length > MAX_SAVED_PROJECTS) {
history.pop()
}
saveHistory(history)