Skip to content

Commit

Permalink
Language chooser in navbar (#99)
Browse files Browse the repository at this point in the history
* Theme radio dropdowns

* Add language switch to navbar

* yarn build

* fixup! Add language switch to navbar

* Update LanguageForm to use AlpineJS

* Simplify LanguageForm

---------

Co-authored-by: Kevin Chung <[email protected]>
  • Loading branch information
erdnaxe and ColdHeat authored Nov 26, 2024
1 parent 3f9bb7a commit 4ecf9da
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 43 deletions.
20 changes: 20 additions & 0 deletions assets/js/components/language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import CTFd from "../index";
import Alpine from "alpinejs";

Alpine.data("LanguageForm", () => ({
async set(event) {
let language = event.target.getAttribute("value");
document.cookie = `language=${language};SameSite=Lax`;

// Set user language preference if logged in
if (CTFd.user.id) {
await CTFd.fetch("/api/v1/users/me", {
method: "PATCH",
body: JSON.stringify({ language }),
});
}

// Reload with new language
window.location.reload();
},
}));
2 changes: 2 additions & 0 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import eventAlerts from "./utils/notifications/alerts";
import eventToasts from "./utils/notifications/toasts";
import eventRead from "./utils/notifications/read";

import "./components/language";

dayjs.extend(advancedFormat);
CTFd.init(window.init);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion static/assets/page.3c5083de.js

This file was deleted.

1 change: 1 addition & 0 deletions static/assets/page.811c80a2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{C as o,m as d}from"./index.8a9f494f.js";window.CTFd=o;window.Alpine=d;d.start();

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ecf9da

Please sign in to comment.