implement send messages and notiseboard

This commit is contained in:
PoliEcho 2025-04-10 00:11:55 +02:00
parent fe9735fe58
commit 5173a05a09
3 changed files with 14 additions and 8 deletions

View File

@ -7,8 +7,6 @@
#include <cstring>
#include <curses.h>
#include <cwchar>
#include <fstream>
#include <iostream>
#include <menu.h>
#include <nlohmann/json.hpp>
#include <string>
@ -23,14 +21,18 @@ std::vector<allocation> komens_allocated;
void insert_content(WINDOW *content_window, size_t i, json &resp_from_api);
void komens_page() {
void komens_page(koment_type type) {
current_allocated = &komens_allocated;
json resp_from_api;
{
/*std::ifstream f("test-data/komens.json");
resp_from_api = json::parse(f);
f.close();*/
const std::string endpoint = "/api/3/komens/messages/received";
const char *types[] = {"/api/3/komens/messages/received",
"/api/3/komens/message",
"/api/3/komens/messages/noticeboard"};
const std::string endpoint = types[type];
resp_from_api = bakaapi::get_data_from_endpoint(endpoint, POST);
}
@ -94,7 +96,7 @@ void komens_page() {
komens_items[i] = new_item(title_bufs[i], name_bufs[i]);
}
max_item_lenght = max_title_lenght + max_name_lenght;
max_item_lenght = 3 + max_title_lenght + 1 + max_name_lenght;
}
komens_items[num_of_komens] = nullptr;

View File

@ -1,4 +1,9 @@
#ifndef _ba_ko_hg_
#define _ba_ko_hg_
void komens_page();
enum koment_type {
RECEIVED,
SEND,
NOTICEBOARD,
};
void komens_page(koment_type type);
#endif

View File

@ -11,7 +11,6 @@ void komens_menu() {
wchar_t *choices[] = {
L"received", L"send", L"noticeboard", L"Exit", nullptr,
};
void (*choicesFuncs[])() = {komens_page, nullptr, nullptr, nullptr, nullptr};
ITEM **my_items;
int c;
@ -88,7 +87,7 @@ void komens_menu() {
if (item_index(current_item(my_menu)) == n_choices - 1) {
goto close_menu;
}
choicesFuncs[item_index(current_item(my_menu))]();
komens_page(static_cast<koment_type>(item_index(current_item(my_menu))));
pos_menu_cursor(my_menu);
refresh();
wrefresh(my_menu_win);