Skip to content

Commit

Permalink
Fix bug where ids were missing in older cv.json
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiabdm committed Mar 5, 2024
1 parent b010a15 commit fec87e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions data/example-cv-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const cvSettingTemplate: Cv = {
website: 'www.MsKnope.com',
education: [
{
id: '1',
title: 'A Environmental and Public Affairs',
location: 'Indiana University, Bloomington, Indiana',
from: new Date(1993, 9, 1),
Expand All @@ -28,6 +29,7 @@ export const cvSettingTemplate: Cv = {
],
work: [
{
id: '1',
title: 'Deputy Director Parks Department',
location: 'City of Pawnee, Indiana',
from: new Date(2009, 1, 1),
Expand All @@ -37,6 +39,7 @@ export const cvSettingTemplate: Cv = {
'<ul><li><p>In placerat nisi pellentesque felis blandit, vel varius justo eleifend.</p></li><li><p>Etiam porttitor tortor vel lobortis ultricies.</p></li><li><p>Nam non libero accumsan, sagittis nibh vitae, auctor ligula.</p></li><li><p>Sed hendrerit dui a ante porttitor, vitae tristique ipsum laoreet.</p></li><li><p>Suspendisse interdum mauris a lectus dignissim, vitae aliquet ante tempor.</p></li></ul>',
},
{
id: '2',
title: 'City Councilor',
location: 'City of Pawnee, Indiana',
from: new Date(2012, 1, 1),
Expand All @@ -48,6 +51,7 @@ export const cvSettingTemplate: Cv = {
],
projects: [
{
id: '3',
title: 'Lot 48',
location: 'City of Pawnee, Indiana',
from: new Date(2009, 1, 1),
Expand Down
26 changes: 20 additions & 6 deletions data/useCvState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {
cvSettingTemplate,
cvSettingsEmptyTemplate,
} from './example-cv-settings'
import type {
Cv,
CvEvent,
DefaultSkill,
LanguagesSkill,
SectionName,
import {
type Cv,
type CvEvent,
type DefaultSkill,
type LanguagesSkill,
type SectionName,
SectionNameList,
} from '~/types/cvfy'

const state = reactive({
Expand All @@ -32,6 +33,7 @@ export function useCvState() {
else {
const cvSettingsObj = JSON.parse(cvSettings)
state.formSettings = { ...cvSettingsEmptyTemplate, ...cvSettingsObj }
patchId(state.formSettings)
}
localStorage.setItem(locale, JSON.stringify(state.formSettings))
state.isLoading = false
Expand Down Expand Up @@ -104,6 +106,7 @@ export function useCvState() {
...cvSettingsEmptyTemplate,
...data.formSettings,
}
patchId(state.formSettings)
}
fr.readAsText(e.target.files[0])
}
Expand Down Expand Up @@ -135,6 +138,17 @@ export function useCvState() {
state.formSettings[propName] = e.status
}

function patchId(formSettings: Cv) {
// Make sure that older cvs have id in each entry of a section
for (const key in SectionNameList) {
const section = key as SectionName
for (const e of formSettings[section]) {
if (!e.id)
e.id = crypto.randomUUID()
}
}
}

return {
...toRefs(state),
setUpCvSettings,
Expand Down

0 comments on commit fec87e2

Please sign in to comment.