Skip to content

Commit

Permalink
added suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nor0x committed Sep 10, 2024
1 parent 64be85e commit d39eb4a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
17 changes: 15 additions & 2 deletions WahlGPT.Web/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@
};


protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender)
{
await _js.InvokeVoidAsync("doSuggestions");
}
}

private void QuestionChanged(ChangeEventArgs e)
{
_question = e?.Value?.ToString() ?? "";
Expand All @@ -237,6 +245,11 @@
{
try
{
var question = _question;
if(string.IsNullOrEmpty(question))
{
return;
}
if (_timer is null)
{
_countDown = 10;
Expand All @@ -247,7 +260,7 @@
return;
}
_answers = new();
if (string.IsNullOrEmpty(_question))
if (string.IsNullOrEmpty(question))
{
return;
}
Expand All @@ -271,7 +284,7 @@
await _js.InvokeVoidAsync("scrollToElement", "#one");
foreach (var p in _parties.Where(p => p.selected))
{
var answer = await _chat.AskQuestion(_question, new List<string> { p.documentId });
var answer = await _chat.AskQuestion(question, new List<string> { p.documentId });
if (answer is null)
{
_answers.Add(("Sorry, ich konnte keine Antwort finden.", p.party, null));
Expand Down
46 changes: 44 additions & 2 deletions WahlGPT.Web/wwwroot/js/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
window.scrollToElement = function (selector) {
var element = document.querySelector(selector);
if (element) {
//animate height of #one to 200px

let one = document.getElementById('one');
one.style.height = 'auto';
one.style.opacity = '1';
Expand All @@ -18,3 +16,47 @@ window.copyToClipboard = function (email) {
alert('Email Adresse kopiert: ' + email);
}

let suggestions = [
"Was wird für Umweltschutz getan?",
"Wie ist die Position zu Klimaschutz?",
"Wie wird die Digitalisierung vorangetrieben?",
"Wie steht die Partei zum Thema Bildung?",
"Wie können Familien finanziell unterstützt werden?",
"Gibt es Pläne für die Gesundheitsversorgung?",
"Welche Pläne gibt es für die Pensionen?",
"Wie ist die Position zu sozialen Themen?",
"Welche Pläne gibt es für die Wirtschaft?",
"Wie können Startups unterstützt werden?",
"Wie ist die Position zu Europa und EU?",
"Wie steht die Partei zu Migration?",
"Welche Pläne gibt es für die Landwirtschaft?",
"Wie ist die Position zu Sicherheit und Polizei?",
];

var questionInput = undefined;
window.doSuggestions = function () {
questionInput = document.querySelector('.question-input');
question = questionInput.value;
if (question == '') {
let placeholder = document.querySelector('.question-input');
let index = Math.floor(Math.random() * suggestions.length);
typeWriter(placeholder, suggestions[index], 0);

setInterval(function () {
if (questionInput && questionInput.value == '') {
let placeholder = document.querySelector('.question-input');
let index = Math.floor(Math.random() * suggestions.length);
typeWriter(placeholder, suggestions[index], 0);
}
}, Math.floor(Math.random() * 3000) + 3000);
}
}

let typeWriter = function (element, text, i) {
if (i < text.length) {
element.setAttribute('placeholder', text.substring(0, i + 1));
setTimeout(function () {
typeWriter(element, text, i + 1)
}, Math.floor(Math.random() * 90) + 10);
}
}

0 comments on commit d39eb4a

Please sign in to comment.