Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Chatterbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
element-hq
Chatterbox
Commits
472123b8
Commit
472123b8
authored
3 years ago
by
Midhun Suresh
Browse files
Options
Downloads
Patches
Plain Diff
Use Navigation from Hydrogen
parent
d87cae00
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main.ts
+18
-4
18 additions, 4 deletions
src/main.ts
src/viewmodels/AccountSetupViewModel.ts
+4
-4
4 additions, 4 deletions
src/viewmodels/AccountSetupViewModel.ts
src/viewmodels/RootViewModel.ts
+22
-21
22 additions, 21 deletions
src/viewmodels/RootViewModel.ts
with
44 additions
and
29 deletions
src/main.ts
+
18
−
4
View file @
472123b8
import
type
{
IChatterboxConfig
}
from
"
./types/IChatterboxConfig
"
;
import
{
Platform
,
createNavigation
,
createRouter
}
from
"
hydrogen-view-sdk
"
;
import
{
Platform
,
create
Router
,
Navigation
}
from
"
hydrogen-view-sdk
"
;
import
{
RootViewModel
}
from
"
./viewmodels/RootViewModel
"
;
import
{
RootView
}
from
"
./ui/views/RootView
"
;
import
assetPaths
from
"
hydrogen-view-sdk/paths/vite
"
;
...
...
@@ -23,13 +23,27 @@ async function main() {
root
.
className
=
"
hydrogen
"
;
const
config
=
await
fetchConfig
(
root
);
const
platform
=
new
Platform
(
root
,
assetPaths
,
{},
{
development
:
import
.
meta
.
env
.
DEV
});
const
navigation
=
create
Navigation
();
const
navigation
=
new
Navigation
(
allowsChild
);
platform
.
setNavigation
(
navigation
);
const
urlRouter
=
createRouter
({
navigation
,
history
:
platform
.
history
});
urlRouter
.
attach
(
);
const
rootViewModel
=
new
RootViewModel
(
config
,
{
platform
,
navigation
,
urlCreator
:
urlRouter
});
const
applySegment
=
getNavigation
(
navigation
);
const
rootViewModel
=
new
RootViewModel
(
config
,
{
platform
,
navigation
,
urlCreator
:
urlRouter
,
applySegment
});
const
rootView
=
new
RootView
(
rootViewModel
);
root
.
appendChild
(
rootView
.
mount
());
}
function
allowsChild
(
parent
,
child
)
{
return
true
;
}
function
getNavigation
(
navigation
)
{
function
applySegment
(
segment
:
string
,
value
?:
string
)
{
const
s
=
navigation
.
segment
(
segment
,
value
);
const
path
=
navigation
.
pathFrom
([
s
]);
navigation
.
applyPath
(
path
);
}
return
applySegment
;
}
main
();
This diff is collapsed.
Click to expand it.
src/viewmodels/AccountSetupViewModel.ts
+
4
−
4
View file @
472123b8
...
...
@@ -7,15 +7,15 @@ import "hydrogen-view-sdk/style.css";
export
class
AccountSetupViewModel
extends
ViewModel
{
private
_config
:
IChatterboxConfig
;
private
_client
:
Client
;
private
_state
:
ObservableValue
<
string
>
;
private
_termsStage
?:
any
;
private
_password
:
string
;
private
_applySegment
:
any
;
constructor
(
options
)
{
super
(
options
);
this
.
_client
=
options
.
client
;
this
.
_config
=
options
.
config
;
this
.
_
state
=
options
.
state
;
this
.
_
applySegment
=
options
.
applySegment
;
this
.
_startRegistration
();
}
...
...
@@ -53,11 +53,11 @@ export class AccountSetupViewModel extends ViewModel {
throw
new
Error
(
"
load failed:
"
+
this
.
_client
.
loadError
.
message
);
}
this
.
_
state
.
se
t
(
"
timeline
"
);
this
.
_
applySegmen
t
(
"
timeline
"
);
}
dismiss
()
{
this
.
_
state
.
se
t
(
"
start
"
);
this
.
_
applySegmen
t
(
"
start
"
);
}
private
get
_homeserver
():
string
{
...
...
This diff is collapsed.
Click to expand it.
src/viewmodels/RootViewModel.ts
+
22
−
21
View file @
472123b8
import
{
ViewModel
,
Client
,
createNavigation
,
createRouter
,
Platform
,
ObservableValue
}
from
"
hydrogen-view-sdk
"
;
import
{
ViewModel
,
Client
,
Platform
}
from
"
hydrogen-view-sdk
"
;
import
{
IChatterboxConfig
}
from
"
../types/IChatterboxConfig
"
;
import
{
ChatterboxViewModel
}
from
"
./ChatterboxViewModel
"
;
import
"
hydrogen-view-sdk/style.css
"
;
import
{
AccountSetupViewModel
}
from
"
./AccountSetupViewModel
"
;
type
Options
=
{
platform
:
Platform
,
urlCreator
:
ReturnType
<
create
Router
>
,
navigation
:
ReturnType
<
createNavigation
>
};
type
Options
=
{
platform
:
Platform
,
navigation
:
ReturnType
<
create
Navigation
>
,
applySegment
:
(
segment
:
string
,
value
?:
string
)
=>
void
};
export
class
RootViewModel
extends
ViewModel
{
private
_config
:
IChatterboxConfig
;
private
_client
:
Client
;
private
_chatterBoxViewModel
?:
ChatterboxViewModel
;
private
_accountSetupViewModel
?:
AccountSetupViewModel
;
private
_state
:
ObservableValue
<
string
>
=
new
ObservableValue
(
""
);
private
_activeSection
:
string
=
"
start
"
;
private
_applySegment
:
Options
[
"
applySegment
"
];
constructor
(
config
:
IChatterboxConfig
,
options
:
Options
)
{
super
(
options
);
this
.
_config
=
config
;
this
.
_client
=
new
Client
(
this
.
platform
);
this
.
_state
.
subscribe
(
stage
=>
this
.
_applyNavigation
(
stage
));
this
.
_applySegment
=
options
.
applySegment
;
this
.
_setupNavigation
();
}
private
_setupNavigation
()
{
this
.
navigation
.
observe
(
"
account-setup
"
).
subscribe
(()
=>
this
.
_showAccountSetup
());
this
.
navigation
.
observe
(
"
timeline
"
).
subscribe
(()
=>
this
.
_showTimeline
());
this
.
navigation
.
observe
(
"
start
"
).
subscribe
(()
=>
this
.
_showStartButton
());
}
async
start
()
{
const
sessionAlreadyExists
=
await
this
.
attemptStartWithExistingSession
();
if
(
sessionAlreadyExists
)
{
this
.
_
state
.
se
t
(
"
timeline
"
);
this
.
_
applySegmen
t
(
"
timeline
"
);
return
;
}
this
.
_state
.
set
(
"
account-setup
"
);
}
private
_applyNavigation
(
stage
:
string
)
{
switch
(
stage
)
{
case
"
timeline
"
:
this
.
_showTimeline
();
break
;
case
"
start
"
:
this
.
_showStartButton
();
break
;
case
"
account-setup
"
:
this
.
_showAccountSetup
();
break
;
}
this
.
_applySegment
(
"
account-setup
"
);
}
private
async
_showTimeline
()
{
this
.
_activeSection
=
"
timeline
"
;
this
.
_chatterBoxViewModel
=
new
ChatterboxViewModel
(
this
.
childOptions
({
session
:
this
.
_client
.
session
,
config
:
this
.
_config
,
state
:
this
.
_state
}));
this
.
_chatterBoxViewModel
=
new
ChatterboxViewModel
(
this
.
childOptions
({
session
:
this
.
_client
.
session
,
config
:
this
.
_config
,
state
:
this
.
_state
,
applySegment
:
this
.
_applySegment
,
})
);
await
this
.
_chatterBoxViewModel
.
loadRoom
();
this
.
emitChange
(
"
activeSection
"
);
}
...
...
@@ -58,6 +58,7 @@ export class RootViewModel extends ViewModel {
client
:
this
.
_client
,
config
:
this
.
_config
,
state
:
this
.
_state
,
applySegment
:
this
.
_applySegment
,
})
);
this
.
emitChange
(
"
activeSection
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment