Skip to content

Commit

Permalink
delete support + query params
Browse files Browse the repository at this point in the history
  • Loading branch information
kondaurovDev committed Feb 19, 2025
1 parent 55efe7d commit badc55f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/cv-maker/core/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ function ResumeHead(resume: ResumeObject) {
function CompanyProject(project: ProjectDetails, isLast: boolean) {
let clazz = "project no-break pb-3";
if (!isLast) clazz += " border-b-1 border-gray-300 border-dashed mb-2";
console.log({ title: project.title, isLast })
return (
<div className={clazz}>
<div className="flex">
Expand Down
13 changes: 12 additions & 1 deletion src/cv-maker/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ export function debounce<T extends (...args: unknown[]) => void>(
func(...args);
}, wait);
};
}
}

export function getUrlParam(name: string) {
const params = new URLSearchParams(location.search);
return params.get(name);
}

export function setUrlParam(name: string, value: string) {
const url = new URL(location.href);
url.searchParams.set(name, value);
window.history.replaceState(null, '', url);
}
1 change: 1 addition & 0 deletions src/cv-maker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<button
class="btn bg-[#DC382D] hover:bg-[#B93224]"
x-on:click="$dispatch('delete')"
x-show="availableResumes.length > 1"
>Delete</button>
</div>

Expand Down
20 changes: 18 additions & 2 deletions src/cv-maker/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Alpine from "alpinejs";
import { debounce, getResumeObject, parseJSON, resumeObjectToHTML } from "./core/utils";
import { debounce, getResumeObject, getUrlParam, parseJSON, resumeObjectToHTML, setUrlParam } from "./core/utils";
import type resumeSchema from "./static/resume-schema.json"
import { makeJsonEditor } from "#/common/editor/make";
import { hasMajorError } from "#/common/editor/text-model";
Expand Down Expand Up @@ -56,7 +56,7 @@ const state: {
mode: "view",
editorHasError: false,
availableResumes: [],
currentResume: "example"
currentResume: getUrlParam("resume") ?? "example"
});

Alpine.data("state", () => state);
Expand All @@ -80,6 +80,12 @@ async function loadStoredResume() {
name: key
});
};

const lastResumeId = state.availableResumes.at(-1)?.id;

if (lastResumeId) {
state.currentResume = lastResumeId;
}

}

Expand All @@ -96,6 +102,7 @@ function selectResume() {
};
state.resumeObject = resume;
state.resumeHtml = resumeObjectToHTML(resume);
setUrlParam("resume", state.currentResume);
}

async function setup() {
Expand Down Expand Up @@ -181,6 +188,15 @@ async function setup() {
if (!name) return;
localStorage.setItem(name, JSON.stringify(state.resumeObject));
state.availableResumes.push({ id: name, name });
state.currentResume = name;
selectResume();
prepareEditor();
});

window.addEventListener('delete', () => {
localStorage.removeItem(state.currentResume);
loadStoredResume();
selectResume();
});

window.addEventListener('resize', () => {
Expand Down

0 comments on commit badc55f

Please sign in to comment.