Skip to content

Commit

Permalink
Merge pull request activist-org#861 from nicomaz/update-buttons-based…
Browse files Browse the repository at this point in the history
…-on-screen-size

Update buttons based on screen size
  • Loading branch information
andrewtavis authored May 1, 2024
2 parents 74c6f58 + 31e4e2b commit f68f3d1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 47 deletions.
36 changes: 11 additions & 25 deletions frontend/pages/events/[id]/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@
:event="event"
/>
<MediaMap
v-if="
(event.offlineLocation && !textExpanded) ||
(event.offlineLocation && isUnderLargeBP)
"
v-if="event.offlineLocation && !textExpanded"
class="h-[17.5rem] w-full"
:markerColors="event.type === 'learn' ? ['#2176AE'] : ['#BA3D3B']"
:eventNames="[event.name]"
Expand Down Expand Up @@ -102,41 +99,30 @@ const expandReduceText = () => {
textExpanded.value = !textExpanded.value;
};
const currentWidth = ref(window.innerWidth);
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
const windowWidth = ref(window.innerWidth);
const shareButtonLabel = ref("");
function updateShareBtnLabel() {
if (currentWidth.value < Breakpoint.SMALL) {
windowWidth.value = window.innerWidth;
if (windowWidth.value < Breakpoint.SMALL) {
shareButtonLabel.value = "components.btn-action.share";
} else {
shareButtonLabel.value = "components._global.share-group";
}
}
onMounted(() => {
window.addEventListener("resize", handleResize);
window.addEventListener("resize", updateShareBtnLabel);
updateShareBtnLabel();
});
const isUnderLargeBP = ref(false);
const checkUnderLargeBP = () => {
isUnderLargeBP.value = window.innerWidth < 1024;
};
const handleResize = () => {
checkUnderLargeBP();
if (resizeTimeout) {
clearTimeout(resizeTimeout);
}
resizeTimeout = setTimeout(updateShareBtnLabel, 100);
};
onUpdated(() => {
updateShareBtnLabel();
});
onMounted(() => {
window.addEventListener("resize", handleResize);
handleResize(); // initial check
onUnmounted(() => {
window.removeEventListener("resize", updateShareBtnLabel);
});
const modalIsOpen = ref(false);
Expand Down
23 changes: 12 additions & 11 deletions frontend/pages/organizations/[id]/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,31 @@ const expandReduceText = () => {
textExpanded.value = !textExpanded.value;
};
const currentWidth = ref(window.innerWidth);
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
const windowWidth = ref(window.innerWidth);
const shareButtonLabel = ref("");
function updateShareBtnLabel() {
if (currentWidth.value < Breakpoint.SMALL) {
windowWidth.value = window.innerWidth;
if (windowWidth.value < Breakpoint.SMALL) {
shareButtonLabel.value = "components.btn-action.share";
} else {
shareButtonLabel.value = "components._global.share-organization";
}
}
const handleResize = () => {
if (resizeTimeout) {
clearTimeout(resizeTimeout);
}
resizeTimeout = setTimeout(updateShareBtnLabel, 100);
};
onMounted(() => {
window.addEventListener("resize", handleResize);
window.addEventListener("resize", updateShareBtnLabel);
updateShareBtnLabel();
});
onUpdated(() => {
updateShareBtnLabel();
});
onUnmounted(() => {
window.removeEventListener("resize", updateShareBtnLabel);
});
// TODO: for testing purpose, should be removed.
// const upVotes = ref(123);
// const downVotes = ref(123);
Expand Down
23 changes: 12 additions & 11 deletions frontend/pages/organizations/[id]/groups/[id]/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,31 @@ const expandReduceText = () => {
textExpanded.value = !textExpanded.value;
};
const currentWidth = ref(window.innerWidth);
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
const windowWidth = ref(window.innerWidth);
const shareButtonLabel = ref("");
function updateShareBtnLabel() {
if (currentWidth.value < Breakpoint.SMALL) {
windowWidth.value = window.innerWidth;
if (windowWidth.value < Breakpoint.SMALL) {
shareButtonLabel.value = "components.btn-action.share";
} else {
shareButtonLabel.value = "components._global.share-group";
}
}
const handleResize = () => {
if (resizeTimeout) {
clearTimeout(resizeTimeout);
}
resizeTimeout = setTimeout(updateShareBtnLabel, 100);
};
onMounted(() => {
window.addEventListener("resize", handleResize);
window.addEventListener("resize", updateShareBtnLabel);
updateShareBtnLabel();
});
onUpdated(() => {
updateShareBtnLabel();
});
onUnmounted(() => {
window.removeEventListener("resize", updateShareBtnLabel);
});
const modalIsOpen = ref(false);
function openModal() {
Expand Down

0 comments on commit f68f3d1

Please sign in to comment.