Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todo nav #50

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/Notepad.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -16,6 +16,7 @@
<Compile Include="queries/summary.sql.fs" />
<Compile Include="Database.fs" />
<Compile Include="Json.fs" />
<Compile Include="Word.fs" />
<Compile Include="Summary.fs" />
<Compile Include="Note.fs" />
<Compile Include="Program.fs" />
Expand Down
1 change: 1 addition & 0 deletions api/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ webHost [||] {
get "/api/diary/{id}" Note.noteByIdPartDebug
put "/api/diary/{id}" Note.addNotePart
get "/api/todo" Note.todoListsHandler
get "/api/random-word" Word.getRandomWord
]

use_middleware serveVueFiles
Expand Down
13 changes: 13 additions & 0 deletions api/Word.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Word

open System

let randomWords =
[ ] // Add more words as needed

let getRandomWord =
fun ctx ->
let random = Random()
let word = randomWords.[random.Next(randomWords.Length)]
// refresh note summary
Falco.Request.mapRoute (ignore) (fun _ -> {| word = word |} |> Json.Response.ofJson) ctx
58 changes: 8 additions & 50 deletions web/src/components/DiaryEditor.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
<template>
<div class="content">
<div class="nav">
{{ time }}
<a href="#">{{ date }}</a>
<a v-if="date != today" :href="'/view?date=' + today">Today</a>
<a v-if="date == today" href="/todo">Todo</a>
<a href="content">
<Icon :icon="icons.tableOfContents" />
<Icon v-if="loading" icon="line-md:loading-alt-loop" />
</a>
</div>
<div class="editor">
<el-tiptap :content="content" :extensions="extensions" @onUpdate="debouncedOnUpdate" @onInit="onInit"></el-tiptap>
<el-tiptap :key="'editor-' + date" :content="content" :extensions="extensions" @onUpdate="debouncedOnUpdate" @onInit="onInit"></el-tiptap>
</div>
<Icon v-if="loading" icon="line-md:loading-alt-loop" />
</div>
</template>

Expand Down Expand Up @@ -42,29 +33,12 @@ const props = defineProps({
});


const now = ref(moment());
const loading = ref(true);
const timeFormat = 'h:mm:ss a';
const last_note_json = ref(null);
const content = ref(null);
const icons = {
tableOfContents,
};
const extensions = createExtensions();
const json = ref(null);

onMounted(() => {
// eslint-disable-next-line no-unused-vars
const interval = setInterval(() => now.value = moment(), 1000);
});

const today = computed(() => {
return now.value.format('YYYYMMDD');
});

const time = computed(() => {
return now.value.format(timeFormat);
});

const mutation = useMutation({
mutationFn: async () => {
Expand Down Expand Up @@ -122,38 +96,22 @@ const onInit = async ({ editor }) => {
editor.setContent(lastNoteJson);
}
} catch (error) {
if (error.response && error.response.status === 401) {
// Use the correct router method in the Vue 3 setup
router.push({ name: 'login' });
}
console.error('Error updating diary:', error);
console.error('Error fetching diary content:', error);
} finally {
loading.value = false;
}
};
</script>

<style>
.content {
max-width: 65rem;
margin: auto;
}

.nav {
margin: 1em 1em 1rem 1em;
display: flex;
justify-content: space-between;
}

<style scoped>
pre code {
font-family: "Fira Code", Courier, Monaco, monospace;
}

.nav a {
display: inline-block;
text-decoration: none;
border-radius: 5%;
}

/* Change the link color on hover */
.nav a:hover {
background-color: rgb(223, 214, 214);
color: white;
}
</style>
2 changes: 1 addition & 1 deletion web/src/components/NavBar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="nav">
<a v-if="date != today" :href="'/view?date=' + today">Diary</a>
<a v-if="date != today" href="/">Diary</a>
<a href="content">
<Icon :icon="icons.tableOfContents" />
<Icon v-if="loading" icon="line-md:loading-alt-loop" />
Expand Down
2 changes: 1 addition & 1 deletion web/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default new Router({
name: 'home',
component: Home
},
{ path: '/login', component: Login },
{ path: '/login', component: Login, name: 'login' },
{ path: '/logout', component: Logout },
{
path: '/content',
Expand Down
2 changes: 1 addition & 1 deletion web/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export function parseJwt (token) {
}).join(''))

return JSON.parse(jsonPayload)
}
}
93 changes: 88 additions & 5 deletions web/src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,98 @@
<template>
<DiaryEditor :date="date"></DiaryEditor>
<div class="content">
<div class="nav">
{{ time }}
<div class="date-nav">
<div @click="navigateDate(-1)" class="icon-container">
<Icon icon="grommet-icons:form-previous" width="1.2rem" />
</div>
<div>
{{ displayDate }}
</div>
<div v-if="date < today" @click="navigateDate(1)" class="icon-container">
<Icon icon="grommet-icons:form-next" width="1.2rem" />
</div>
<div v-if="date != today" @click="navigateDateToToday" class="icon-container">
<Icon icon="fluent:arrow-next-16-regular" width="1.2rem" />
</div>
</div>
<a href="/todo">Todo</a>
<a href="content">
<Icon :icon="tableOfContents" />
</a>
</div>
<DiaryEditor :date="date"></DiaryEditor>
</div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { ref, computed, onMounted } from 'vue';
import moment from 'moment';
import { Icon } from '@iconify/vue2';
import tableOfContents from '@iconify/icons-mdi/table-of-contents';
import DiaryEditor from "@/components/DiaryEditor";
import { get_date_of_today } from "../util.js";

const date = ref(get_date_of_today());

const now = ref(moment());
const date = ref(moment().format('YYYYMMDD'))

onMounted(() => {
date.value = get_date_of_today();
// eslint-disable-next-line no-unused-vars
date.value = now.value.format("YYYYMMDD")
const interval = setInterval(() => now.value = moment(), 1000);
});

const today = computed(() => {
return now.value.format('YYYYMMDD');
});

const time = computed(() => {
const timeFormat = 'h:mm:ss a';
return now.value.format(timeFormat);
});

const displayDate = computed(() => {
if (date.value == today.value) {
return 'Today'
} else {
return date.value
}
})

function navigateDate(offset) {
const newDate = moment(date.value).add(offset, 'days').format("YYYYMMDD");
if (newDate > today.value) {
alert("can not into future")
}
date.value = newDate
}

function navigateDateToToday() {
date.value = today.value
}

</script>

<style scoped>
.content {
max-width: 65rem;
margin: auto;
}

.nav {
margin: 1em 1em 1rem 1em;
display: flex;
justify-content: space-between;
}

.nav .date-nav {
display: flex;
align-items: center;
white-space: nowrap;
}

.icon-container {
display: flex;
align-items: center;
}
</style>
Loading