From b0c2893ea3e88cf8477102ccb1845407989c98d6 Mon Sep 17 00:00:00 2001 From: syke9p3 Date: Sun, 21 Jul 2024 11:22:06 +0800 Subject: [PATCH] date generation --- app.js | 62 +++++++++++++++++++++++++++++++------ index.html | 21 ++++++++++--- javascript/events.js | 74 ++++++++++++++++++++++++++++++++++++++++++++ javascript/modal.js | 0 javascript/output.js | 0 javascript/state.js | 50 ++++++++++++++++++++++++++++++ javascript/utils.js | 27 +++++++++++++++- 7 files changed, 219 insertions(+), 15 deletions(-) create mode 100644 javascript/events.js create mode 100644 javascript/modal.js create mode 100644 javascript/output.js create mode 100644 javascript/state.js diff --git a/app.js b/app.js index 4bed099..4ee3236 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ import { classify, modelStatus } from "./javascript/classifier.js" -import { countCharacters, isValidCharacterCount, typeWriter, updateLabelsContainer } from "./javascript/utils.js" +import { countCharacters, generateDate, getDate, getTime, isValidCharacterCount, typeWriter, updateLabelsContainer } from "./javascript/utils.js" export const globalState = { prevInput: '', @@ -15,9 +15,13 @@ const clearButton = document.getElementById("clear-btn"); const exampleSelector = document.getElementById("sample-hate-speech"); const wordCountDisplay = document.getElementById("word-count"); const labelsContainer = document.getElementById("labels-container"); +const outputContainer = document.getElementById("output-container"); const inputDisplayContainer = document.getElementById("input-display-container"); const inputDisplay = document.getElementById("input-display"); const inputDisplayText = document.getElementById("input-display-text"); +const inputDisplayDate = document.getElementById("input-display-date"); +const tweetTime = document.getElementById("tweet-time"); +const tweetDate = document.getElementById("tweet-date"); const outputDisplay = document.getElementById("output-display"); const loadingDisplay = document.getElementById("loading-display"); const modelStatusDisplay = document.getElementById("model-status"); @@ -153,18 +157,28 @@ const setInputFieldValue = (text) => { } const updateSubmitButtonState = () => { - const wordCount = globalState.wordCount; - const prevInput = globalState.prevInput; - console.group("updateSubmitButtonState: ") - console.log("wordcount: ", wordCount) - console.log("prevInput: ", prevInput) - console.groupEnd() + // console.group("updateSubmitButtonState: ") + // console.log("wordcount: ", wordCount) + // console.log("prevInput: ", prevInput) + // console.groupEnd() // Disable the submit button if input is invalid or data is being fetched - submitButton.disabled = !isValidCharacterCount(wordCount) || globalState.isLoading || globalState.prevInput === inputField.value; + submitButton.disabled = !isValidCharacterCount(globalState.wordCount) || globalState.isLoading || globalState.prevInput === inputField.value; }; +const displayDateToInputDisplay = () => { + const newDate = generateDate(); + const time = getTime(newDate); + const date = getDate(newDate); + + tweetTime.textContent = time; + tweetDate.textContent = date; + + inputDisplayDate.style.display = "flex"; + +} + /** * Takes a string and displays it to the input display in output UI. * @param {string | {label: string, score: number}[]} output an array of labels and scores sorted by descending scores @@ -175,6 +189,9 @@ const updateInputDisplay = (inputText) => { inputDisplayContainer.style.display = "grid" // inputDisplayText.textContent = inputText typeWriter(inputDisplayText, inputText); + displayDateToInputDisplay(); + + } /** @@ -230,7 +247,6 @@ const updateLoadingDisplay = (isLoading) => { labelsContainer.classList.remove("fade-out"); - } else { } } @@ -257,6 +273,8 @@ clearButton.onclick = (e) => { // TEST: should reset the exampleOptions to default // TEST: should reset word count + inputField.scrollIntoView({ behavior: "smooth" }); + inputField.value = ""; updateInput() exampleSelector.selectedIndex = 0; @@ -270,6 +288,8 @@ clearButton.onclick = (e) => { */ const handleSubmitInput = async (input) => { + outputContainer.scrollIntoView({ behavior: "smooth" }); + // TEST: should get output from the classifier if successful // TEST: should display output to the UI @@ -335,3 +355,27 @@ exampleSelector.oninput = () => { handleInputChange() debugGlobalState() } + + +/** TODO + * @TODO set title attribute to analyzeBtn on hover when same prevInput and input + * @TODO date and time to post + * @TODO save results to local storage + * @TODO retrieve from local storage and display to UI + * @TODO filter results + * @TODO pagination + * @TODO count and graph results + * @TODO export as csv + * @TODO dark mode + * @TODO guide below as an article + * @TODO description for the labels with icons/emoji (take from github readme) + */ + +/** FEATURES + * @FEAT input text + * @FEAT hate speech examples + * @FEAT word counter + * @FEAT clear input field + * @FEAT post like display + * @FEAT hate speech categories display + */ \ No newline at end of file diff --git a/index.html b/index.html index 0ac6542..14357e5 100644 --- a/index.html +++ b/index.html @@ -55,9 +55,15 @@

the system requires a minimum of 3 characters and accepts up to a maximum of 280 characters.

- + @@ -146,6 +152,11 @@

MLTHSC

Let's analyze Tagalog hate speech tweet according to Age, Gender, Physical, Race, Religion and Others. + +
3:41:55 AM
+
+
22 Jan 2023
+
@@ -248,14 +259,14 @@

Saved Posts

- + -