Refactor kantine.js into modular ES6 structure
Moved `kantine.js` into a `src/` directory with multiple modularized files: - `api.js`: All API calls and constants - `state.js`: State management (auth, cache, theme, tags, etc.) - `utils.js`: Helpers for UI and Date formatting - `ui.js`: DOM manipulation logic - `events.js`: Initial DOM event listeners and logic hooks - `actions.js`: Data fetching actions, local processing logic - `ui_helpers.js`: UI helper functions (rendering modals, handling DOM injections) Updated the `build-bookmarklet.sh` to compile with Webpack via newly created `webpack.config.js`. Updated all relevant test scripts to use the new output `dist/kantine.bundle.js` and modified logic to work within Webpack scopes. Co-authored-by: TauNeutrino <1600410+TauNeutrino@users.noreply.github.com>
This commit is contained in:
25
src/state.js
Normal file
25
src/state.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { getISOWeek } from './utils.js';
|
||||
|
||||
export let allWeeks = [];
|
||||
export let currentWeekNumber = getISOWeek(new Date());
|
||||
export let currentYear = new Date().getFullYear();
|
||||
export let displayMode = 'this-week';
|
||||
export let authToken = localStorage.getItem('kantine_authToken');
|
||||
export let currentUser = localStorage.getItem('kantine_currentUser');
|
||||
export let orderMap = new Map();
|
||||
export let userFlags = new Set(JSON.parse(localStorage.getItem('kantine_flags') || '[]'));
|
||||
export let pollIntervalId = null;
|
||||
export let langMode = localStorage.getItem('kantine_lang') || 'de';
|
||||
export let highlightTags = JSON.parse(localStorage.getItem('kantine_highlightTags') || '[]');
|
||||
|
||||
export function setAllWeeks(weeks) { allWeeks = weeks; }
|
||||
export function setCurrentWeekNumber(week) { currentWeekNumber = week; }
|
||||
export function setCurrentYear(year) { currentYear = year; }
|
||||
export function setDisplayMode(mode) { displayMode = mode; }
|
||||
export function setAuthToken(token) { authToken = token; }
|
||||
export function setCurrentUser(user) { currentUser = user; }
|
||||
export function setOrderMap(map) { orderMap = map; }
|
||||
export function setUserFlags(flags) { userFlags = flags; }
|
||||
export function setPollIntervalId(id) { pollIntervalId = id; }
|
||||
export function setLangMode(lang) { langMode = lang; }
|
||||
export function setHighlightTags(tags) { highlightTags = tags; }
|
||||
Reference in New Issue
Block a user