@@ -85,7 +85,7 @@ class GhRepoScreen extends StatelessWidget {
8585
8686 return Tuple3 (repo, countFuture, readmeData);
8787 },
88- actionBuilder: (data, setState ) {
88+ actionBuilder: (data, _ ) {
8989 final repo = data.item1;
9090 return ActionButton (
9191 title: S .of (context).repositoryActions,
@@ -102,7 +102,7 @@ class GhRepoScreen extends StatelessWidget {
102102 ],
103103 );
104104 },
105- bodyBuilder: (data, setState ) {
105+ bodyBuilder: (data, setData ) {
106106 final repo = data.item1;
107107 final contributionFuture = data.item2;
108108 final readmeData = data.item3;
@@ -133,49 +133,34 @@ class GhRepoScreen extends StatelessWidget {
133133 ActionItem (
134134 text: _buildWatchState (v),
135135 onTap: (_) async {
136+ final activityApi =
137+ context.read <AuthModel >().ghClient.activity;
136138 switch (v) {
137139 case GSubscriptionState .SUBSCRIBED :
138140 case GSubscriptionState .IGNORED :
139- await context
140- .read <AuthModel >()
141- .ghClient
142- .activity
143- .setRepositorySubscription (
144- RepositorySlug (
145- repo.owner.login, repo.name),
146- subscribed: v ==
147- GSubscriptionState .SUBSCRIBED ,
148- ignored:
149- v == GSubscriptionState .IGNORED ,
150- );
151- setState (() {
152- // if (res.subscribed) {
153- // repo.viewerSubscription =
154- // GSubscriptionState.SUBSCRIBED;
155- // } else if (res.ignored) {
156- // repo.viewerSubscription =
157- // GSubscriptionState.IGNORED;
158- // }
159- });
141+ await activityApi.setRepositorySubscription (
142+ RepositorySlug (
143+ repo.owner.login, repo.name),
144+ subscribed:
145+ v == GSubscriptionState .SUBSCRIBED ,
146+ ignored: v == GSubscriptionState .IGNORED ,
147+ );
160148 break ;
161149 case GSubscriptionState .UNSUBSCRIBED :
162- await context
163- .read <AuthModel >()
164- .ghClient
165- .activity
150+ await activityApi
166151 .deleteRepositorySubscription (
167- RepositorySlug (
168- repo.owner.login,
169- repo.name,
170- ),
171- );
172- setState (() {
173- // repo.viewerSubscription =
174- // GSubscriptionState.UNSUBSCRIBED;
175- });
152+ RepositorySlug (
153+ repo.owner.login,
154+ repo.name,
155+ ),
156+ );
176157 break ;
177158 default :
178159 }
160+
161+ setData (data.withItem1 (repo.rebuild ((b) {
162+ b.viewerSubscription = v;
163+ })));
179164 },
180165 )
181166 ]);
@@ -186,24 +171,18 @@ class GhRepoScreen extends StatelessWidget {
186171 active: repo.viewerHasStarred,
187172 text: repo.viewerHasStarred ? 'Unstar' : 'Star' ,
188173 onTap: () async {
174+ final activityApi =
175+ context.read <AuthModel >().ghClient.activity;
189176 if (repo.viewerHasStarred) {
190- await context
191- .read <AuthModel >()
192- .ghClient
193- .activity
194- .unstar (
195- RepositorySlug (repo.owner.login, repo.name));
177+ await activityApi.unstar (
178+ RepositorySlug (repo.owner.login, repo.name));
196179 } else {
197- await context
198- .read <AuthModel >()
199- .ghClient
200- .activity
201- .star (
202- RepositorySlug (repo.owner.login, repo.name));
180+ await activityApi.star (
181+ RepositorySlug (repo.owner.login, repo.name));
203182 }
204- setState (( ) {
205- // repo .viewerHasStarred = !repo.viewerHasStarred;
206- });
183+ setData (data. withItem1 (repo. rebuild ((b ) {
184+ b .viewerHasStarred = ! repo.viewerHasStarred;
185+ }))) ;
207186 },
208187 ),
209188 ],
0 commit comments