Skip to content

Commit

Permalink
🐞fix: fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
blinko-space committed Oct 27, 2024
1 parent 7d8bf81 commit 348a180
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public/sitemap*
public/assets
.blinko/faiss/*
.blinko/pgdump/*
.blinko/files/*
dump.sql
5 changes: 3 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
transpilePackages: ['@mdxeditor/editor', 'react-diff-view'],
webpack: (config, { isServer }) => {
Expand All @@ -11,9 +12,9 @@ module.exports = {
return config;
},
outputFileTracing: true,
reactStrictMode: true,
reactStrictMode: isProduction? true : false,
swcMinify:false,
eslint: {
ignoreDuringBuilds: true,
},
}
}
28 changes: 12 additions & 16 deletions src/components/BlinkoRightClickMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import { DialogStore } from "@/store/module/Dialog";
import { BlinkoEditor } from "../BlinkoEditor";
import { useEffect, useState } from "react";
import { NoteType } from "@/server/types";
import { reaction } from "mobx";

export const BlinkoRightClickMenu = observer(() => {
const { t } = useTranslation();
const blinko = RootStore.Get(BlinkoStore)
const [forceUpdate, setForceUpdate] = useState(0)
const store = RootStore.Local(() => ({
editorHeight: 90,
editBlinko() {
console.log(123)
RootStore.Get(DialogStore).setData({
size: '2xl',
isOpen: true,
Expand All @@ -28,21 +29,16 @@ export const BlinkoRightClickMenu = observer(() => {
})
},
}))
useEffect(() => {
setForceUpdate(forceUpdate + 1)
}, [blinko.curSelectedNote])
return <ContextMenu className='font-bold' id="blink-item-context-menu" hideOnLeave={false} animation="zoom">
<ContextMenuItem onClick={e => {
store.editBlinko()
}}>
<ContextMenuItem onClick={() => { store.editBlinko() }}>
<div className="flex items-start gap-2">
<Icon icon="tabler:edit" width="20" height="20" />
<div>{t('edit')}</div>
</div>
</ContextMenuItem>
<ContextMenuItem onClick={e => {
blinko.isMultiSelectMode = true
blinko.onMultiSelectNote(blinko.curSelectedNote.id)
blinko.onMultiSelectNote(blinko.curSelectedNote?.id!)
}}>
<div className="flex items-start gap-2">
<Icon icon="mingcute:multiselect-line" width="20" height="20" />
Expand All @@ -53,32 +49,32 @@ export const BlinkoRightClickMenu = observer(() => {
<ContextMenuItem
onClick={e => {
blinko.upsertNote.call({
id: blinko.curSelectedNote.id,
type: blinko.curSelectedNote.type == NoteType.NOTE ? NoteType.BLINKO : NoteType.NOTE
id: blinko.curSelectedNote?.id,
type: blinko.curSelectedNote?.type == NoteType.NOTE ? NoteType.BLINKO : NoteType.NOTE
})
}}>
{forceUpdate && <div className="flex items-start gap-2">
<div className="flex items-start gap-2">
<Icon icon="ri:exchange-2-line" width="20" height="20" />
<div>{t('convert-to')} {blinko.curSelectedNote?.type == NoteType.NOTE ?
<span className='text-yellow-500'>{t('blinko')}</span> : <span className='text-blue-500'>{t('note')}</span>}</div>
</div>}
</div>
</ContextMenuItem>

<ContextMenuItem onClick={e => {
blinko.upsertNote.call({ id: blinko.curSelectedNote?.id, isArchived: !blinko.curSelectedNote?.isArchived })
}}>
{forceUpdate && <div className="flex items-start gap-2">
<div className="flex items-start gap-2">
<Icon icon="eva:archive-outline" width="20" height="20" />
{blinko.curSelectedNote?.isArchived ? t('recovery') : t('archive')}
</div>}
</div>
</ContextMenuItem>
<ContextMenuItem className='select-none divider hover:!bg-none'>
<Divider orientation="horizontal" />
</ContextMenuItem>

<ContextMenuItem onClick={async e => {
PromiseCall(api.notes.deleteMany.mutate({ ids: [blinko.curSelectedNote?.id] }))
api.ai.embeddingDelete.mutate({ id: blinko.curSelectedNote?.id })
PromiseCall(api.notes.deleteMany.mutate({ ids: [blinko.curSelectedNote?.id!] }))
api.ai.embeddingDelete.mutate({ id: blinko.curSelectedNote?.id! })
}}>
<div className="flex items-start gap-2 text-red-500">
<Icon icon="mingcute:delete-2-line" width="20" height="20" />
Expand Down
11 changes: 6 additions & 5 deletions src/components/Common/Editor/attachmentsRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { type Attachment } from '@/server/types';
type IProps = {
files: FileType[]
preview?: boolean
columns?: number
}

const AttachmentsRender = observer(({ files, preview = false }: IProps) => {
const AttachmentsRender = observer(({ files, preview = false, columns = 3 }: IProps) => {
const { t } = useTranslation()
const store = RootStore.Local(() => ({
deleteFile: new PromiseState({
Expand Down Expand Up @@ -51,7 +52,7 @@ const AttachmentsRender = observer(({ files, preview = false }: IProps) => {
})

return <>
<div className='columns-3 md:columns-3'>
<div className={`columns-${columns} md:columns-${columns}`}>
<PhotoProvider>
{files?.filter(i => i.isImage).map((file, index) => (
<div className='relative group'>
Expand Down Expand Up @@ -80,7 +81,7 @@ const AttachmentsRender = observer(({ files, preview = false }: IProps) => {
</PhotoProvider>

</div>
<div className="columns-3 mt-3">
<div className={`columns-${columns} mt-3`}>
{files?.filter(i => !i.isImage).map((file, index) => (
<div onClick={() => {
if (preview) {
Expand All @@ -98,12 +99,12 @@ const AttachmentsRender = observer(({ files, preview = false }: IProps) => {
</>
})

const FilesAttachmentRender = observer(({ files, preview }: { files: Attachment[], preview?: boolean }) => {
const FilesAttachmentRender = observer(({ files, preview, columns }: { files: Attachment[], preview?: boolean, columns?: number }) => {
const [handledFiles, setFiles] = useState<FileType[]>([])
useEffect(() => {
setFiles(HandleFileType(files))
}, [files])
return <AttachmentsRender files={handledFiles} preview={preview} />
return <AttachmentsRender files={handledFiles} preview={preview} columns={columns} />
})

export { AttachmentsRender, FilesAttachmentRender }
Expand Down
3 changes: 3 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { initStore } from '@/store/init';
import { Inspector, InspectParams } from 'react-dev-inspector';
import { CommonLayout } from '@/components/Layout';
import { AppProvider } from '@/store/module/AppProvider';
import { RootStore } from '@/store';
import { BlinkoStore } from '@/store/blinkoStore';
const MyApp = ({ Component, pageProps }) => {
console.log('use MyApp')
initStore();
useProgressBar();
return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/archived.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { observer } from "mobx-react-lite";
import Home from ".";

const Page = observer(() => {
return <Home isArchived/>
return <Home />
});

export default Page
35 changes: 16 additions & 19 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { _ } from '@/lib/lodash';
import { observer } from 'mobx-react-lite';
import Masonry from 'react-masonry-css'
import { useTranslation } from 'react-i18next';
import { useEffect, useState } from 'react';
import { useEffect } from 'react';
import { RootStore } from '@/store';
import { motion } from "framer-motion"
import { FilesAttachmentRender } from '@/components/Common/Editor/attachmentsRender';
Expand All @@ -15,43 +15,44 @@ import { useRouter } from 'next/router';
import { BlinkoEditor } from '@/components/BlinkoEditor';
import { BlinkoMultiSelectPop } from '@/components/BlinkoMultiSelectPop';
import dayjs from '@/lib/dayjs';
import { PromiseCall } from '@/store/standard/PromiseState';
import { api } from '@/lib/trpc';
import { BlinkoRightClickMenu } from '@/components/BlinkoRightClickMenu';
import { NoteType } from '@/server/types';
import { ScrollArea } from '@/components/Common/ScrollArea';

const Home = observer(({ type, isArchived }: { type?: number | null, isArchived?: boolean | null }) => {
const Home = observer(() => {
const { t } = useTranslation();
const blinko = RootStore.Get(BlinkoStore)
const router = useRouter();
const { tagId } = router.query;

useEffect(() => {
if (!router.isReady) return
blinko.noteListFilterConfig.type = type ? Number(type) : 0
blinko.noteTypeDefault = type ? Number(type) : 0
blinko.noteListFilterConfig.type = NoteType.BLINKO
blinko.noteTypeDefault = NoteType.BLINKO
blinko.noteListFilterConfig.tagId = null
blinko.noteListFilterConfig.isArchived = false

if (router.pathname == '/notes') {
blinko.noteListFilterConfig.type = NoteType.NOTE
blinko.noteTypeDefault = NoteType.NOTE
}
if (tagId) {
console.log({ tagId })
blinko.noteListFilterConfig.tagId = Number(tagId) as number
}
if (router.pathname == '/all') {
blinko.noteListFilterConfig.type = -1
}
if (isArchived) {
if (router.pathname == '/archived') {
blinko.noteListFilterConfig.type = -1
blinko.noteListFilterConfig.isArchived = true
}
blinko.noteList.resetAndCall({})
}, [type, tagId])
}, [router.isReady])

const store = RootStore.Local(() => ({
editorHeight: 75,
get showEditor() {
return !isArchived
return !blinko.noteListFilterConfig.isArchived
},
get showLoadAll() {
return blinko.noteList.isLoadAll
Expand Down Expand Up @@ -87,21 +88,17 @@ const Home = observer(({ type, isArchived }: { type?: number | null, isArchived?
columnClassName="my-masonry-grid_column">
{
blinko.noteList?.value?.map(i => {
return <motion.div className='w-full' style={{ boxShadow: '0 0 15px -5px #5858581a' }}
// whileHover={{ y: 2 }}
key={i.id}>
return <motion.div key={i.id} className='w-full' style={{ boxShadow: '0 0 15px -5px #5858581a' }}>
<ContextMenuTrigger id="blink-item-context-menu" >
<div
onContextMenu={e => {
blinko.curSelectedNote = _.cloneDeep(i)
}}
<div onContextMenu={e => {
blinko.curSelectedNote = _.cloneDeep(i)
}}
onClick={() => {
if (blinko.isMultiSelectMode) {
blinko.onMultiSelectNote(i.id)
}
}}>
<Card shadow='none' className={`mb-4 flex flex-col p-4 bg-background transition-all
${blinko.curMultiSelectIds?.includes(i.id) ? 'border-2 border-primary' : ''}`}>
<Card shadow='none' className={`mb-4 flex flex-col p-4 bg-background transition-all ${blinko.curMultiSelectIds?.includes(i.id) ? 'border-2 border-primary' : ''}`}>
<div className='mb-2 text-xs text-desc'>{dayjs(i.createdAt).fromNow()}</div>
<MarkdownRender content={i.content} />
<div className={i.attachments?.length != 0 ? 'my-2' : ''}>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { observer } from "mobx-react-lite";
import Home from ".";

const Page = observer(() => {
return <Home type={1}/>
return <Home/>
});

export default Page
22 changes: 13 additions & 9 deletions src/pages/review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { showTipsDialog } from '@/components/Common/TipsDialog';
import { DialogStore } from '@/store/module/Dialog';
import confetti from 'canvas-confetti'
import { useMediaQuery } from 'usehooks-ts';
import { FilesAttachmentRender } from '@/components/Common/Editor/attachmentsRender';
const App = observer(() => {
const blinko = RootStore.Get(BlinkoStore)
const swiperRef = useRef(null);
Expand Down Expand Up @@ -50,6 +51,7 @@ const App = observer(() => {

return (
<div className="App h-full overflow-hidden">

{
blinko.dailyReviewNoteList.value?.length != 0 && <>
<Swiper
Expand All @@ -63,20 +65,19 @@ const App = observer(() => {
grabCursor={true}
modules={[EffectCards]}
className="mt-10 md:mt-4 w-[300px] h-[380px] md:w-[350px] md:h-[520px]"
allowSlideNext={true} // Allow sliding to the next slide
allowSlidePrev={true} // Allow sliding to the previous slide
touchRatio={1} // Make it responsive to touches
resistance={true} // Provide some resistance for a smooth user experience
resistanceRatio={0.5} // Ratio for swiping resistance
slidesPerView={1} // Only one slide can be viewed at a time
centeredSlides={true} // Each slide is centered
allowSlideNext={true}
allowSlidePrev={true}
touchRatio={1}
resistance={true}
resistanceRatio={0.5}
slidesPerView={1}
centeredSlides={true}
>
{
blinko.dailyReviewNoteList.value?.map((i, index) => (
<SwiperSlide key={i.id} data-id={i.id} className='bg-white shadow-lg p-4 w-full overflow-hidden h-full'>
<div className='bg-white p-0 w-full overflow-y-scroll h-full'>
<div className='flex items-center gap-2 mb-2'>
<div>{i.id}</div>
<div className='text-xs text-desc'>{dayjs(i.createdAt).fromNow()}</div>
{
store.isBlinko ?
Expand All @@ -91,6 +92,9 @@ const App = observer(() => {
}
</div>
<MarkdownRender content={i.content} />
<div className={i.attachments?.length != 0 ? 'my-2' : ''}>
<FilesAttachmentRender columns={2} files={i.attachments ?? []} preview />
</div>
</div>
</SwiperSlide>
))
Expand Down Expand Up @@ -142,12 +146,12 @@ const App = observer(() => {
</>
}


{blinko.dailyReviewNoteList.value?.length == 0 && <div className='select-none text-ignore flex items-center justify-center gap-2 w-full mt-2 md:mt-10'>
<Icon icon="line-md:coffee-half-empty-twotone-loop" width="24" height="24" />
<div className='text-md text-ignore font-bold'>{t('congratulations-youve-reviewed-everything-today')}</div>
</div>}
</div >

);
})

Expand Down
1 change: 1 addition & 0 deletions src/server/routers/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const noteRouter = router({
return await prisma.notes.findMany({
where: { createdAt: { gt: new Date(new Date().getTime() - 24 * 60 * 60 * 1000) }, isReviewed: false },
orderBy: { id: 'desc' },
include: { attachments: true }
})
}),
reviewNote: authProcedure
Expand Down
12 changes: 2 additions & 10 deletions src/store/aiStore.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import { _ } from '@/lib/lodash';
import { makeAutoObservable } from 'mobx';
import { Store } from './standard/base';
import { ToastPlugin } from './module/Toast/Toast';
import { RootStore } from './root';
import { streamApi } from '@/lib/trpc';
import { StorageListState } from './standard/StorageListState';
import { Note } from '@/server/types';
import { makeAutoObservable } from 'mobx';

type Chat = {
content: string
Expand All @@ -15,10 +15,10 @@ type Chat = {
}

export class AiStore implements Store {
sid = 'AiStore';
constructor() {
makeAutoObservable(this)
}
sid = 'AiStore';
noteContent = '';
aiSearchText = '';
aiSearchResult = {
Expand Down Expand Up @@ -53,14 +53,6 @@ export class AiStore implements Store {
relationNotes: Note[] = []
chatHistory = new StorageListState<Chat>({ key: 'chatHistory' })
private abortController = new AbortController()
async onBottom() {
// await this.noteList.callNextPage({})
}

loadAllData() {
// this.noteList.resetAndCall({})
// this.tagList.call()
}

async completionsStream() {
try {
Expand Down
Loading

0 comments on commit 348a180

Please sign in to comment.