Fix workflow YAML and improve CV section editing
This commit is contained in:
@@ -211,6 +211,7 @@ export const translations = {
|
||||
profileCvSectionDraft: "Section draft",
|
||||
profileCvSectionDraftPlaceholder: "Your rewritten section will appear here.",
|
||||
profileCvSectionAppend: "Append to CV text",
|
||||
profileCvSectionReplace: "Replace matching section",
|
||||
profileSaveChanges: "Save changes",
|
||||
profileUpdated: "Profile updated.",
|
||||
profileUpdateFailed: "Failed to update profile.",
|
||||
@@ -984,6 +985,7 @@ export const translations = {
|
||||
profileCvSectionDraft: "Seksjonsutkast",
|
||||
profileCvSectionDraftPlaceholder: "Den omskrevne seksjonen vises her.",
|
||||
profileCvSectionAppend: "Legg til i CV-teksten",
|
||||
profileCvSectionReplace: "Erstatt matchende seksjon",
|
||||
profileSaveChanges: "Lagre endringer",
|
||||
profileUpdated: "Profil oppdatert.",
|
||||
profileUpdateFailed: "Kunne ikke oppdatere profil.",
|
||||
|
||||
@@ -46,6 +46,28 @@ function initialsFrom(values: Array<string | undefined>) {
|
||||
return (joined[0][0] + joined[1][0]).toUpperCase();
|
||||
}
|
||||
|
||||
function replaceCvSection(source: string, sectionName: string, sectionDraft: string) {
|
||||
const trimmedSource = source.trim();
|
||||
const trimmedDraft = sectionDraft.trim();
|
||||
if (!trimmedDraft) return source;
|
||||
if (!trimmedSource) return `${sectionName}\n${trimmedDraft}`;
|
||||
|
||||
const headingPattern = /^([A-Z][A-Za-z &/]+):?\s*$/gm;
|
||||
const matches = Array.from(trimmedSource.matchAll(headingPattern));
|
||||
const normalizedTarget = sectionName.trim().toLowerCase();
|
||||
const targetIndex = matches.findIndex((match) => match[1].trim().toLowerCase() === normalizedTarget);
|
||||
|
||||
if (targetIndex === -1) {
|
||||
return `${trimmedSource}\n\n${sectionName}\n${trimmedDraft}`.trim();
|
||||
}
|
||||
|
||||
const start = matches[targetIndex].index ?? 0;
|
||||
const end = targetIndex + 1 < matches.length ? (matches[targetIndex + 1].index ?? trimmedSource.length) : trimmedSource.length;
|
||||
const before = trimmedSource.slice(0, start).trimEnd();
|
||||
const after = trimmedSource.slice(end).trimStart();
|
||||
return [before, `${sectionName}\n${trimmedDraft}`, after].filter(Boolean).join("\n\n").trim();
|
||||
}
|
||||
|
||||
export default function ProfilePage() {
|
||||
const { toast } = useToast();
|
||||
const { t } = useI18n();
|
||||
@@ -376,6 +398,7 @@ export default function ProfilePage() {
|
||||
<Box sx={{ mt: 1, display: "flex", justifyContent: "flex-end", gap: 1, flexWrap: "wrap" }}>
|
||||
<Button variant="text" disabled={!cvSectionDraft.trim()} onClick={() => navigator.clipboard.writeText(cvSectionDraft)}>{t("profileCopyCvText")}</Button>
|
||||
<Button variant="outlined" disabled={!cvSectionDraft.trim()} onClick={() => setProfileCvText((prev) => `${prev.trim()}\n\n${cvSection}\n${cvSectionDraft.trim()}`.trim())}>{t("profileCvSectionAppend")}</Button>
|
||||
<Button variant="contained" disabled={!cvSectionDraft.trim()} onClick={() => setProfileCvText((prev) => replaceCvSection(prev, cvSection, cvSectionDraft))}>{t("profileCvSectionReplace")}</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box sx={{ mt: 1, display: "flex", justifyContent: "space-between", gap: 1, flexWrap: "wrap" }}>
|
||||
|
||||
Reference in New Issue
Block a user