Skip to content

Commit 67ae0c2

Browse files
committed
pkp/pkp-lib#11327 Code cleanup and refactoring
1 parent 234a0ef commit 67ae0c2

File tree

14 files changed

+430
-222
lines changed

14 files changed

+430
-222
lines changed

src/frontend/components/PkpAvatarInitials/pkpAvatarInitials.vue

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/frontend/components/PkpIcon/PkpIcon.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import MoreOptions from './icons/MoreOptions.vue';
55
import Error from './icons/Error.vue';
66
import Help from './icons/Help.vue';
77
import User from './icons/User.vue';
8+
import Orcid from '@/frontend/components/PkpIcon/icons/Orcid.vue';
9+
import OrcidUnauthenticated from '@/frontend/components/PkpIcon/icons/OrcidUnauthenticated.vue';
810
const svgIcons = {
911
Cancel,
1012
MoreOptions,
1113
Error,
1214
Help,
1315
User,
16+
Orcid,
17+
OrcidUnauthenticated,
1418
};
1519
1620
const props = defineProps({
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
3+
<g clip-path="url(#clip0_11_315)">
4+
<path
5+
d="M12 24C18.6274 24 24 18.6274 24 12C24 5.37258 18.6274 0 12 0C5.37258 0 0 5.37258 0 12C0 18.6274 5.37258 24 12 24Z"
6+
fill="#A6CE39"
7+
/>
8+
<path
9+
d="M8.10938 17.4375H6.65625V7.40625H8.10938V17.4375ZM10.2188 7.40625H14.1094C17.8125 7.40625 19.4531 10.0781 19.4531 12.4219C19.4531 15 17.4375 17.4375 14.1094 17.4375H10.1719L10.2188 7.40625ZM11.6719 16.1719H13.9688C17.25 16.1719 18 13.6875 18 12.4688C18 10.4531 16.7344 8.76562 13.9219 8.76562H11.7188L11.6719 16.1719ZM8.34375 5.34375C8.34375 5.85938 7.92188 6.28125 7.40625 6.28125C6.89062 6.28125 6.46875 5.85938 6.46875 5.34375C6.46875 5.09511 6.56752 4.85665 6.74334 4.68084C6.91915 4.50502 7.15761 4.40625 7.40625 4.40625C7.92188 4.40625 8.34375 4.82812 8.34375 5.34375Z"
10+
fill="white"
11+
/>
12+
</g>
13+
<defs>
14+
<clipPath id="clip0_11_315">
15+
<rect width="24" height="24" fill="white" />
16+
</clipPath>
17+
</defs>
18+
</svg>
19+
</template>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<svg
3+
viewBox="0 0 32 32"
4+
fill="none"
5+
xmlns="http://www.w3.org/2000/svg"
6+
class="mr-2 inline-block w-6 align-middle"
7+
>
8+
<path
9+
fill-rule="evenodd"
10+
clip-rule="evenodd"
11+
d="M29.474 16c0 7.442-6.032 13.474-13.474 13.474S2.526 23.442 2.526 16 8.558 2.526 16 2.526 29.474 8.558 29.474 16Z"
12+
fill="#fff"
13+
/>
14+
<path
15+
fill-rule="evenodd"
16+
clip-rule="evenodd"
17+
d="M32 16c0 8.837-7.163 16-16 16S0 24.837 0 16 7.163 0 16 0s16 7.163 16 16ZM16 29.474c7.442 0 13.474-6.032 13.474-13.474S23.442 2.526 16 2.526 2.526 8.558 2.526 16 8.558 29.474 16 29.474Z"
18+
fill="#7FAA26"
19+
/>
20+
<path
21+
fill-rule="evenodd"
22+
clip-rule="evenodd"
23+
d="M18.22 10.973h-4.547v11.6h4.569c3.8 0 6.133-2.82 6.133-5.8 0-1.365-.469-2.815-1.478-3.925-1.013-1.115-2.557-1.875-4.676-1.875Zm-.177 9.732h-2.347v-7.864h2.264c1.521 0 2.603.46 3.304 1.167.703.709 1.046 1.688 1.046 2.765 0 .654-.2 1.641-.83 2.46-.621.808-1.677 1.473-3.437 1.473Zm-.083-8.073c3.13 0 4.558 1.898 4.558 4.141 0-2.243-1.429-4.141-4.558-4.141h-2.472 2.472Zm6.205 4.017.001.124c0 2.869-2.242 5.591-5.924 5.591h-4.36V11.182v11.182h4.36c3.682 0 5.924-2.722 5.924-5.591l-.001-.124ZM9.5 11.005v11.588h2.024V11.005H9.5Zm1.815.208v11.172-11.172H9.71h1.606ZM10.512 10.15c.7 0 1.262-.575 1.262-1.263 0-.687-.561-1.262-1.262-1.262-.7 0-1.262.563-1.262 1.262 0 .688.561 1.262 1.262 1.262Zm.614-.408a1.044 1.044 0 0 0 0 0Z"
24+
fill="#7FAA26"
25+
/>
26+
</svg>
27+
</template>

src/frontend/components/PkpModal/PkpDialog.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ import {
6767
DialogTitle,
6868
} from 'reka-ui';
6969
import PkpIcon from '@/frontend/components/PkpIcon/PkpIcon.vue';
70+
import {usePkpLocalize} from '@/frontend/composables/usePkpLocalize';
7071
71-
import {useLocalize} from '@/composables/useLocalize';
72-
const {t} = useLocalize();
72+
const {t} = usePkpLocalize();
7373
7474
const props = defineProps({
7575
/** Used only internally, don't pass this prop via openDialog */

src/frontend/components/PkpModal/PkpModalBody.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<div class="pkpModalBody__closeWrapper">
4242
<DialogClose
4343
ref="closeModalButton"
44-
type="button"
44+
as="button"
4545
class="pkpModalBody__close"
4646
>
4747
<span class="pkpModalBody__srOnly">
@@ -78,8 +78,8 @@ import PkpIcon from '@/frontend/components/PkpIcon/PkpIcon.vue';
7878
import {focusFirstHeading} from '@/components/Modal/modalHelpers';
7979
8080
const containerId = useId();
81-
import {useLocalize} from '@/composables/useLocalize';
82-
const {t} = useLocalize();
81+
import {usePkpLocalize} from '@/frontend/composables/usePkpLocalize';
82+
const {t} = usePkpLocalize();
8383
const closeModal = inject('closeModal');
8484
const closeModalButton = inject('closeModalButton');
8585
/* Initial focus */
@@ -230,6 +230,7 @@ function handleAutoFocus(event) {
230230
position: relative;
231231
outline: none;
232232
background-color: var(--pkp-background-color-secondary);
233+
cursor: pointer;
233234
}
234235
235236
.pkpModalBody__close:hover {

src/frontend/components/PkpTextarea/PkpTextarea.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<div class="pkpTextarea">
3-
<Label class="pkpTextarea__label" :for="textareaId">
3+
<Label
4+
class="pkpTextarea__label"
5+
:class="{'-screenReader': isLabelSrOnly}"
6+
:for="textareaId"
7+
>
48
{{ props.label }}
59
</Label>
610
<textarea
@@ -35,6 +39,11 @@ const props = defineProps({
3539
type: Boolean,
3640
default: false,
3741
},
42+
// Whether the label should be visually hidden but still accessible to screen readers
43+
isLabelSrOnly: {
44+
type: Boolean,
45+
default: false,
46+
},
3847
});
3948
4049
defineEmits(['update:modelValue']);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<div>
3+
<a
4+
id="scrollToComments"
5+
style="cursor: pointer"
6+
@click.prevent="scrollToComments"
7+
>
8+
{{ t('userComment.allComments', {commentCount: allCommentsCount}) }}
9+
</a>
10+
<div>
11+
<a
12+
v-if="!currentUser"
13+
class="pkpScrollToComments__login"
14+
style="margin-top: 2rem"
15+
:href="loginUrl"
16+
>
17+
{{ t('userComment.login') }}
18+
</a>
19+
</div>
20+
</div>
21+
</template>
22+
23+
<script setup>
24+
import {usePkpLocalize} from '@/frontend/composables/usePkpLocalize';
25+
const {t} = usePkpLocalize();
26+
27+
const currentUser = pkp.currentUser;
28+
defineProps({
29+
/** The total number of comments across all publications */
30+
allCommentsCount: {
31+
type: Number,
32+
required: true,
33+
},
34+
/** The URL to the login page */
35+
loginUrl: {
36+
type: String,
37+
required: true,
38+
},
39+
});
40+
41+
const scrollToComments = () => {
42+
// Element with ID 'pkpUserCommentsContainer' is defined in the pkpUserComment component.
43+
const commentsContainer = document.getElementById('pkpUserCommentsContainer');
44+
if (commentsContainer) {
45+
commentsContainer.scrollIntoView({behavior: 'smooth'});
46+
}
47+
};
48+
</script>
49+
50+
<style>
51+
.pkpScrollToComments__login {
52+
display: inline-flex;
53+
align-items: center;
54+
justify-content: center;
55+
padding: var(--pkp-spacing-2) var(--pkp-spacing-4);
56+
font: var(--pkp-font-base-bold);
57+
border-radius: var(--pkp-radius);
58+
cursor: pointer;
59+
border: 1px solid var(--pkp-color-transparent);
60+
gap: var(--pkp-spacing-2);
61+
background-color: var(--pkp-color-primary);
62+
color: var(--pkp-text-color-on-dark);
63+
text-decoration: none;
64+
}
65+
66+
.pkpScrollToComments__login:hover {
67+
background-color: var(--pkp-color-hover);
68+
color: var(--pkp-text-color-on-dark);
69+
}
70+
</style>

src/frontend/components/PkpUserComment/PkpUserComment.vue

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
>
1010
<PkpButton
1111
v-if="!currentUser && id === latestPublicationId"
12-
class="userComments__loginButton"
12+
class="pkpUserComments__loginButton"
1313
@click="login"
1414
>
1515
{{ t('userComment.login') }}
@@ -19,7 +19,7 @@
1919
:publication-id="id"
2020
:items-per-page="itemsPerPage"
2121
:is-latest-publication="id === latestPublicationId"
22-
:total-publication-comments="commentsCountPerPublication[id] || 0"
22+
:total-publication-comments="commentsCountPerPublication[id]"
2323
/>
2424
</PkpAccordion>
2525
</template>
@@ -30,53 +30,65 @@
3030
import PkpUserCommentsList from '@/frontend/components/PkpUserComment/PkpUserCommentsList.vue';
3131
import PkpAccordion from '@/frontend/components/PkpAccordion/PkpAccordion.vue';
3232
import PkpButton from '@/frontend/components/PkpButton/PkpButton.vue';
33-
import {useLocalize} from '@/composables/useLocalize';
33+
import {usePkpLocalize} from '@/frontend/composables/usePkpLocalize';
3434
35-
const {t} = useLocalize();
35+
const {t} = usePkpLocalize();
3636
const props = defineProps({
37+
/** The ID of the latest publication associated with the published item(article, book, etc.)*/
3738
latestPublicationId: {
3839
type: Number,
3940
required: true,
4041
},
42+
/** An array of published publication IDs associated with the published item(article, book, etc.) */
4143
publicationIds: {
4244
type: Array,
4345
required: false,
4446
default: () => [],
4547
},
46-
userCommentForm: {
47-
type: Object,
48-
required: true,
49-
},
50-
userCommentReportForm: {
51-
type: Object,
48+
/** Number of comments get when fetching comments */
49+
itemsPerPage: {
50+
type: Number,
5251
required: true,
5352
},
54-
itemsPerPage: {},
53+
/**
54+
* URL to redirect the user to login page
55+
*/
5556
loginUrl: {
5657
type: String,
5758
required: true,
5859
},
60+
/**
61+
* An object where keys are publication IDs and values are the number of comments for that publication
62+
*/
5963
commentsCountPerPublication: {
6064
type: Object,
6165
required: true,
6266
},
6367
});
6468
const currentUser = pkp.currentUser;
6569
70+
/**
71+
* Returns the title for the accordion based on the publication ID and the number of comments.
72+
* @param {number} id - The publication ID.
73+
* @returns {string} The title for the accordion.
74+
*/
6675
function getVersionTitle(id) {
6776
return t('userComment.versionWithCount', {
6877
version: id,
69-
versionCommentsCount: props.commentsCountPerPublication[id],
78+
versionCommentsCount: props.commentsCountPerPublication[id] || 0,
7079
});
7180
}
7281
82+
/**
83+
* Redirects the user to the login page.
84+
*/
7385
function login() {
7486
window.location = props.loginUrl;
7587
}
7688
</script>
7789

7890
<style>
79-
.userComments__loginButton {
91+
.pkpUserComments__loginButton {
8092
margin-top: 0.5rem;
8193
margin-bottom: 1rem;
8294
}

0 commit comments

Comments
 (0)