Compare commits

..

No commits in common. "48b4f9cda8d8139eaf4011fe3e6289af938ec841" and "fe9735fe58ad9777832ee0e722efa5a267bd3aa9" have entirely different histories.

3 changed files with 9 additions and 15 deletions

View File

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

View File

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

View File

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