1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-23 14:59:36 +02:00

feat: Implement lazy loading for images and update dependencies

This commit is contained in:
Sean Morley 2024-05-05 14:00:40 +00:00
parent e949c06bd2
commit 4069bc5052
3 changed files with 41 additions and 24 deletions

View file

@ -15,6 +15,7 @@
import type { Adventure } from "$lib/utils/types";
const dispatch = createEventDispatcher();
import { onMount } from "svelte";
import { addActivityType } from "$lib";
let modal: HTMLDialogElement;
onMount(() => {
@ -25,7 +26,7 @@
});
function create() {
addActivityType();
activitySetup();
if (newAdventure.name.trim() === "") {
alert("Name is required");
return;
@ -46,16 +47,10 @@
let activityInput: string = "";
function addActivityType() {
if (activityInput.trim() !== "") {
const activities = activityInput
.split(" ")
.filter((activity) => activity.trim() !== "");
newAdventure.activityTypes = activities;
function activitySetup() {
newAdventure = addActivityType(activityInput, newAdventure);
activityInput = "";
}
console.log(newAdventure.activityTypes);
}
</script>
<dialog id="my_modal_1" class="modal">

View file

@ -4,6 +4,7 @@
import type { Adventure } from "$lib/utils/types";
const dispatch = createEventDispatcher();
import { onMount } from "svelte";
import { addActivityType } from "$lib";
let modal: HTMLDialogElement;
console.log(adventureToEdit.id);
@ -19,7 +20,7 @@
});
function submit() {
addActivityType();
activitySetup();
dispatch("submit", adventureToEdit);
console.log(adventureToEdit);
}
@ -36,16 +37,10 @@
let activityInput: string = "";
function addActivityType() {
if (activityInput.trim() !== "") {
const activities = activityInput
.split(",")
.filter((activity) => activity.trim() !== "");
adventureToEdit.activityTypes = activities;
function activitySetup() {
adventureToEdit = addActivityType(activityInput, adventureToEdit);
activityInput = "";
}
console.log(adventureToEdit.activityTypes);
}
</script>
<dialog id="my_modal_1" class="modal">

View file

@ -1,5 +1,6 @@
import inspirationalQuotes from "./json/quotes.json";
import countryCodes from "./json/countries.json";
import type { Adventure } from "./utils/types";
/**
* Converts a country code to its corresponding country name.
@ -8,7 +9,8 @@ import countryCodes from "./json/countries.json";
*/
export function countryCodeToName(countryCode: string): string | null {
// Look up the country name using the provided country code
const countryName = countryCodes[countryCode.toLowerCase() as keyof typeof countryCodes];
const countryName =
countryCodes[countryCode.toLowerCase() as keyof typeof countryCodes];
// Return the country name if found, otherwise return null
return countryName || null;
}
@ -19,7 +21,7 @@ export function countryCodeToName(countryCode: string): string | null {
* @param country - The 2 digit country code representing the desired flag.
* @returns The URL of the flag image.
*/
export function getFlag(size:number,country: string) {
export function getFlag(size: number, country: string) {
return `https://flagcdn.com/h${size}/${country}.png`;
}
@ -48,5 +50,30 @@ export function getRandomQuote() {
const randomIndex = Math.floor(Math.random() * quotes.length);
let quoteString = quotes[randomIndex].quote;
let authorString = quotes[randomIndex].author;
return "\"" + quoteString + "\" - " + authorString;
return '"' + quoteString + '" - ' + authorString;
}
/**
* Adds activity types to the adventure.
*
* @param activityInput - The input string containing activity types separated by commas.
* @param adventureToEdit - The adventure object to which the activity types will be added.
* @returns The adventure object with the updated activity types.
*/
export function addActivityType(
activityInput: string,
adventureToEdit: Adventure
) {
if (activityInput.trim() !== "") {
const activities = activityInput
.split(",")
.filter((activity) => activity.trim() !== "");
// trims the whitespace from the activities
for (let i = 0; i < activities.length; i++) {
activities[i] = activities[i].trim();
}
adventureToEdit.activityTypes = activities;
activityInput = "";
}
return adventureToEdit;
}