native: add stack view and login api

This commit is contained in:
Johannes Jöns 2024-07-11 10:49:13 +02:00
parent c8343c1600
commit addc7450a6
4 changed files with 171 additions and 106 deletions

View file

@ -18,6 +18,7 @@ qt_add_qml_module(alisa
Main.qml
Data.qml
Test.qml
MainPage.qml
LoginScreen.qml
RESOURCES

View file

@ -19,6 +19,8 @@ Window {
height: 400
visible: true
signal loginSuccess(string token)
color: getColors().window
Text {
@ -71,5 +73,26 @@ Window {
}
text: qsTr("Submit")
onClicked: {
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.clan-war.net/api/v1/auth/login");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace
loginSuccess(token);
} else {
console.log("Login failed: " + xhr.status);
}
}
}
var data = JSON.stringify({
email: nameT.text,
password: passwordT.text
});
xhr.send(data);
}
}
}

View file

@ -1,4 +1,4 @@
import QtQuick 2.15
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 2.15
import QtQuick.Controls 2.15
@ -20,117 +20,28 @@ Window {
title: qsTr("Alisa - License Managment")
Rectangle {
id: s1
anchors {
top: parent.top
left: parent.left
right: parent.right
}
radius: 0
height: 50
color: getColors().midlight
property string authToken: ""
TextField {
anchors{
verticalCenter: s1.verticalCenter
rightMargin: 5
right: logginB.left
}
StackView {
id: stackView
anchors.fill: parent
initialItem: loginPageComponent
}
placeholderText: qsTr("Seach")
}
Button{
id: logginB
anchors{
verticalCenter: s1.verticalCenter
rightMargin: 10
right: s1.right
}
text: qsTr("Login")
onClicked: {
var component = Qt.createComponent("LoginScreen.qml")
var window = component.createObject(root)
window.show()
Component {
id: loginPageComponent
LoginScreen {
onLoginSuccess: {
authToken = token
stackView.push(mainPageComponent)
}
}
}
Rectangle{
id: s2
anchors {
top: s1.bottom
left: parent.left
right: parent.right
bottom: parent.bottom
}
radius: 0
color: getColors().window
TableView {
anchors {
topMargin: 5
fill: s2
}
columnSpacing: 0
rowSpacing: 1
clip: true
boundsBehavior: Flickable.StopAtBounds
model: Data {}
delegate: Rectangle {
id: r
anchors{
}
color: getColors().base
implicitWidth: 100
implicitHeight: 50
border.width: 0
Text {
anchors {
horizontalCenter: r.horizontalCenter
verticalCenter: r.verticalCenter
}
text: display
color: getColors().text
anchors.centerIn: parent
}
}
}
}
Button {
id: testB
anchors {
bottom: parent.bottom
left: parent.left
}
text: qsTr("Test Window")
onClicked: {
var component = Qt.createComponent("Test.qml")
var window = component.createObject(root)
window.show()
}
}
Button {
id: loginScreenB
anchors {
left: testB.right
bottom: parent.bottom
}
text: qsTr("Login Screen")
onClicked: {
var component = Qt.createComponent("LoginScreen.qml")
var window = component.createObject(root)
window.show()
Component {
id: mainPageComponent
MainPage {
authToken: authToken
}
}
}

130
native/MainPage.qml Normal file
View file

@ -0,0 +1,130 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 2.15
import QtQuick.Controls 2.15
Rectangle {
SystemPalette { id: activeColors; colorGroup: SystemPalette.Active }
SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive }
SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled }
function getColors() {
return root.active ? activeColors : inactiveColors;
}
property string authToken: ""
Rectangle {
id: s1
anchors {
top: parent.top
left: parent.left
right: parent.right
}
radius: 0
height: 50
color: getColors().midlight
TextField {
anchors{
verticalCenter: s1.verticalCenter
rightMargin: 5
right: logginB.left
}
placeholderText: qsTr("Seach")
}
Button{
id: logginB
anchors{
verticalCenter: s1.verticalCenter
rightMargin: 10
right: s1.right
}
text: qsTr("Login")
onClicked: {
var component = Qt.createComponent("LoginScreen.qml")
var window = component.createObject(root)
window.show()
}
}
}
Rectangle{
id: s2
anchors {
top: s1.bottom
left: parent.left
right: parent.right
bottom: parent.bottom
}
radius: 0
color: getColors().window
TableView {
anchors {
topMargin: 5
fill: s2
}
columnSpacing: 0
rowSpacing: 1
clip: true
boundsBehavior: Flickable.StopAtBounds
model: Data {}
delegate: Rectangle {
id: r
anchors{
}
color: getColors().base
implicitWidth: 100
implicitHeight: 50
border.width: 0
Text {
anchors {
horizontalCenter: r.horizontalCenter
verticalCenter: r.verticalCenter
}
text: display
color: getColors().text
anchors.centerIn: parent
}
}
}
}
Button {
id: testB
anchors {
bottom: parent.bottom
left: parent.left
}
text: qsTr("Test Window")
onClicked: {
var component = Qt.createComponent("Test.qml")
var window = component.createObject(root)
window.show()
}
}
Button {
id: loginScreenB
anchors {
left: testB.right
bottom: parent.bottom
}
text: qsTr("Login Screen")
onClicked: {
var component = Qt.createComponent("LoginScreen.qml")
var window = component.createObject(root)
window.show()
}
}
}