Skip to content

Commit

Permalink
Loading first favorite + setting to deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialFreak committed Nov 12, 2023
1 parent 3e95576 commit 5da13b5
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 24 deletions.
4 changes: 2 additions & 2 deletions client/public/base_static/site.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"theme_color": "#121212",
"background_color": "#121212",
"display": "standalone",
"start_url": "../#favorite",
"scope": "../",
"start_url": "/#favorite",
"scope": "/",
"id": "better_vplan",
"description": "Die (garantiert bessere!!!) Alternative zur VpMobil24 App",
"lang": "de",
Expand Down
39 changes: 25 additions & 14 deletions client/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"cached": "Offline Plan",
"network_cached": "Aktueller Plan",
"network_uncached": "Online only Plan"
}
};
let load_favorite = false;
function init_vars() {
school_num = localStorage.getItem('school_num');
Expand Down Expand Up @@ -285,40 +286,44 @@
}
}
$: select_plan($favourites, $selected_favourite);
function navigate_favorite() {
if(!load_favorite || !$settings.load_first_favorite) {
return;
}
navigate_page('plan');
if($favourites.length === 0) {
return;
}
$selected_favourite = 0;
load_favorite = false;
}
function reset_favourite() {
selected_favourite.set(-1);
}
// reset favourite when selecting new thing
$: selected_form && reset_favourite();
$: selected_teacher && reset_favourite();
$: selected_room && reset_favourite();
// reset favourite when selecting new plan
$: (selected_form || selected_teacher || selected_room) && reset_favourite();
$: if ($selected_favourite !== -1) {
// check if selected_favourite is in favourites
if ($favourites.length <= $selected_favourite) {
selected_favourite.set(-1);
}
}
// CHANGE THIS FOR SETTING IF FIRST FAVOURITE SHOULD BE SELECTED
/*$: if ($favourites.length !== 0 && $selected_favourite === -1) {
selected_favourite.set(0);
}*/
$logged_in = localStorage.getItem('logged_in') === 'true';
init_vars();
check_login_status();
refresh_plan_vars();
get_favourites();
$: $logged_in && init_indexed_db();
$: !$logged_in && logout();
$: school_num && (api_base = `/api/v69.420/${school_num}`);
$: get_meta(school_num);
$: school_num && get_meta(school_num);
$: all_revisions = [".newest"].concat((meta?.dates || {})[date] || []);
//$: school_num && get_preferences();
$: all_rooms && (grouped_rooms = group_rooms(all_rooms));
$: $logged_in && get_settings();
$: $logged_in && (get_settings(), get_favourites(navigate_favorite));
$: select_plan($favourites, $selected_favourite);
$: (Object.keys($settings).length !== 0) && localStorage.setItem("settings", `${JSON.stringify($settings)}`);
$: update_colors($settings);
$: $logged_in && get_greeting();
Expand Down Expand Up @@ -359,6 +364,10 @@
let new_location = location.hash.slice(1);
if(!((new_location === "login" || new_location === "register") && $logged_in)) {
if(new_location === "") {new_location = "plan";}
if(new_location === "favorite") {
load_favorite = true;
new_location = "plan";
}
navigate_page(new_location);
}
</script>
Expand Down Expand Up @@ -443,6 +452,8 @@
{/if}
{:else if $current_page === "school_manager"}
<SchoolManager bind:school_num bind:date bind:plan_type bind:plan_value />
{:else if $current_page === "favorite"}
<span class="responsive-text">Lade deine Favoriten...</span>
{:else if $current_page === "favorites"}
<Favourites />
{:else if $current_page === "pwa_install"}
Expand Down
15 changes: 13 additions & 2 deletions client/src/components/Favourites.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Button from "../base_components/Button.svelte";
import {notifications} from "../notifications.js";
import {favourites, title} from "../stores.js";
import {favourites, title, settings} from "../stores.js";
import CollapsibleWrapper from "../base_components/CollapsibleWrapper.svelte";
import Collapsible from "../base_components/Collapsible.svelte";
import { onMount } from "svelte";
Expand Down Expand Up @@ -243,7 +243,7 @@
<CollapsibleWrapper class="extra-accordion-padding" let:closeOtherPanels>
{#each cur_favourites as _, favourite}
<Collapsible on:panel-open={closeOtherPanels} let:toggle>
<button slot="handle" on:click={toggle} class="toggle-button" class:first={favourite == 0}>{cur_favourites[favourite].name ? cur_favourites[favourite].name : "Unbenannter Favorit"}</button>
<button slot="handle" on:click={toggle} class="toggle-button" class:first={favourite == 0} class:load_first_favorite={$settings.load_first_favorite}>{cur_favourites[favourite].name ? cur_favourites[favourite].name : "Unbenannter Favorit"}</button>
<div class="wrapper-content">
<label for="favourite_name">Name des Favoriten</label>
<input name="favourite_name" type="text" maxlength="40" class="textfield" bind:value={cur_favourites[favourite].name}>
Expand Down Expand Up @@ -334,6 +334,17 @@
&.first {
border-top: unset;
&.load_first_favorite {
outline: 2px solid var(--accent-color);
outline-offset: -2px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
@media only screen and (min-width: 1501px) {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
}
}
&.last {
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/Plan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
let tmp_date;
tmp_date = enabled_dates[(enabled_dates.indexOf(date)+day_amount)];
if (typeof tmp_date === 'undefined') {
notifications.danger("Für dieses Datum existiert kein Vertretungsplan!");
// Removed due to being more annoying than it bringing value to the UX
// notifications.danger("Für dieses Datum existiert kein Vertretungsplan!");
return;
}
date = tmp_date;
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<div class="settings-container">
<span class="responsive-text"><input type="checkbox" bind:checked={temp_settings.normal_greetings}>Normale Begrüßungen</span>
<span class="responsive-text"><input type="checkbox" bind:checked={temp_settings.chatgpt_greetings}>ChatGPT Begrüßungen</span>
<span class="responsive-text"><input type="checkbox" bind:checked={temp_settings.load_first_favorite}>Beim Start den ersten Favoriten laden</span>
<span class="responsive-text"><input type="checkbox" bind:checked={temp_settings.swipe_day_change}>Swipen um Tag zu wechseln</span>
<span class="responsive-text"><input type="checkbox" bind:checked={temp_settings.day_switch_keys}>Pfeiltasten (Tastatur) zum Tag wechseln nutzen</span>
<h2 class="category-heading">Aussehen</h2>
Expand Down
2 changes: 1 addition & 1 deletion client/src/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function gen_location_hash(location_name, school_num, date, plan_type, pl

export function load_lessons(data, plan_type, plan_value, use_grouped_form_plans, meta, plan_var_resetter, update_lessons) {
// Check if settings and data are loaded
if(use_grouped_form_plans === undefined || data === undefined) {
if(use_grouped_form_plans === undefined || data === undefined || data.length == 0) {
return;
}
// Check the presence of necessary variables
Expand Down
1 change: 0 additions & 1 deletion client/src/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export const active_modal = writable("");
export const notifications_list = writable([]);
export const pwa_prompt = writable();
export const new_changelogs_available = writable(false);
// TODO: as soon as this is connected to the endpoint, this needs to be cached and there needs to be a fallback
export const favourites = writable([]);
export const selected_favourite = writable(0);
8 changes: 5 additions & 3 deletions client/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,20 @@ export async function load_meta(school_num) {
})
}

export function get_favourites() {
export function get_favourites(callback = () => {}) {
return customFetch("/api/v69.420/favourites")
.then(data => {
localStorage.setItem("favourites", JSON.stringify(data));
favourites.set(data);
callback();
}).catch(error => {
console.log("Favourites couldn't be loaded from server.");
// check if favourites in localstorage
if(!localStorage.getItem("favourites")) {
favourites.set([])
favourites.set([]);
} else {
favourites.set(JSON.parse(localStorage.getItem("favourites")))
favourites.set(JSON.parse(localStorage.getItem("favourites")));
}
callback();
})
}
4 changes: 4 additions & 0 deletions var.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def validate_color(elem):
"default": True,
"type": "bool",
},
"load_first_favorite": {
"default": True,
"type": "bool",
},
}

TYPE_FUNCTIONS = {
Expand Down

0 comments on commit 5da13b5

Please sign in to comment.