fix(project): save the last 6 projects in history, show only 5 on desktop
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:
parent
5892622676
commit
6641cbebc2
@ -63,6 +63,10 @@ const filteredProjects = computed(() => {
|
|||||||
|
|
||||||
@media screen and (min-width: $widescreen) {
|
@media screen and (min-width: $widescreen) {
|
||||||
--project-grid-columns: 5;
|
--project-grid-columns: 5;
|
||||||
|
|
||||||
|
.project-grid-item:nth-child(6) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ test('store project in history', () => {
|
|||||||
expect(saved).toBe('[{"id":1}]')
|
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
|
let saved: string | null = null
|
||||||
vi.spyOn(localStorage, 'getItem').mockImplementation(() => saved)
|
vi.spyOn(localStorage, 'getItem').mockImplementation(() => saved)
|
||||||
vi.spyOn(localStorage, 'setItem').mockImplementation((key: string, projects: string) => {
|
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: 4})
|
||||||
saveProjectToHistory({id: 5})
|
saveProjectToHistory({id: 5})
|
||||||
saveProjectToHistory({id: 6})
|
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', () => {
|
test('don\'t store the same project twice', () => {
|
||||||
|
@ -20,6 +20,8 @@ function saveHistory(history: ProjectHistory[]) {
|
|||||||
localStorage.setItem('projectHistory', JSON.stringify(history))
|
localStorage.setItem('projectHistory', JSON.stringify(history))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_SAVED_PROJECTS = 6
|
||||||
|
|
||||||
export function saveProjectToHistory(project: ProjectHistory) {
|
export function saveProjectToHistory(project: ProjectHistory) {
|
||||||
const history: ProjectHistory[] = getHistory()
|
const history: ProjectHistory[] = getHistory()
|
||||||
|
|
||||||
@ -33,7 +35,7 @@ export function saveProjectToHistory(project: ProjectHistory) {
|
|||||||
// Add the new project to the beginning of the project
|
// Add the new project to the beginning of the project
|
||||||
history.unshift(project)
|
history.unshift(project)
|
||||||
|
|
||||||
if (history.length > 5) {
|
if (history.length > MAX_SAVED_PROJECTS) {
|
||||||
history.pop()
|
history.pop()
|
||||||
}
|
}
|
||||||
saveHistory(history)
|
saveHistory(history)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user