Skip to content

Commit

Permalink
feat: add storage
Browse files Browse the repository at this point in the history
  • Loading branch information
xie392 committed Jun 3, 2024
1 parent 6d373f9 commit c71b75a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
12 changes: 6 additions & 6 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 4,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 4,
"singleQuote": true,
"printWidth": 120,
"trailingComma": "none"
}
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<div id="root"></div>
<script src="/assets/js/socket.io-1.2.0.js"></script>
<script type="module" src="/src/main.tsx"></script>
<script src="//cdn.jsdelivr.net/npm/eruda"></script>
<!-- <script src="//cdn.jsdelivr.net/npm/eruda"></script>
<script>
eruda.init()
</script>
</script> -->
</body>
</html>
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"emoji-mart": "^5.6.0",
"i18next": "^23.11.5",
"i18next-browser-languagedetector": "^8.0.0",
"inversify": "^6.0.2",
"js-md5": "^0.8.3",
"openpgp": "^5.11.1",
"quill": "2.0.2",
Expand All @@ -61,7 +60,6 @@
"react-infinite-scroll-component": "^6.1.0",
"react-router": "^6.23.1",
"react-router-dom": "^6.23.1",
"reflect-metadata": "^0.2.2",
"zustand": "^4.5.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { App as AppComponent } from 'antd'
import useAuth from '@/hooks/useLogin'
import enUS from 'antd/locale/en_US'
import zhCN from 'antd/locale/zh_CN'
import dayjs from 'dayjs'
import { locale as dayjsLocale } from 'dayjs'
import { Locale } from 'antd/es/locale'
import Call from '@/components/call'

Expand All @@ -20,10 +20,10 @@ const App = () => {
useEffect(() => {
if (localStorage.getItem('locale') !== 'zh-CN') {
setLocal(zhCN)
dayjs.locale('zh-cn')
dayjsLocale('zh-cn')
} else {
setLocal(enUS)
dayjs.locale('en')
dayjsLocale('en')
}
}, [])

Expand Down
1 change: 0 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import '@/i18n'
import '@/styles/base.scss'
import App from './app'
import { SafeArea } from '@capacitor-community/safe-area'
import 'reflect-metadata'

const Router = __IS_ELECTRON__ ? HashRouter : BrowserRouter

Expand Down
10 changes: 10 additions & 0 deletions src/storage/impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Storage from '.'

class StorageImpl extends Storage {
// private tableName: string
// constructor(tableName: string) {
// this.tableName = tableName
// }
}

export default StorageImpl
31 changes: 11 additions & 20 deletions src/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import useUserStore from '@/stores/user'
import type { FriendData, GroupData, RequestData } from '@/types/storage'
import Dexie, { Table } from 'dexie'
import { injectable, Container } from 'inversify'
import GroupMessagesService from './services/group-messages'

export const TYPES = {
Storage: Symbol.for('Storage')
}

@injectable()
class Storage extends Dexie {
private_messages!: Table<Message>
group_messages!: Table<Message>
chatList!: Table<ChatData>
chat_list!: Table<ChatData>
request_list!: Table<RequestData>
friends!: Table<FriendData>
groups!: Table<GroupData>

constructor(name: string, version: number = 1) {
super(name)
this.version(version).stores({
private_messages: '++id, sender, receiver, content, timestamp',
group_messages: '++id, sender, group, content, timestamp',
chatList: '++id, name, members, lastMessage, lastMessageTime'
private_messages: '++id, msg_id, dialog_id, content, type, sender_id, receiver_id',
group_messages: '++id, msg_id, dialog_id, content, type, sender_id, receiver_id, group_id',
chat_list: '++id, dialog_id, dialog_name, dialog_avatar, top_at, last_message',
request_list: '++id, request_id, dialog_id', // TODO: add more fields
friends: '++id, user_id', // TODO: add more fields
groups: '++id, group_id' // TODO: add more fields
})
}
}
Expand All @@ -29,13 +29,4 @@ export function createStorage(name: string = 'coss-storage', version: number = 1
return new Storage(`${name}-${userId}`, version)
}

const container = new Container()

container.bind<Storage>(TYPES.Storage).to(Storage).inSingletonScope()

container.bind<GroupMessagesService>(GroupMessagesService).toSelf().inSingletonScope()

const groupMessagesService = container.get<GroupMessagesService>(GroupMessagesService)

export { groupMessagesService }
export default Storage
Empty file.
5 changes: 5 additions & 0 deletions src/types/storage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface RequestData {}

export interface FriendData {}

export interface GroupData {}

0 comments on commit c71b75a

Please sign in to comment.