Skip to content

Commit

Permalink
feat: show commit hash in settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sxyntheon committed Jan 20, 2024
1 parent 7aaf09d commit d7e4f7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions frontend/src/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,28 @@ export const SubjectNames: { [key: string]: string } = {
};
export function JSESSIONIDCookieString(JSESSIONID: string): string {
return `JSESSIONID=${JSESSIONID}; max-age=600; secure; samesite=none; domain=.theschedule.de`;
}
export async function getCommitHash(): Promise<string> {
const result = await fetch("https://api.github.com/repos/ixhbinphoenix/bne/commits/master", {
method: "GET"
}) as unknown as Array<any>
try {
return JSON.parse(await readStream(result.body)).sha.substring(0, 7)
}
catch (error) {
return Promise.reject(error)
}
}
async function readStream(stream: ReadableStream<Uint8Array>) {
const textDecode = new TextDecoder();
const chunks = [];
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
chunks.push(textDecode.decode(value));
}
return chunks.join("");
}
10 changes: 9 additions & 1 deletion frontend/src/components/plan-components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import Logout from "./settings-components/Logout";
import UserData from "./settings-components/UserData";
import { onSwipe } from "../../api/Touch";
import { accountIsVerified, resendVerifyEmail } from "../../api/theBackend";
import { getCommitHash } from "../../api/main";

export default function Settings(): JSX.Element {
const [commitHash, setCommitHash] = useState("");
const [resendMessage, setResendMessage] = useState("Link erneut versenden");
const [NotVerifiedMessage, setNotVerifiedMessage] = useState({ display: "none" });
const [TopbarColor, setTopbarColor] = useState({ "background-color": "var(--highlight-blue)" });
Expand Down Expand Up @@ -72,6 +74,11 @@ export default function Settings(): JSX.Element {
const [pageContent, setPageContent] = useState<JSX.Element>(Menu);
const [username, setUsername] = useState("");
useEffect(() => {
getCommitHash().then(
(result) => {
setCommitHash(result)
}
)
showNotVerifiedMessage();
const usernameRaw = localStorage.getItem("untis_username");
const nameParts = usernameRaw?.split("_");
Expand All @@ -88,10 +95,11 @@ export default function Settings(): JSX.Element {
}, [pageContent]);

return (
<div class="settings-page">
<div class="settings-page" >
<div id="top-bar" style={TopbarColor}>
<div id="username">{username}</div>
{notVerifiedMessageDiv}
<p style="position: absolute; font-size: 1vmin; right: 0%; bottom: 0%;">Version: {commitHash}</p>
</div>
<button
class="back-button"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/styles/Settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
flex-direction: column;

& > #top-bar {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
Expand Down

0 comments on commit d7e4f7a

Please sign in to comment.