Skip to content

Connected deadline text to be dynamic google doc #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions assets/javascript/deadlineText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//DO NOT CHANGE DELIMITERs
const DELIMITER_BEG =
'DO NOT DELETE THIS TEXT AND INCLUDE A SPACE AFTER COLON: ';
// 2 Ending because for some reason fetching from google doc has to
const DELIMITER_END1 = '</span>';
const DELIMITER_END2 = '"';
Comment on lines +5 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make things clear, the ending index will be at either </span> or at " on the Google Doc, whichever comes first?
Besides that, all is good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because there is a weird thing that happens (i don't know why) but fetching the google doc has two potential results it can pull where one has after the text it ends with</span> or the other with ". That is why I added a couple of safety checks to make sure it doesn't mess up. I tried using google's own API to fetch the data making it more consistent and clean but it took 2 seconds to fetch so I opted to use this method instead


const deadlineElements = document.querySelectorAll('[data-deadline]');

fetch(
//public view only url
//trickfirerobotics@gmail.com
'https://docs.google.com/document/d/1tRysVWzUv-sKNg6lWe7n-CvKLZU0HNW3SZiIs19d09Q/edit?usp=sharing'
)
.then(res => {
//check to make sure API works
if (!res.ok) {
throw new error('DEADLINE TEXT API NOT WORKING');
}
return res.text();
})
.then(text => {
let indexBeg = text.indexOf(DELIMITER_BEG) + DELIMITER_BEG.length;
let indexEnd = Math.min(
text.indexOf(DELIMITER_END1, indexBeg),
text.indexOf(DELIMITER_END2, indexBeg)
);
//Catches if the DELIMITER isn't found
if (indexBeg == -1 + DELIMITER_BEG.length || indexEnd == -1) {
throw new Error('DELIMITER WAS NOT FOUND');
}

const deadlineText = `Deadline: ${text.substring(indexBeg, indexEnd)}`;
//safety check to make sure it didn't go over
if (deadlineText.length > 100) {
throw new Error('TEXT WAS OVER 100 CHARS');
}
deadlineElements.forEach(ele => {
ele.innerText = deadlineText;
});
})
.catch(error => {
console.error(error);
});
2 changes: 0 additions & 2 deletions assets/moduleHtml/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@
</p>
</div>
<script>
console.log(document.getElementById('copyright-text').innerText);
let copyrightTextElement =
document.getElementById('copyright-text');
let currentYear = new Date().getFullYear();
console.log(currentYear);
copyrightTextElement.innerText =
copyrightTextElement.innerText.replace('2022', currentYear);
</script>
Expand Down
20 changes: 15 additions & 5 deletions join_us.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
$('#footer').load('./assets/moduleHtml/footer.html');
});
</script>
<!-- Updates Deadline text dynamicaly -->
<script
type="module"
async
src="./assets/javascript/deadlineText.js"
></script>
</head>

<body>
Expand Down Expand Up @@ -102,9 +108,10 @@ <h1>Why Join?</h1>
>
TrickFire Robotics Application Link
</a>
<br/>
<b>Deadline: Between June 20th and July 15th</b>

<br />
<b data-deadline>
Deadline: Please check the form above</b
>
</p>
</div>
</div>
Expand Down Expand Up @@ -147,15 +154,18 @@ <h1>Why Join?</h1>
>
TrickFire Robotics Application Link
</a>
<br/>
<b>Deadline: Between June 20th and July 15th</b>
<br />
<b data-deadline>
Deadline: Please check the form above</b
>
</p>
</div>
</div>
<div class="space-after-rows"></div>
</section>

<footer id="footer"></footer>

<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
Expand Down