Skip to content

Commit

Permalink
add global gallery / all-media view
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Laux committed Sep 14, 2023
1 parent 8a601a0 commit 66d5331
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/renderer/components/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const MediaTabs: Readonly<
},
}

type mediaProps = { chatId: number }
type mediaProps = { chatId: number | 'all' }

export default class Gallery extends Component<
mediaProps,
Expand Down Expand Up @@ -67,16 +67,11 @@ export default class Gallery extends Component<
throw new Error('chat id missing')
}
const msgTypes = MediaTabs[id].values

const accountId = selectedAccountId()
const chatId = this.props.chatId !== 'all' ? this.props.chatId : null

BackendRemote.rpc
.getChatMedia(
accountId,
this.props.chatId,
msgTypes[0],
msgTypes[1],
null
)
.getChatMedia(accountId, chatId, msgTypes[0], msgTypes[1], null)
.then(async media_ids => {
// throws if some media is not found
const all_media_fetch_results = await BackendRemote.rpc.getMessages(
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ const Sidebar = React.memo(
ActionEmitter.emitAction(KeybindAction.ChatList_SwitchToArchiveView)
}

const onOpenGlobalGallery = () => {
setSidebarState('invisible')
ActionEmitter.emitAction(KeybindAction.GlobalGallery_Open)
}

useEffect(() => {
window.addEventListener('keyup', onEscapeKeyUp)
return () => {
Expand Down Expand Up @@ -172,6 +177,13 @@ const Sidebar = React.memo(
>
{tx('chat_archived_chats_title')}
</div>
<div
key='global_gallery'
className='sidebar-item'
onClick={onOpenGlobalGallery}
>
{tx('menu_all_media')}
</div>
<div key='settings' className='sidebar-item' onClick={onOpenSettings}>
{tx('menu_settings')}
</div>
Expand Down
29 changes: 29 additions & 0 deletions src/renderer/components/screens/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
openViewProfileDialog,
selectChat,
setChatView,
unselectChat,
} from '../helpers/ChatMethods'

import {
Expand Down Expand Up @@ -62,6 +63,19 @@ export default function MainScreen() {
const screenContext = useContext(ScreenContext)
const selectedChat = useChatStore()

const [alternativeView, setAlternativeView] = useState<
null | 'global-gallery'
>(null)
useEffect(() => {
if (selectedChat.chat?.id) {
setAlternativeView(null)
}
}, [selectedChat.chat?.id])
useKeyBindingAction(KeybindAction.GlobalGallery_Open, () => {
unselectChat()
setAlternativeView('global-gallery')
})

const onChatClick = (chatId: number) => {
if (chatId === C.DC_CHAT_ID_ARCHIVED_LINK) return setShowArchivedChats(true)

Expand Down Expand Up @@ -168,6 +182,8 @@ export default function MainScreen() {
</RecoverableCrashScreen>
)
}
} else if (alternativeView === 'global-gallery') {
MessageListView = <Gallery chatId={'all'} />
} else {
const style: React.CSSProperties = settingsStore
? getBackgroundImageStyle(settingsStore.desktopSettings)
Expand Down Expand Up @@ -231,6 +247,19 @@ export default function MainScreen() {
)}
</NavbarGroup>
<NavbarGroup align={Alignment.RIGHT}>
{alternativeView === 'global-gallery' && (
<NavbarHeading
style={{
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
width: '100%',
}}
onClick={onTitleClick}
>
{tx('menu_all_media')}
</NavbarHeading>
)}
{selectedChat.chat && (
<NavbarHeading
style={{
Expand Down
1 change: 1 addition & 0 deletions src/renderer/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum KeybindAction {
KeybindingCheatSheet_Open = 'keybindinginfo:open',
MessageList_PageUp = 'msglist:pageup',
MessageList_PageDown = 'msglist:pagedown',
GlobalGallery_Open = 'globalgallery:open',

// Actions that are not necessarily triggered by keybindings
ChatList_SwitchToArchiveView = 'chatlist:switch-to-archive-view',
Expand Down

0 comments on commit 66d5331

Please sign in to comment.