Skip to content

Commit

Permalink
feat: font increase and decrease buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus64 committed Jan 29, 2024
1 parent 7d82459 commit bacdd69
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { signOut, updateUserInfo } from '@/services/api/auth'
import Link from './Link.svelte'
import { darkTheme } from '@/state/dark'
import { darkTheme } from '@/state/config'
import Logo from './Logo.svelte'
import Switch from './Switch.svelte'
import {
Expand Down
23 changes: 13 additions & 10 deletions src/components/Passage.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<script context="module">
/**
* @typedef {object} Verse
* @prop {string} study
* @prop {number} number
* @prop {string} verse
*/
/**
* @typedef {object} PassageInfo
* @prop {number} num_chapters
Expand All @@ -7,13 +13,6 @@
* @prop {string} chapter
* @prop {Array<Verse>} vers
*/
/**
* @typedef {object} Verse
* @prop {string} study
* @prop {number} number
* @prop {string} verse
*/
</script>

<script>
Expand All @@ -25,6 +24,10 @@
export let studyMode = false
export let className = ''
/**
* @type {number}
*/
export let fontSize
/** @type {PassageInfo} */
export let info = {
num_chapters: 50,
Expand All @@ -49,15 +52,15 @@
: 'm-4 w-full max-w-full'
} ${className}`}
>
<h3 class="mt-4 text-3xl">{formatName(info.name)}: {info.chapter}</h3>
<h3 class={`mt-4 text-3xl`}>{formatName(info.name)}: {info.chapter}</h3>

{#if info.vers && info.vers.length > 0}
<ul class="flex flex-col gap-2 p-4">
{#each info.vers as v}
{#if v.study}
<h3 class="p-2 text-3xl">{v.study}</h3>
<h3 class="p-2" style={`font-size: ${fontSize + 10}px`}>{v.study}</h3>
{/if}
<p class="verse text-2xl">
<p class="verse" style={`font-size: ${fontSize}px`}>
<b>
{v.number}
</b>
Expand Down
29 changes: 28 additions & 1 deletion src/components/StudyChapter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { createAlert } from '@/services/alert'
import Button from '@/components/Button.svelte'
import { studyMode } from '@/state/study'
import { fontSize, setFontSize } from '@/state/config'
import Passage from '@/components/Passage.svelte'
import { Stretch } from 'svelte-loading-spinners'
import { clickOutside } from '@/utils/clickOutside.js'
Expand All @@ -16,6 +17,8 @@
import Note from './icons/Note.svelte'
import Exit from './icons/Exit.svelte'
import { scale } from 'svelte/transition'
import IncreaseFont from './icons/IncreaseFont.svelte'
import DecreaseFont from './icons/DecreaseFont.svelte'
/** @type {string} */
export let versionRead = 'rv1960'
Expand Down Expand Up @@ -52,6 +55,11 @@
onMount(async () => {
info = await getData()
chapters = info.num_chapters
let configFontSize = localStorage.getItem('fontSize')
if (configFontSize) {
fontSize.set(parseInt(configFontSize))
}
})
async function getData() {
Expand Down Expand Up @@ -167,6 +175,18 @@
break
}
}
function increaseFont() {
if ($fontSize === 25) return
setFontSize($fontSize + 1)
}
function decreaseFont() {
if ($fontSize === 16) return
setFontSize($fontSize - 1)
}
</script>

<svelte:head>
Expand Down Expand Up @@ -410,6 +430,13 @@
>
Nuevo Testamento
</Button>

<Button color="blue" on:click={increaseFont} disabled={$fontSize === 25}>
<IncreaseFont width="1.5rem" height="1.5rem" />
</Button>
<Button color="blue" on:click={decreaseFont} disabled={$fontSize === 16}>
<DecreaseFont width="1.5rem" height="1.5rem" />
</Button>
</div>
</section>

Expand All @@ -426,7 +453,7 @@
<div class="flex max-w-full flex-row max-lg:flex-col">
{#if !loading}
<section class={$studyMode ? 'max-w-full xl:w-1/2 2xl:w-2/4' : 'w-full max-w-full'}>
<Passage className="max-lg:mb-28" studyMode={$studyMode} {info} />
<Passage fontSize={$fontSize} className="max-lg:mb-28" studyMode={$studyMode} {info} />
</section>
{/if}

Expand Down
5 changes: 1 addition & 4 deletions src/components/Switch.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { darkTheme } from '@/state/dark'
import { darkTheme } from '@/state/config'
export let className = ''
let darkMode = false
Expand All @@ -14,9 +14,6 @@
? document.documentElement.classList.add('dark')
: document.documentElement.classList.remove('dark')
}
</script>

<div class={className}>
Expand Down
8 changes: 8 additions & 0 deletions src/components/icons/DecreaseFont.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
/** @type {string} */
export let className = ''
export let width = '24'
export let height = '24'
</script>

<svg xmlns="http://www.w3.org/2000/svg" {width} {height} class={className} viewBox="0 0 24 24"><path fill="currentColor" d="m1.615 18.5l5.289-13h.961l5.289 13h-1.208l-1.448-3.633H4.194L2.746 18.5zm2.939-4.6h5.584L7.435 7.1h-.139zm10.83-1.4v-1h7v1z"/></svg>
13 changes: 13 additions & 0 deletions src/components/icons/IncreaseFont.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
/** @type {string} */
export let className = ''
export let width = '24'
export let height = '24'
</script>

<svg xmlns="http://www.w3.org/2000/svg" {width} {height} class={className} viewBox="0 0 24 24">
<path
fill="currentColor"
d="m1.615 18.5l5.289-13h.961l5.289 13h-1.208l-1.448-3.633H4.194L2.746 18.5zm2.939-4.6h5.584l-2.71-6.8h-.132zm13.83 1.6v-3h-3v-1h3v-3h1v3h3v1h-3v3z"
/>
</svg>
39 changes: 19 additions & 20 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@
import { browser } from '$app/environment'
import { onMount } from 'svelte'
import '@/app.css'
import { darkTheme } from '@/state/dark'
import { darkTheme } from '@/state/config'
export const checkMode = () => {
if (browser) {
if (
localStorage.theme === 'dark' ||
(!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
document.documentElement.classList.add('dark')
darkTheme.set(true)
} else {
document.documentElement.classList.remove('dark')
darkTheme.set(false)
}
}
if (browser) {
if (
localStorage.theme === 'dark' ||
(!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
document.documentElement.classList.add('dark')
darkTheme.set(true)
} else {
document.documentElement.classList.remove('dark')
darkTheme.set(false)
}
}
}
onMount(() => checkMode())
</script>

<div class="flex max-w-[100vw] flex-col justify-between transition-colors theme-transition">
<div class="theme-transition flex max-w-[100vw] flex-col justify-between transition-colors">
<Navbar />

<main class="mx-auto flex w-full max-w-screen-xl flex-col p-4">
Expand All @@ -34,7 +32,8 @@
</div>

<style>
.theme-transition {
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
</style>
.theme-transition {
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
</style>
4 changes: 1 addition & 3 deletions src/routes/notes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import { onMount } from 'svelte'
import Swal from 'sweetalert2'
import { user } from '@/state/user'
import { notes } from '@/state/notes'
import { darkTheme } from '@/state/dark'
import { darkTheme } from '@/state/config'
import { createAlert } from '@/services/alert'
import Button from '@/components/Button.svelte'
import { Stretch } from 'svelte-loading-spinners'
import { API_BASE_URL } from '@/constants'
import { draft, studyMode } from '@/state/study'
import { goto } from '$app/navigation'
let loadingNotes = true
Expand Down
2 changes: 1 addition & 1 deletion src/services/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isDarkTheme } from '@/utils/darkTheme'
* @param {'error'|'loading'|'success'|'normal'=} type
* @param {number=} duration
*/
export async function createAlert (message, type = 'normal', duration = 2000) {
export async function createAlert(message, type = 'normal', duration = 2000) {
const { toast } = await import('wc-toast')
const types = ['error', 'loading', 'success']
/** @type {{ type: 'dark'|'light'|'custom'|undefined }} */
Expand Down
14 changes: 14 additions & 0 deletions src/state/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { writable } from 'svelte/store'

export const darkTheme = writable(false)

export const fontSize = writable(16)

/**
*
* @param {number} size
*/
export function setFontSize(size) {
fontSize.set(size)
localStorage.setItem('fontSize', JSON.stringify(size))
}
3 changes: 0 additions & 3 deletions src/state/dark.js

This file was deleted.

1 comment on commit bacdd69

@vercel
Copy link

@vercel vercel bot commented on bacdd69 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bible-app-ubqz – ./

bible-app-ubqz-git-main-atticus64.vercel.app
bible-app-ubqz-atticus64.vercel.app
bible-study.vercel.app

Please sign in to comment.