Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak committed Jan 29, 2024
1 parent 3f4c38e commit a4ce11b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
27 changes: 18 additions & 9 deletions src/lib/homework/CreateHomeworkAssignment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
export let allAssignments: Assignment[];
export let fromDate: CustomDate;
export let canUseTimetable = true;
let fromAbbr: WeekDay = getWeekdayAbbreviationByDate(fromDate);
let dueWeekday = nextWeekdayForSubject(fromAbbr, subject);
let inputModified = false;
let inputModified = true;
const inputModifiedFalse = () => (inputModified = false);
$: {
Expand All @@ -31,14 +33,17 @@
}
$: {
fromAbbr = getWeekdayAbbreviationByDate(fromDate);
dueWeekday = nextWeekdayForSubject(fromAbbr, subject);
(() => {
if (!canUseTimetable) return;
fromAbbr = getWeekdayAbbreviationByDate(fromDate);
dueWeekday = nextWeekdayForSubject(fromAbbr, subject);
if (!inputModified) {
due = nextCustomDateForWeekday(dueWeekday, fromDate);
} else {
inputModifiedFalse();
}
if (!inputModified) {
due = nextCustomDateForWeekday(dueWeekday, fromDate);
} else {
inputModifiedFalse();
}
})();
}
let autocompleteSubjects = $settings.useTimeTableForAutcomplete
Expand All @@ -51,7 +56,8 @@
: subjectsSortetCapitalized;
}
const generateFullAssignment: () => Assignment = () => ({ subject, description, due });
type ReturnAssignment = () => Assignment;
const generateFullAssignment: ReturnAssignment = () => ({ subject, description, due });
</script>

<div class="flex flex-col justify-evenly items-center">
Expand Down Expand Up @@ -86,6 +92,9 @@
<input
type="text"
bind:value={subject}
on:input={() => {
canUseTimetable = true;
}}
placeholder={i('homework.add.subject')}
class="w-full outline-1 outline-gray-400 outline rounded-sm p-1"
list={`subjects-${fromAbbr}`}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/homework/CreateHomeworkInner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
export let date: CustomDate;
export let canUseTimetable = true;
const emptyAssignment: Assignment = {
subject: '',
description: '',
Expand All @@ -23,6 +25,7 @@
bind:description={assignment.description}
bind:due={assignment.due}
bind:allAssignments={assignments}
{canUseTimetable}
fromDate={date}
/>
</li>
Expand Down
16 changes: 5 additions & 11 deletions src/lib/homework/DataBoxAssignment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import { getIconForSubject, iconExistsForSubject } from '../../constants/subjecticons';
import { subjectColors } from '../../stores';
import type { Assignment } from '../../types/homework';
import { localstorage } from 'svocal';
import { SvocalKeys } from '../../enums/svocal';
import { translate } from '$lib/translate/index';
import Loader from '$lib/Loader.svelte';
import { translate } from '$lib/translate/index';
import { SvocalKeys } from '../../enums/svocal';
import { localstorage } from 'svocal';
import { get } from 'svelte/store';
export let assignment: Assignment;
Expand All @@ -30,13 +31,6 @@
: '';
});
let libretranslateUrl = localstorage(
SvocalKeys.LIBRETRANSLATE_URL,
'https://libretranslate.com/'
);
let libretranslateToken = localstorage(SvocalKeys.LIBRETRANSLATE_TOKEN, '');
let useLibreTranslate = localstorage(SvocalKeys.LIBRETRANSLATE_ENABLE, false);
$: isOverdue = dateIsInPast(assignment.due);
$: {
subjColor = $subjectColors.filter(
Expand All @@ -63,7 +57,7 @@
<h4>{assignment.subject}</h4>
<DateLabel date={assignment.due} />
</span>
{#if $useLibreTranslate}
{#if get(localstorage(SvocalKeys.LIBRETRANSLATE_ENABLE, false))}
{#await translate(assignment.description)}
<span class="flex gap-1">
<Loader type="inline" />
Expand Down
6 changes: 5 additions & 1 deletion src/lib/homework/DataBoxInner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
<TimeAgo classes="text-xs" timestamp={createdAt} type="edited" />
</div>
{#if editMode}
<CreateHomeworkInner bind:assignments={newAssignments} bind:date={newDate} />
<CreateHomeworkInner
bind:assignments={newAssignments}
bind:date={newDate}
canUseTimetable={false}
/>
{:else}
<ul class="list-none p-0 flex flex-col gap-3">
{#each assignments as assignment}
Expand Down

0 comments on commit a4ce11b

Please sign in to comment.