<commit_before>"use strict";

import m = require("mithril");

export function initialize() {
    console.log("Chat Text plugin initialized");
}

var messages = [];

function displayChatLog() {
    return m("div", [
        "Chat log:", m("br"),
        messages.map((message) => {
            return m("div.message", [
                message.text,
                message.status === "pending" ? m("i", " (pending)") : ""
            ]);
        })
    ]);
}

function sendMessage() {
    console.log("send message", currentMessage);
    var newMessage = {
        text: currentMessage,
        status: "pending"
    };
    messages.push(newMessage);
    currentMessage = ""
}

function currentMessageChanged(message) {
    currentMessage = message;
}

var currentMessage = "";

function inputKeyPress(event) {
    var keycode = event.keycode || event.which || 0;
    // console.log("inputKeyPress", keycode);
    if (keycode === 13) {
        event.preventDefault();
        return sendMessage();
    }
    // Do not redraw for a character press as currentMessage will be out of sync with input field
    m.redraw.strategy("none");
}
    
function displayChatEntry() {
    return m("div", [
        "Message:",
        m("input", {
            value: currentMessage,
            onchange: m.withAttr("value", currentMessageChanged), 
            onkeyup: inputKeyPress,
            size: "80"
        }),
        m("button", {onclick: sendMessage}, "Send!")<commit_msg>Add store request that updates pending status in text chat plugin<commit_after>"use strict";

import m = require("mithril");

export function initialize() {
    console.log("Chat Text plugin initialized");
}

var messages = [];

function displayChatLog() {
    return m("div", [
        "Chat log:", m("br"),
        messages.map((message) => {
            return m("div.message", [
                message.text,
                message.status === "pending" ? m("i", " (pending)") : ""
            ]);
        })
    ]);
}

function sendMessage() {
    console.log("send message", currentMessage);
    var newMessage = {
        text: currentMessage,
        status: "pending"
    };
    messages.push(newMessage);
    currentMessage = ""
    
    m.request({
        method: "POST", 
        url: "/api/store", 
        data: {
            type: "store",
            content: newMessage.text,
            basket: "test"
        }
    }).then((result: any) => {
        console.log("m.request result", result);
        if (result.success) newMessage.status = "stored";
    });
    
    m.redraw();
}

function currentMessageChanged(message) {
    currentMessage = message;
}

var currentMessage = "";

function inputKeyPress(event) {
    var keycode = event.keycode || event.which || 0;
    // console.log("inputKeyPress", keycode);
    if (keycode === 13) {
        event.preventDefault();
        return sendMessage();
    }
    // Do not redraw for a character press as currentMessage will be out of sync with input field
    m.redraw.strategy("none");
}
    
function displayChatEntry() {
    return m("div", [
        "Message:",
        m("input", {
            value: currentMessage,
            onchange: m.withAttr("value", currentMessageChanged), 
            onkeyup: inputKeyPress,
            size: "80"
        }),
        m("button", {onclick: sendMessage}, "Send!")
{'fraction_non_alphanumeric': 0.14532975231274248, 'fraction_numerical': 0.0029841838257236644, 'mean_word_length': 2.270243902439024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6545562', 'n_tokens_mistral': 953, 'n_tokens_neox': 936, 'n_words': 231}